未验证 提交 177e043b 编写于 作者: D Dan Field 提交者: GitHub

fix setInitialRoute (#6774)

* fix setInitialRoute
上级 6fa5c0a8
...@@ -20,3 +20,4 @@ tags ...@@ -20,3 +20,4 @@ tags
Thumbs.db Thumbs.db
.idea .idea
pubspec.lock pubspec.lock
.vscode/
...@@ -78,7 +78,7 @@ FLUTTER_EXPORT ...@@ -78,7 +78,7 @@ FLUTTER_EXPORT
* tree-shaken by the Dart compiler. * tree-shaken by the Dart compiler.
* @return YES if the call succeeds in creating and running a Flutter Engine instance; NO otherwise. * @return YES if the call succeeds in creating and running a Flutter Engine instance; NO otherwise.
*/ */
- (bool)runWithEntrypoint:(NSString*)entrypoint; - (BOOL)runWithEntrypoint:(NSString*)entrypoint;
/** /**
* Runs a Dart program on an Isolate using the specified entrypoint and Dart library, * Runs a Dart program on an Isolate using the specified entrypoint and Dart library,
...@@ -95,7 +95,7 @@ FLUTTER_EXPORT ...@@ -95,7 +95,7 @@ FLUTTER_EXPORT
* this will default to the same library as the `main()` function in the Dart program. * this will default to the same library as the `main()` function in the Dart program.
* @return YES if the call succeeds in creating and running a Flutter Engine instance; NO otherwise. * @return YES if the call succeeds in creating and running a Flutter Engine instance; NO otherwise.
*/ */
- (bool)runWithEntrypoint:(NSString*)entrypoint libraryURI:(NSString*)uri; - (BOOL)runWithEntrypoint:(NSString*)entrypoint libraryURI:(NSString*)uri;
/** /**
* Sets the `FlutterViewController` for this instance. The FlutterEngine must be * Sets the `FlutterViewController` for this instance. The FlutterEngine must be
......
...@@ -264,10 +264,10 @@ ...@@ -264,10 +264,10 @@
})); }));
} }
- (bool)runWithEntrypoint:(NSString*)entrypoint libraryURI:(NSString*)libraryURI { - (BOOL)createShell:(NSString*)entrypoint libraryURI:(NSString*)libraryURI {
if (_shell != nullptr) { if (_shell != nullptr) {
FML_LOG(WARNING) << "This FlutterEngine was already invoked."; FML_LOG(WARNING) << "This FlutterEngine was already invoked.";
return false; return NO;
} }
static size_t shellCount = 1; static size_t shellCount = 1;
...@@ -351,13 +351,20 @@ ...@@ -351,13 +351,20 @@
<< entrypoint.UTF8String; << entrypoint.UTF8String;
} else { } else {
[self maybeSetupPlatformViewChannels]; [self maybeSetupPlatformViewChannels];
}
return _shell != nullptr;
}
- (BOOL)runWithEntrypoint:(NSString*)entrypoint libraryURI:(NSString*)libraryURI {
if ([self createShell:entrypoint libraryURI:libraryURI]) {
[self launchEngine:entrypoint libraryURI:libraryURI]; [self launchEngine:entrypoint libraryURI:libraryURI];
} }
return _shell != nullptr; return _shell != nullptr;
} }
- (bool)runWithEntrypoint:(NSString*)entrypoint { - (BOOL)runWithEntrypoint:(NSString*)entrypoint {
return [self runWithEntrypoint:entrypoint libraryURI:nil]; return [self runWithEntrypoint:entrypoint libraryURI:nil];
} }
......
...@@ -42,6 +42,7 @@ ...@@ -42,6 +42,7 @@
- (shell::FlutterPlatformViewsController*)platformViewsController; - (shell::FlutterPlatformViewsController*)platformViewsController;
- (FlutterTextInputPlugin*)textInputPlugin; - (FlutterTextInputPlugin*)textInputPlugin;
- (void)launchEngine:(NSString*)entrypoint libraryURI:(NSString*)libraryOrNil; - (void)launchEngine:(NSString*)entrypoint libraryURI:(NSString*)libraryOrNil;
- (BOOL)createShell:(NSString*)entrypoint libraryURI:(NSString*)libraryOrNil;
@end @end
......
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
blink::ViewportMetrics _viewportMetrics; blink::ViewportMetrics _viewportMetrics;
BOOL _initialized; BOOL _initialized;
BOOL _viewOpaque; BOOL _viewOpaque;
BOOL _engineNeedsLaunch;
} }
#pragma mark - Manage and override all designated initializers #pragma mark - Manage and override all designated initializers
...@@ -49,6 +50,7 @@ ...@@ -49,6 +50,7 @@
if (self) { if (self) {
_viewOpaque = YES; _viewOpaque = YES;
_engine.reset([engine retain]); _engine.reset([engine retain]);
_engineNeedsLaunch = NO;
_flutterView.reset([[FlutterView alloc] initWithDelegate:_engine opaque:self.isViewOpaque]); _flutterView.reset([[FlutterView alloc] initWithDelegate:_engine opaque:self.isViewOpaque]);
_weakFactory = std::make_unique<fml::WeakPtrFactory<FlutterViewController>>(self); _weakFactory = std::make_unique<fml::WeakPtrFactory<FlutterViewController>>(self);
...@@ -68,8 +70,8 @@ ...@@ -68,8 +70,8 @@
_weakFactory = std::make_unique<fml::WeakPtrFactory<FlutterViewController>>(self); _weakFactory = std::make_unique<fml::WeakPtrFactory<FlutterViewController>>(self);
_engine.reset([[FlutterEngine alloc] initWithName:@"io.flutter" project:projectOrNil]); _engine.reset([[FlutterEngine alloc] initWithName:@"io.flutter" project:projectOrNil]);
_flutterView.reset([[FlutterView alloc] initWithDelegate:_engine opaque:self.isViewOpaque]); _flutterView.reset([[FlutterView alloc] initWithDelegate:_engine opaque:self.isViewOpaque]);
[_engine.get() runWithEntrypoint:nil]; [_engine.get() createShell:nil libraryURI:nil];
[_engine.get() setViewController:self]; _engineNeedsLaunch = YES;
[self performCommonViewControllerInitialization]; [self performCommonViewControllerInitialization];
} }
...@@ -371,6 +373,12 @@ ...@@ -371,6 +373,12 @@
- (void)viewWillAppear:(BOOL)animated { - (void)viewWillAppear:(BOOL)animated {
TRACE_EVENT0("flutter", "viewWillAppear"); TRACE_EVENT0("flutter", "viewWillAppear");
if (_engineNeedsLaunch) {
[_engine.get() launchEngine:nil libraryURI:nil];
[_engine.get() setViewController:self];
_engineNeedsLaunch = NO;
}
// Only recreate surface on subsequent appearances when viewport metrics are known. // Only recreate surface on subsequent appearances when viewport metrics are known.
// First time surface creation is done on viewDidLayoutSubviews. // First time surface creation is done on viewDidLayoutSubviews.
if (_viewportMetrics.physical_width) if (_viewportMetrics.physical_width)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册