Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

SystemNavigator.pop can pop w/o UINavigationController #6341

Merged
merged 5 commits into from
Sep 27, 2018

Conversation

dnfield
Copy link
Contributor

@dnfield dnfield commented Sep 26, 2018

Today, iOS apps in Flutter ignore System.pop unless they find that the rootViewController is a UINavigationViewController.

For Add2App, it's entirely possible someone will show the view using something like showDetailViewController from UIViewController. This patch updates the logic to handle that scenario, but to do so the FlutterPlatformPlugin needs to get access to the FlutterViewController, and to do that I added functionality there for FlutterViewController to create WeakPtrs.

I'd be very happy if it turns out there's a way to stack allocate the WeakPtrFactory (or equivalent functionality) in Objective C++.

/cc @matthew-carroll - It might be worth investigating how SystemNavigator.pop is working in Android's Add2App use cases

Fixes part of flutter/flutter#22054

@dnfield
Copy link
Contributor Author

dnfield commented Sep 26, 2018

Also would be happy if there's a more idiomatic Objective C++ way to pass a weak reference to another object

@interface FlutterPlatformPlugin : NSObject

- (instancetype)initWithViewController:(fml::WeakPtr<UIViewController>)vc;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a designated initializer? If so, please decorated this with NS_DESIGNATED_INITIALIZER.

@@ -31,7 +32,20 @@

using namespace shell;

