1 // Copyright 2013 The Flutter Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef FLUTTER_FLUTTERVIEWCONTROLLER_H_ 6 #define FLUTTER_FLUTTERVIEWCONTROLLER_H_ 7 8 #import <UIKit/UIKit.h> 9 #include <sys/cdefs.h> 10 11 #include "FlutterEngine.h" 12 #include "FlutterMacros.h" 13 #include "FlutterPlugin.h" 14 #include "FlutterTexture.h" 15 16 @class FlutterEngine; 17 18 /** 19 * The name used for semantic update notifications via `NSNotificationCenter`. 20 * 21 * The object passed as the sender is the `FlutterViewController` associated 22 * with the update. 23 */ 24 FLUTTER_EXPORT 25 extern NSNotificationName const FlutterSemanticsUpdateNotification; 26 27 /** 28 * A `UIViewController` implementation for Flutter views. 29 * 30 * Dart execution, channel communication, texture registration, and plugin registration are all 31 * handled by `FlutterEngine`. Calls on this class to those members all proxy through to the 32 * `FlutterEngine` attached FlutterViewController. 33 * 34 * A FlutterViewController can be initialized either with an already-running `FlutterEngine` via 35 * the `initWithEngine:` initializer, or it can be initialized with a `FlutterDartProject` that 36 * will be used to implicitly spin up a new `FlutterEngine`. Creating a `FlutterEngine before 37 * showing a `FlutterViewController` can be used to pre-initialize the Dart VM and to prepare the 38 * isolate in order to reduce the latency to the first rendered frame. Holding a `FlutterEngine` 39 * independently of FlutterViewControllers can also be used to not to lose Dart-related state and 40 * asynchronous tasks when navigating back and forth between a FlutterViewController and other 41 * `UIViewController`s. 42 */ 43 FLUTTER_EXPORT 44 @interface FlutterViewController : UIViewController <FlutterTextureRegistry, FlutterPluginRegistry> 45 46 /** 47 * Initializes this FlutterViewController with the specified `FlutterEngine`. 48 * 49 * The initialized viewcontroller will attach itself to the engine as part of this process. 50 * 51 * @param engine The `FlutterEngine` instance to attach to. 52 * @param nibNameOrNil The NIB name to initialize this UIViewController with. 53 * @param nibBundleOrNil The NIB bundle. 54 */ 55 - (instancetype)initWithEngine:(FlutterEngine*)engine 56 nibName:(NSString*)nibNameOrNil 57 bundle:(NSBundle*)nibBundleOrNil NS_DESIGNATED_INITIALIZER; 58 59 /** 60 * Initializes a new FlutterViewController and `FlutterEngine` with the specified 61 * `FlutterDartProject`. 62 * 63 * @param projectOrNil The `FlutterDartProject` to initialize the `FlutterEngine` with. 64 * @param nibNameOrNil The NIB name to initialize this UIViewController with. 65 * @param nibBundleOrNil The NIB bundle. 66 */ 67 - (instancetype)initWithName:(NSString*)nibNameOrNil 68 bundle:(NSBundle*)nibBundleOrNil NS_DESIGNATED_INITIALIZER; 69 70 - (void)handleStatusBarTouches:(UIEvent*)event; 71 72 /** 73 * Registers a callback that will be invoked when the Flutter view has been rendered. 74 * The callback will be fired only once. 75 * 76 * Replaces an existing callback. Use a `nil` callback to unregister the existing one. 77 */ 78 - (void)setFlutterViewDidRenderCallback:(void (^)(void))callback; 79 80 /** 81 * Returns the file name for the given asset. 82 * The returned file name can be used to access the asset in the application's 83 * main bundle. 84 * 85 * @param asset The name of the asset. The name can be hierarchical. 86 * @return The file name to be used for lookup in the main bundle. 87 */ 88 - (NSString*)lookupKeyForAsset:(NSString*)asset; 89 90 /** 91 * Returns the file name for the given asset which originates from the specified 92 * package. 93 * The returned file name can be used to access the asset in the application's 94 * main bundle. 95 * 96 * @param asset The name of the asset. The name can be hierarchical. 97 * @param package The name of the package from which the asset originates. 98 * @return The file name to be used for lookup in the main bundle. 99 */ 100 - (NSString*)lookupKeyForAsset:(NSString*)asset fromPackage:(NSString*)package; 101 102 /** 103 * Sets the first route that the Flutter app shows. The default is "/". 104 * This method will guarnatee that the initial route is delivered, even if the 105 * Flutter window hasn't been created yet when called. It cannot be used to update 106 * the current route being shown in a visible FlutterViewController (see pushRoute 107 * and popRoute). 108 * 109 * @param route The name of the first route to show. 110 */ 111 - (void)setInitialRoute:(NSString*)route; 112 113 /** 114 * Instructs the Flutter Navigator (if any) to go back. 115 */ 116 - (void)popRoute; 117 118 /** 119 * Instructs the Flutter Navigator (if any) to push a route on to the navigation 120 * stack. The setInitialRoute method should be preferred if this is called before the 121 * FlutterViewController has come into view. 122 * 123 * @param route The name of the route to push to the navigation stack. 124 */ 125 - (void)pushRoute:(NSString*)route; 126 127 /** 128 * The `FlutterPluginRegistry` used by this FlutterViewController. 129 */ 130 - (id<FlutterPluginRegistry>)pluginRegistry; 131 132 /** 133 * True if at least one frame has rendered and the ViewController has appeared. 134 * 135 * This property is reset to false when the ViewController disappears. It is 136 * guaranteed to only alternate between true and false for observers. 137 */ 138 @property(nonatomic, readonly, getter=isDisplayingFlutterUI) BOOL displayingFlutterUI; 139 140 /** 141 * Specifies the view to use as a splash screen. Flutter's rendering is asynchronous, so the first 142 * frame rendered by the Flutter application might not immediately appear when theFlutter view is 143 * initially placed in the view hierarchy. The splash screen view will be used as 144 * a replacement until the first frame is rendered. 145 * 146 * The view used should be appropriate for multiple sizes; an autoresizing mask to 147 * have a flexible width and height will be applied automatically. 148 */ 149 @property(strong, nonatomic) UIView* splashScreenView; 150 151 /** 152 * Attempts to set the `splashScreenView` property from the `UILaunchStoryboardName` from the 153 * main bundle's `Info.plist` file. This method will not change the value of `splashScreenView` 154 * if it cannot find a default one from a storyboard or nib. 155 * 156 * @return `YES` if successful, `NO` otherwise. 157 */ 158 - (BOOL)loadDefaultSplashScreenView; 159 160 /** 161 * Controls whether the created view will be opaque or not. 162 * 163 * Default is `YES`. Note that setting this to `NO` may negatively impact performance 164 * when using hardware acceleration, and toggling this will trigger a re-layout of the 165 * view. 166 */ 167 @property(nonatomic, getter=isViewOpaque) BOOL viewOpaque; 168 169 /** 170 * The `FlutterEngine` instance for this view controller. 171 */ 172 @property(weak, nonatomic, readonly) FlutterEngine* engine; 173 174 /** 175 * The `FlutterBinaryMessenger` associated with this FlutterViewController (used for communicating 176 * with channels). 177 * 178 * This is just a convenient way to get the |FlutterEngine|'s binary messenger. 179 */ 180 @property(nonatomic, readonly) NSObject<FlutterBinaryMessenger>* binaryMessenger; 181 182 @end 183 184 #endif // FLUTTER_FLUTTERVIEWCONTROLLER_H_ 185