diff --git a/shell/platform/darwin/ios/framework/Headers/FlutterViewController.h b/shell/platform/darwin/ios/framework/Headers/FlutterViewController.h index 2e8b02d0519..5459c17f4f8 100644 --- a/shell/platform/darwin/ios/framework/Headers/FlutterViewController.h +++ b/shell/platform/darwin/ios/framework/Headers/FlutterViewController.h @@ -24,6 +24,14 @@ FLUTTER_EXPORT - (void)handleStatusBarTouches:(UIEvent*)event; +/** + Registers a callback that will be invoked when the Flutter view has been rendered. + The callback will be fired only once. + + Replaces an existing callback. Use a `nil` callback to unregister the existing one. + */ +- (void)setFlutterViewDidRenderCallback:(void (^)(void))callback; + /** Returns the file name for the given asset. The returned file name can be used to access the asset in the application's main bundle. diff --git a/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm b/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm index 471e88e2dc5..ccbee6eebe8 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm @@ -51,6 +51,7 @@ // setup a shell along with its platform view before the view has to appear. fml::scoped_nsobject _flutterView; fml::scoped_nsobject _splashScreenView; + fml::ScopedBlock _flutterViewRenderedCallback; UIInterfaceOrientationMask _orientationPreferences; UIStatusBarStyle _statusBarStyle; blink::ViewportMetrics _viewportMetrics; @@ -367,6 +368,10 @@ completion:^(BOOL finished) { [_splashScreenView.get() removeFromSuperview]; _splashScreenView.reset(); + if (_flutterViewRenderedCallback != nil) { + _flutterViewRenderedCallback.get()(); + _flutterViewRenderedCallback.reset(); + } }]; } @@ -443,6 +448,10 @@ UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; } +- (void)setFlutterViewDidRenderCallback:(void (^)(void))callback { + _flutterViewRenderedCallback.reset(callback, fml::OwnershipPolicy::Retain); +} + #pragma mark - Surface creation and teardown updates - (void)surfaceUpdated:(BOOL)appeared {