@implementation FlutterPlatformPlugin
@implementation FlutterPlatformPlugin {
fml::WeakPtr<UIViewController> _vc;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: We prefer not to abbreviate instance variable names in code. _viewController works better IMO.

UIViewController* viewController = [UIApplication sharedApplication].keyWindow.rootViewController;
if ([viewController isKindOfClass:[UINavigationController class]]) {
[((UINavigationController*)viewController) popViewControllerAnimated:NO];
} else if (_vc && viewController != _vc.get()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The second check is redundant.

@@ -34,6 +35,7 @@ @implementation FlutterViewController {
fml::scoped_nsobject<FlutterDartProject> _dartProject;
shell::ThreadHost _threadHost;
std::unique_ptr<shell::Shell> _shell;
fml::WeakPtrFactory<FlutterViewController>* _weakFactory;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We really try to avoid raw pointers. Please consider using a unique pointer. I realize the ObjC++ interop makes this a bit awkward.

Copy link
Member

@chinmaygarde chinmaygarde left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor nit but looks good otherwise. Thanks!

@@ -65,6 +67,8 @@ - (instancetype)initWithProject:(FlutterDartProject*)projectOrNil
bundle:(NSBundle*)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
_weakFactory = std::unique_ptr<fml::WeakPtrFactory<FlutterViewController>>(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: std::make_unique<fml::WeakPtrFactory<FlutterViewController>>(self) is used in the engine for construction of unique pointer.

@chinmaygarde
Copy link
Member

The CI bot failure is because of clang-format. I recommend wiring up your editor to format on save.

@dnfield
Copy link
Contributor Author

dnfield commented Sep 27, 2018

I was having issues with depot_tools clang-format not working, and I thought I fixed it but now it doesn't seem to get the right clang format rules... I'll fix that though. Thanks!

@dnfield dnfield merged commit 3052dbd into flutter:master Sep 27, 2018
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Sep 27, 2018
flutter/engine@38a646e...3052dbd

git log 38a646e..3052dbd --no-merges --oneline
3052dbd SystemNavigator.pop can pop w/o UINavigationController (flutter/engine#6341)
0c096f7 Roll src/third_party/skia b3e48afc936d..227d4e10276c (1 commits) (flutter/engine#6359)
b8c2a17 Roll src/third_party/skia cfe1264d7465..b3e48afc936d (3 commits) (flutter/engine#6356)
c589b31 Expose push/popRoute on FlutterViewController (flutter/engine#6347)
075b3fc Roll src/third_party/skia 5ea41fc89b26..cfe1264d7465 (1 commits) (flutter/engine#6355)
2dd9b99 Roll Dart to version 808ed6238b9262660e31ea826f7aea6cfa3a3493 (flutter/engine#6354)
5b79938 Dont make any binaries specify an X11 dependency. (flutter/engine#6353)
309ac4e V0.8.2 fix compile problem with xcode10 (flutter/engine#6339)
26fdd1e Roll src/third_party/skia 5767fc042834..5ea41fc89b26 (3 commits) (flutter/engine#6351)
cc44ca5 Perform persistent cache stores on the IO thread outside the frame workload. (flutter/engine#6350)
f2a3df9 Wire up the Skia persistent GPU related artifacts cache. (flutter/engine#6278)
9d4b80a Roll src/third_party/skia 17282da3aa94..5767fc042834 (8 commits) (flutter/engine#6348)
ef98dcb Add support for counter timeline traces from the engine. (flutter/engine#6315)
a961e96 Roll buildroot to pick up updated vs toolchain. (flutter/engine#6346)
d6bb599 Fixed IsolateNameServer documentation (flutter/engine#6344)
0c854ac Roll src/third_party/skia bdf1431686c2..17282da3aa94 (4 commits) (flutter/engine#6345)
e394ea1 Roll src/third_party/skia c05302bc84da..bdf1431686c2 (1 commits) (flutter/engine#6343)
bcdfc23 Roll src/third_party/skia 5457141b011e..c05302bc84da (1 commits) (flutter/engine#6342)
a861f37 Pass on the new unsafe-package-serialization option (flutter/engine#6331)
5e77a1e Roll src/third_party/skia bd03b54cb98d..5457141b011e (1 commits) (flutter/engine#6340)
6332db8 Roll src/third_party/skia f18c297cfb74..bd03b54cb98d (1 commits) (flutter/engine#6338)
a08bc52 Roll src/third_party/skia 7ffa40cedbc4..f18c297cfb74 (6 commits) (flutter/engine#6336)
8247ce2 Implement restore functions on Android and iOS (flutter/engine#6322)
2ead5c0 Roll src/third_party/skia 4ef464cd3c2e..7ffa40cedbc4 (10 commits) (flutter/engine#6334)

The AutoRoll server is located here: https://autoroll.skia.org/r/flutter-engine-flutter-autoroll

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/&#43;/master/autoroll/README.md

If the roll is causing failures, please contact the current sheriff, who should
be CC&#39;d on the roll, and stop the roller if necessary.
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Sep 27, 2018
flutter/engine@9d4b80a...5ae4708

git log 9d4b80a..5ae4708 --no-merges --oneline
5ae4708 Roll src/third_party/skia 227d4e10276c..ab3144c3abb9 (11 commits) (flutter/engine#6360)
763627f Do not export libdart symbols (flutter/engine#6337)
3052dbd SystemNavigator.pop can pop w/o UINavigationController (flutter/engine#6341)
0c096f7 Roll src/third_party/skia b3e48afc936d..227d4e10276c (1 commits) (flutter/engine#6359)
b8c2a17 Roll src/third_party/skia cfe1264d7465..b3e48afc936d (3 commits) (flutter/engine#6356)
c589b31 Expose push/popRoute on FlutterViewController (flutter/engine#6347)
075b3fc Roll src/third_party/skia 5ea41fc89b26..cfe1264d7465 (1 commits) (flutter/engine#6355)
2dd9b99 Roll Dart to version 808ed6238b9262660e31ea826f7aea6cfa3a3493 (flutter/engine#6354)
5b79938 Dont make any binaries specify an X11 dependency. (flutter/engine#6353)
309ac4e V0.8.2 fix compile problem with xcode10 (flutter/engine#6339)
26fdd1e Roll src/third_party/skia 5767fc042834..5ea41fc89b26 (3 commits) (flutter/engine#6351)
cc44ca5 Perform persistent cache stores on the IO thread outside the frame workload. (flutter/engine#6350)
f2a3df9 Wire up the Skia persistent GPU related artifacts cache. (flutter/engine#6278)

The AutoRoll server is located here: https://autoroll.skia.org/r/flutter-engine-flutter-autoroll

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/&#43;/master/autoroll/README.md

If the roll is causing failures, please contact the current sheriff, who should
be CC&#39;d on the roll, and stop the roller if necessary.
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Sep 27, 2018
flutter/engine@9d4b80a...3a01f39

git log 9d4b80a..3a01f39 --no-merges --oneline
3a01f39 Change log level from ERROR to WARNING (flutter/engine#6361)
5ae4708 Roll src/third_party/skia 227d4e10276c..ab3144c3abb9 (11 commits) (flutter/engine#6360)
763627f Do not export libdart symbols (flutter/engine#6337)
3052dbd SystemNavigator.pop can pop w/o UINavigationController (flutter/engine#6341)
0c096f7 Roll src/third_party/skia b3e48afc936d..227d4e10276c (1 commits) (flutter/engine#6359)
b8c2a17 Roll src/third_party/skia cfe1264d7465..b3e48afc936d (3 commits) (flutter/engine#6356)
c589b31 Expose push/popRoute on FlutterViewController (flutter/engine#6347)
075b3fc Roll src/third_party/skia 5ea41fc89b26..cfe1264d7465 (1 commits) (flutter/engine#6355)
2dd9b99 Roll Dart to version 808ed6238b9262660e31ea826f7aea6cfa3a3493 (flutter/engine#6354)
5b79938 Dont make any binaries specify an X11 dependency. (flutter/engine#6353)
309ac4e V0.8.2 fix compile problem with xcode10 (flutter/engine#6339)
26fdd1e Roll src/third_party/skia 5767fc042834..5ea41fc89b26 (3 commits) (flutter/engine#6351)
cc44ca5 Perform persistent cache stores on the IO thread outside the frame workload. (flutter/engine#6350)
f2a3df9 Wire up the Skia persistent GPU related artifacts cache. (flutter/engine#6278)

The AutoRoll server is located here: https://autoroll.skia.org/r/flutter-engine-flutter-autoroll

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/&#43;/master/autoroll/README.md

If the roll is causing failures, please contact the current sheriff, who should
be CC&#39;d on the roll, and stop the roller if necessary.
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Sep 27, 2018
flutter/engine@9d4b80a...edf6249

git log 9d4b80a..edf6249 --no-merges --oneline
edf6249 Add pushOffset to SceneBuilder (flutter/engine#6349)
3a01f39 Change log level from ERROR to WARNING (flutter/engine#6361)
5ae4708 Roll src/third_party/skia 227d4e10276c..ab3144c3abb9 (11 commits) (flutter/engine#6360)
763627f Do not export libdart symbols (flutter/engine#6337)
3052dbd SystemNavigator.pop can pop w/o UINavigationController (flutter/engine#6341)
0c096f7 Roll src/third_party/skia b3e48afc936d..227d4e10276c (1 commits) (flutter/engine#6359)
b8c2a17 Roll src/third_party/skia cfe1264d7465..b3e48afc936d (3 commits) (flutter/engine#6356)
c589b31 Expose push/popRoute on FlutterViewController (flutter/engine#6347)
075b3fc Roll src/third_party/skia 5ea41fc89b26..cfe1264d7465 (1 commits) (flutter/engine#6355)
2dd9b99 Roll Dart to version 808ed6238b9262660e31ea826f7aea6cfa3a3493 (flutter/engine#6354)
5b79938 Dont make any binaries specify an X11 dependency. (flutter/engine#6353)
309ac4e V0.8.2 fix compile problem with xcode10 (flutter/engine#6339)
26fdd1e Roll src/third_party/skia 5767fc042834..5ea41fc89b26 (3 commits) (flutter/engine#6351)
cc44ca5 Perform persistent cache stores on the IO thread outside the frame workload. (flutter/engine#6350)
f2a3df9 Wire up the Skia persistent GPU related artifacts cache. (flutter/engine#6278)

The AutoRoll server is located here: https://autoroll.skia.org/r/flutter-engine-flutter-autoroll

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/&#43;/master/autoroll/README.md

If the roll is causing failures, please contact the current sheriff, who should
be CC&#39;d on the roll, and stop the roller if necessary.
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Sep 27, 2018
flutter/engine@9d4b80a...d80c1de

git log 9d4b80a..d80c1de --no-merges --oneline
d80c1de Roll src/third_party/skia ab3144c3abb9..656cefe65d62 (11 commits) (flutter/engine#6362)
edf6249 Add pushOffset to SceneBuilder (flutter/engine#6349)
3a01f39 Change log level from ERROR to WARNING (flutter/engine#6361)
5ae4708 Roll src/third_party/skia 227d4e10276c..ab3144c3abb9 (11 commits) (flutter/engine#6360)
763627f Do not export libdart symbols (flutter/engine#6337)
3052dbd SystemNavigator.pop can pop w/o UINavigationController (flutter/engine#6341)
0c096f7 Roll src/third_party/skia b3e48afc936d..227d4e10276c (1 commits) (flutter/engine#6359)
b8c2a17 Roll src/third_party/skia cfe1264d7465..b3e48afc936d (3 commits) (flutter/engine#6356)
c589b31 Expose push/popRoute on FlutterViewController (flutter/engine#6347)
075b3fc Roll src/third_party/skia 5ea41fc89b26..cfe1264d7465 (1 commits) (flutter/engine#6355)
2dd9b99 Roll Dart to version 808ed6238b9262660e31ea826f7aea6cfa3a3493 (flutter/engine#6354)
5b79938 Dont make any binaries specify an X11 dependency. (flutter/engine#6353)
309ac4e V0.8.2 fix compile problem with xcode10 (flutter/engine#6339)
26fdd1e Roll src/third_party/skia 5767fc042834..5ea41fc89b26 (3 commits) (flutter/engine#6351)
cc44ca5 Perform persistent cache stores on the IO thread outside the frame workload. (flutter/engine#6350)
f2a3df9 Wire up the Skia persistent GPU related artifacts cache. (flutter/engine#6278)

The AutoRoll server is located here: https://autoroll.skia.org/r/flutter-engine-flutter-autoroll

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/&#43;/master/autoroll/README.md

If the roll is causing failures, please contact the current sheriff, who should
be CC&#39;d on the roll, and stop the roller if necessary.
GaryQian pushed a commit to GaryQian/engine that referenced this pull request Oct 2, 2018
* SystemNavigator.pop can pop w/o UINavigationController
@dnfield dnfield deleted the system_pop_ios branch November 14, 2018 19:26
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants