From 4c97eefa3dd7660afb7ded25886c87cbcc5b46e6 Mon Sep 17 00:00:00 2001 From: Sarah Zakarias Date: Fri, 9 Jun 2017 10:37:53 +0200 Subject: [PATCH] Add setInitialRoute on FlutterViewController (flutter/engine#3754) --- .../framework/Headers/FlutterViewController.h | 8 ++++++++ .../framework/Source/FlutterViewController.mm | 16 +++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Headers/FlutterViewController.h b/engine/src/flutter/shell/platform/darwin/ios/framework/Headers/FlutterViewController.h index 20955f32fa..18480cb0ad 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Headers/FlutterViewController.h +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Headers/FlutterViewController.h @@ -20,6 +20,14 @@ FLUTTER_EXPORT bundle:(NSBundle*)nibBundleOrNil NS_DESIGNATED_INITIALIZER; - (void)handleStatusBarTouches:(UIEvent*)event; + +/** + Sets the first route that the Flutter app shows. The default is "/". + + - Parameter route: The name of the first route to show. + */ +- (void)setInitialRoute:(NSString*)route; + @end #endif // FLUTTER_FLUTTERVIEWCONTROLLER_H_ diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm index 3d74044186..1007f0b56a 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm @@ -72,6 +72,7 @@ class PlatformMessageResponseDarwin : public blink::PlatformMessageResponse { fml::scoped_nsprotocol _lifecycleChannel; fml::scoped_nsprotocol _systemChannel; BOOL _initialized; + BOOL _connected; } + (void)initialize { @@ -164,7 +165,6 @@ class PlatformMessageResponseDarwin : public blink::PlatformMessageResponse { [self setupNotificationCenterObservers]; - [self connectToEngineAndLoad]; } - (void)setupNotificationCenterObservers { @@ -225,6 +225,11 @@ class PlatformMessageResponseDarwin : public blink::PlatformMessageResponse { object:nil]; } + +- (void)setInitialRoute:(NSString*)route { + [_navigationChannel.get() invokeMethod:@"setInitialRoute" + arguments:route]; +} #pragma mark - Initializing the engine - (void)alertView:(UIAlertView*)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { @@ -232,6 +237,10 @@ class PlatformMessageResponseDarwin : public blink::PlatformMessageResponse { } - (void)connectToEngineAndLoad { + if (_connected) + return; + _connected = YES; + TRACE_EVENT0("flutter", "connectToEngineAndLoad"); // We ask the VM to check what it supports. @@ -264,6 +273,11 @@ class PlatformMessageResponseDarwin : public blink::PlatformMessageResponse { [view release]; } +- (void)viewWillAppear:(BOOL)animated { + [self connectToEngineAndLoad]; + [super viewWillAppear:animated]; +} + #pragma mark - Application lifecycle notifications - (void)applicationBecameActive:(NSNotification*)notification {