From 453d549a26fc62b9476a402754d1ebaf88f16d00 Mon Sep 17 00:00:00 2001 From: Xiao Yu Date: Sat, 31 Aug 2019 01:38:19 -0700 Subject: [PATCH 1/6] Annotate nullability on FlutterEngine to make swift writing slightly more ergonomic --- .../ios/framework/Headers/FlutterEngine.h | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Headers/FlutterEngine.h b/shell/platform/darwin/ios/framework/Headers/FlutterEngine.h index c65bef707b78c..6b5e12344017f 100644 --- a/shell/platform/darwin/ios/framework/Headers/FlutterEngine.h +++ b/shell/platform/darwin/ios/framework/Headers/FlutterEngine.h @@ -58,7 +58,7 @@ FLUTTER_EXPORT * the threads used by this FlutterEngine. * @param projectOrNil The `FlutterDartProject` to run. */ -- (instancetype)initWithName:(NSString*)labelPrefix project:(FlutterDartProject*)projectOrNil; +- (nonnull instancetype)initWithName:(nonnull NSString*)labelPrefix project:(nullable FlutterDartProject*)projectOrNil; /** * Initialize this FlutterEngine with a `FlutterDartProject`. @@ -77,17 +77,17 @@ FLUTTER_EXPORT * @param allowHeadlessExecution Whether or not to allow this instance to continue * running after passing a nil `FlutterViewController` to `-setViewController:`. */ -- (instancetype)initWithName:(NSString*)labelPrefix - project:(FlutterDartProject*)projectOrNil +- (nonnull instancetype)initWithName:(nonnull NSString*)labelPrefix + project:(nullable FlutterDartProject*)projectOrNil allowHeadlessExecution:(BOOL)allowHeadlessExecution NS_DESIGNATED_INITIALIZER; /** * The default initializer is not available for this object. * Callers must use `-[FlutterEngine initWithName:project:]`. */ -- (instancetype)init NS_UNAVAILABLE; +- (nullable instancetype)init NS_UNAVAILABLE; -+ (instancetype)new NS_UNAVAILABLE; ++ (nullable instancetype)new NS_UNAVAILABLE; /** * Runs a Dart program on an Isolate from the main Dart library (i.e. the library that @@ -103,7 +103,7 @@ FLUTTER_EXPORT * tree-shaken by the Dart compiler. * @return YES if the call succeeds in creating and running a Flutter Engine instance; NO otherwise. */ -- (BOOL)runWithEntrypoint:(NSString*)entrypoint; +- (BOOL)runWithEntrypoint:(nullable NSString*)entrypoint; /** * Runs a Dart program on an Isolate using the specified entrypoint and Dart library, @@ -120,7 +120,7 @@ FLUTTER_EXPORT * 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. */ -- (BOOL)runWithEntrypoint:(NSString*)entrypoint libraryURI:(NSString*)uri; +- (BOOL)runWithEntrypoint:(nullable NSString*)entrypoint libraryURI:(nullable NSString*)uri; /** * Destroy running context for an engine. @@ -172,13 +172,13 @@ FLUTTER_EXPORT * it will signal the engine to stop animations and drawing. However, neither will impact the state * of the Dart program's execution. */ -@property(nonatomic, weak) FlutterViewController* viewController; +@property(nonatomic, weak, nullable) FlutterViewController* viewController; /** * The `FlutterMethodChannel` used for localization related platform messages, such as * setting the locale. */ -@property(nonatomic, readonly) FlutterMethodChannel* localizationChannel; +@property(nonatomic, readonly, nonnull) FlutterMethodChannel* localizationChannel; /** * The `FlutterMethodChannel` used for navigation related platform messages. * @@ -186,13 +186,13 @@ FLUTTER_EXPORT * Channel](https://docs.flutter.io/flutter/services/SystemChannels/navigation-constant.html) * @see [Navigator Widget](https://docs.flutter.io/flutter/widgets/Navigator-class.html) */ -@property(nonatomic, readonly) FlutterMethodChannel* navigationChannel; +@property(nonatomic, readonly, nonnull) FlutterMethodChannel* navigationChannel; /** * The `FlutterMethodChannel` used for core platform messages, such as * information about the screen orientation. */ -@property(nonatomic, readonly) FlutterMethodChannel* platformChannel; +@property(nonatomic, readonly, nonnull) FlutterMethodChannel* platformChannel; /** * The `FlutterMethodChannel` used to communicate text input events to the @@ -201,7 +201,7 @@ FLUTTER_EXPORT * @see [Text Input * Channel](https://docs.flutter.io/flutter/services/SystemChannels/textInput-constant.html) */ -@property(nonatomic, readonly) FlutterMethodChannel* textInputChannel; +@property(nonatomic, readonly, nonnull) FlutterMethodChannel* textInputChannel; /** * The `FlutterBasicMessageChannel` used to communicate app lifecycle events @@ -210,7 +210,7 @@ FLUTTER_EXPORT * @see [Lifecycle * Channel](https://docs.flutter.io/flutter/services/SystemChannels/lifecycle-constant.html) */ -@property(nonatomic, readonly) FlutterBasicMessageChannel* lifecycleChannel; +@property(nonatomic, readonly, nonnull) FlutterBasicMessageChannel* lifecycleChannel; /** * The `FlutterBasicMessageChannel` used for communicating system events, such as @@ -219,13 +219,13 @@ FLUTTER_EXPORT * @see [System * Channel](https://docs.flutter.io/flutter/services/SystemChannels/system-constant.html) */ -@property(nonatomic, readonly) FlutterBasicMessageChannel* systemChannel; +@property(nonatomic, readonly, nonnull) FlutterBasicMessageChannel* systemChannel; /** * The `FlutterBasicMessageChannel` used for communicating user settings such as * clock format and text scale. */ -@property(nonatomic, readonly) FlutterBasicMessageChannel* settingsChannel; +@property(nonatomic, readonly, nonnull) FlutterBasicMessageChannel* settingsChannel; /** * The `NSURL` of the observatory for the service isolate. @@ -234,20 +234,20 @@ FLUTTER_EXPORT * observatory service is ready. In release mode or before the observatory has * started, it returns `nil`. */ -@property(nonatomic, readonly) NSURL* observatoryUrl; +@property(nonatomic, readonly, nullable) NSURL* observatoryUrl; /** * The `FlutterBinaryMessenger` associated with this FlutterEngine (used for communicating with * channels). */ -@property(nonatomic, readonly) NSObject* binaryMessenger; +@property(nonatomic, readonly, nonnull) NSObject* binaryMessenger; /** * The UI Isolate ID of of the engine. * * This property will be nil if the engine is not running. */ -@property(nonatomic, readonly, copy) NSString* isolateId; +@property(nonatomic, readonly, copy, nullable) NSString* isolateId; @end From 0ebce580a499653d379cd5fa133b454a0d87e6fd Mon Sep 17 00:00:00 2001 From: Xiao Yu Date: Tue, 3 Sep 2019 11:21:04 -0700 Subject: [PATCH 2/6] review --- .../darwin/ios/framework/Headers/FlutterEngine.h | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/shell/platform/darwin/ios/framework/Headers/FlutterEngine.h b/shell/platform/darwin/ios/framework/Headers/FlutterEngine.h index 6b5e12344017f..7e52c872a1635 100644 --- a/shell/platform/darwin/ios/framework/Headers/FlutterEngine.h +++ b/shell/platform/darwin/ios/framework/Headers/FlutterEngine.h @@ -177,11 +177,15 @@ FLUTTER_EXPORT /** * The `FlutterMethodChannel` used for localization related platform messages, such as * setting the locale. + * + * Can be nil after `destroyContext` is called. */ -@property(nonatomic, readonly, nonnull) FlutterMethodChannel* localizationChannel; +@property(nonatomic, readonly, nullable) FlutterMethodChannel* localizationChannel; /** * The `FlutterMethodChannel` used for navigation related platform messages. * + * Can be nil after `destroyContext` is called. + * * @see [Navigation * Channel](https://docs.flutter.io/flutter/services/SystemChannels/navigation-constant.html) * @see [Navigator Widget](https://docs.flutter.io/flutter/widgets/Navigator-class.html) @@ -191,6 +195,8 @@ FLUTTER_EXPORT /** * The `FlutterMethodChannel` used for core platform messages, such as * information about the screen orientation. + * + * Can be nil after `destroyContext` is called. */ @property(nonatomic, readonly, nonnull) FlutterMethodChannel* platformChannel; @@ -198,6 +204,8 @@ FLUTTER_EXPORT * The `FlutterMethodChannel` used to communicate text input events to the * Dart Isolate. * + * Can be nil after `destroyContext` is called. + * * @see [Text Input * Channel](https://docs.flutter.io/flutter/services/SystemChannels/textInput-constant.html) */ @@ -207,6 +215,8 @@ FLUTTER_EXPORT * The `FlutterBasicMessageChannel` used to communicate app lifecycle events * to the Dart Isolate. * + * Can be nil after `destroyContext` is called. + * * @see [Lifecycle * Channel](https://docs.flutter.io/flutter/services/SystemChannels/lifecycle-constant.html) */ @@ -216,6 +226,8 @@ FLUTTER_EXPORT * The `FlutterBasicMessageChannel` used for communicating system events, such as * memory pressure events. * + * Can be nil after `destroyContext` is called. + * * @see [System * Channel](https://docs.flutter.io/flutter/services/SystemChannels/system-constant.html) */ @@ -224,6 +236,8 @@ FLUTTER_EXPORT /** * The `FlutterBasicMessageChannel` used for communicating user settings such as * clock format and text scale. + * + * Can be nil after `destroyContext` is called. */ @property(nonatomic, readonly, nonnull) FlutterBasicMessageChannel* settingsChannel; From 600bfa4dfb0fb4b19e0846c4c8bd3dd16a410586 Mon Sep 17 00:00:00 2001 From: Xiao Yu Date: Tue, 3 Sep 2019 15:04:54 -0700 Subject: [PATCH 3/6] use nonnull_begin/end --- .../ios/framework/Headers/FlutterEngine.h | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Headers/FlutterEngine.h b/shell/platform/darwin/ios/framework/Headers/FlutterEngine.h index 7e52c872a1635..2966927a0a4dd 100644 --- a/shell/platform/darwin/ios/framework/Headers/FlutterEngine.h +++ b/shell/platform/darwin/ios/framework/Headers/FlutterEngine.h @@ -14,6 +14,8 @@ #include "FlutterPlugin.h" #include "FlutterTexture.h" +NS_ASSUME_NONNULL_BEGIN + @class FlutterViewController; /** @@ -58,7 +60,7 @@ FLUTTER_EXPORT * the threads used by this FlutterEngine. * @param projectOrNil The `FlutterDartProject` to run. */ -- (nonnull instancetype)initWithName:(nonnull NSString*)labelPrefix project:(nullable FlutterDartProject*)projectOrNil; +- (instancetype)initWithName:(NSString*)labelPrefix project:(nullable FlutterDartProject*)projectOrNil; /** * Initialize this FlutterEngine with a `FlutterDartProject`. @@ -77,7 +79,7 @@ FLUTTER_EXPORT * @param allowHeadlessExecution Whether or not to allow this instance to continue * running after passing a nil `FlutterViewController` to `-setViewController:`. */ -- (nonnull instancetype)initWithName:(nonnull NSString*)labelPrefix +- (instancetype)initWithName:(NSString*)labelPrefix project:(nullable FlutterDartProject*)projectOrNil allowHeadlessExecution:(BOOL)allowHeadlessExecution NS_DESIGNATED_INITIALIZER; @@ -190,7 +192,7 @@ FLUTTER_EXPORT * Channel](https://docs.flutter.io/flutter/services/SystemChannels/navigation-constant.html) * @see [Navigator Widget](https://docs.flutter.io/flutter/widgets/Navigator-class.html) */ -@property(nonatomic, readonly, nonnull) FlutterMethodChannel* navigationChannel; +@property(nonatomic, readonly) FlutterMethodChannel* navigationChannel; /** * The `FlutterMethodChannel` used for core platform messages, such as @@ -198,7 +200,7 @@ FLUTTER_EXPORT * * Can be nil after `destroyContext` is called. */ -@property(nonatomic, readonly, nonnull) FlutterMethodChannel* platformChannel; +@property(nonatomic, readonly) FlutterMethodChannel* platformChannel; /** * The `FlutterMethodChannel` used to communicate text input events to the @@ -209,7 +211,7 @@ FLUTTER_EXPORT * @see [Text Input * Channel](https://docs.flutter.io/flutter/services/SystemChannels/textInput-constant.html) */ -@property(nonatomic, readonly, nonnull) FlutterMethodChannel* textInputChannel; +@property(nonatomic, readonly) FlutterMethodChannel* textInputChannel; /** * The `FlutterBasicMessageChannel` used to communicate app lifecycle events @@ -220,7 +222,7 @@ FLUTTER_EXPORT * @see [Lifecycle * Channel](https://docs.flutter.io/flutter/services/SystemChannels/lifecycle-constant.html) */ -@property(nonatomic, readonly, nonnull) FlutterBasicMessageChannel* lifecycleChannel; +@property(nonatomic, readonly) FlutterBasicMessageChannel* lifecycleChannel; /** * The `FlutterBasicMessageChannel` used for communicating system events, such as @@ -231,7 +233,7 @@ FLUTTER_EXPORT * @see [System * Channel](https://docs.flutter.io/flutter/services/SystemChannels/system-constant.html) */ -@property(nonatomic, readonly, nonnull) FlutterBasicMessageChannel* systemChannel; +@property(nonatomic, readonly) FlutterBasicMessageChannel* systemChannel; /** * The `FlutterBasicMessageChannel` used for communicating user settings such as @@ -239,7 +241,7 @@ FLUTTER_EXPORT * * Can be nil after `destroyContext` is called. */ -@property(nonatomic, readonly, nonnull) FlutterBasicMessageChannel* settingsChannel; +@property(nonatomic, readonly) FlutterBasicMessageChannel* settingsChannel; /** * The `NSURL` of the observatory for the service isolate. @@ -254,7 +256,7 @@ FLUTTER_EXPORT * The `FlutterBinaryMessenger` associated with this FlutterEngine (used for communicating with * channels). */ -@property(nonatomic, readonly, nonnull) NSObject* binaryMessenger; +@property(nonatomic, readonly) NSObject* binaryMessenger; /** * The UI Isolate ID of of the engine. @@ -265,4 +267,6 @@ FLUTTER_EXPORT @end +NS_ASSUME_NONNULL_END + #endif // FLUTTER_FLUTTERENGINE_H_ From ec587652572cafdeb0ef1821302eecc676165e0b Mon Sep 17 00:00:00 2001 From: Xiao Yu Date: Tue, 3 Sep 2019 15:10:23 -0700 Subject: [PATCH 4/6] autoformat --- shell/platform/darwin/ios/framework/Headers/FlutterEngine.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/shell/platform/darwin/ios/framework/Headers/FlutterEngine.h b/shell/platform/darwin/ios/framework/Headers/FlutterEngine.h index 2966927a0a4dd..f13a8fb507ea6 100644 --- a/shell/platform/darwin/ios/framework/Headers/FlutterEngine.h +++ b/shell/platform/darwin/ios/framework/Headers/FlutterEngine.h @@ -60,7 +60,8 @@ FLUTTER_EXPORT * the threads used by this FlutterEngine. * @param projectOrNil The `FlutterDartProject` to run. */ -- (instancetype)initWithName:(NSString*)labelPrefix project:(nullable FlutterDartProject*)projectOrNil; +- (instancetype)initWithName:(NSString*)labelPrefix + project:(nullable FlutterDartProject*)projectOrNil; /** * Initialize this FlutterEngine with a `FlutterDartProject`. From 63999d8639c9a5d9eb27cb57d09e65abcb38c6ca Mon Sep 17 00:00:00 2001 From: Xiao Yu Date: Wed, 4 Sep 2019 15:31:36 -0700 Subject: [PATCH 5/6] review --- .../ios/framework/Headers/FlutterEngine.h | 18 +++++++++--------- .../ios/framework/Source/FlutterEngine.mm | 10 +++++----- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Headers/FlutterEngine.h b/shell/platform/darwin/ios/framework/Headers/FlutterEngine.h index f13a8fb507ea6..2a0509e4d32b3 100644 --- a/shell/platform/darwin/ios/framework/Headers/FlutterEngine.h +++ b/shell/platform/darwin/ios/framework/Headers/FlutterEngine.h @@ -14,10 +14,10 @@ #include "FlutterPlugin.h" #include "FlutterTexture.h" -NS_ASSUME_NONNULL_BEGIN - @class FlutterViewController; +NS_ASSUME_NONNULL_BEGIN + /** * The FlutterEngine class coordinates a single instance of execution for a * `FlutterDartProject`. It may have zero or one `FlutterViewController` at a @@ -58,10 +58,10 @@ FLUTTER_EXPORT * @param labelPrefix The label prefix used to identify threads for this instance. Should * be unique across FlutterEngine instances, and is used in instrumentation to label * the threads used by this FlutterEngine. - * @param projectOrNil The `FlutterDartProject` to run. + * @param project The `FlutterDartProject` to run. */ - (instancetype)initWithName:(NSString*)labelPrefix - project:(nullable FlutterDartProject*)projectOrNil; + project:(nullable FlutterDartProject*)project; /** * Initialize this FlutterEngine with a `FlutterDartProject`. @@ -76,21 +76,21 @@ FLUTTER_EXPORT * @param labelPrefix The label prefix used to identify threads for this instance. Should * be unique across FlutterEngine instances, and is used in instrumentation to label * the threads used by this FlutterEngine. - * @param projectOrNil The `FlutterDartProject` to run. + * @param project The `FlutterDartProject` to run. * @param allowHeadlessExecution Whether or not to allow this instance to continue * running after passing a nil `FlutterViewController` to `-setViewController:`. */ - (instancetype)initWithName:(NSString*)labelPrefix - project:(nullable FlutterDartProject*)projectOrNil + project:(nullable FlutterDartProject*)project allowHeadlessExecution:(BOOL)allowHeadlessExecution NS_DESIGNATED_INITIALIZER; /** * The default initializer is not available for this object. * Callers must use `-[FlutterEngine initWithName:project:]`. */ -- (nullable instancetype)init NS_UNAVAILABLE; +- (instancetype)init NS_UNAVAILABLE; -+ (nullable instancetype)new NS_UNAVAILABLE; ++ (instancetype)new NS_UNAVAILABLE; /** * Runs a Dart program on an Isolate from the main Dart library (i.e. the library that @@ -175,7 +175,7 @@ FLUTTER_EXPORT * it will signal the engine to stop animations and drawing. However, neither will impact the state * of the Dart program's execution. */ -@property(nonatomic, weak, nullable) FlutterViewController* viewController; +@property(nonatomic, weak) FlutterViewController* viewController; /** * The `FlutterMethodChannel` used for localization related platform messages, such as diff --git a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm index ad7cfc263ee5d..2c8dad0dd5407 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm @@ -69,12 +69,12 @@ @implementation FlutterEngine { FlutterBinaryMessengerRelay* _binaryMessenger; } -- (instancetype)initWithName:(NSString*)labelPrefix project:(FlutterDartProject*)projectOrNil { - return [self initWithName:labelPrefix project:projectOrNil allowHeadlessExecution:YES]; +- (instancetype)initWithName:(NSString*)labelPrefix project:(FlutterDartProject*)project { + return [self initWithName:labelPrefix project:project allowHeadlessExecution:YES]; } - (instancetype)initWithName:(NSString*)labelPrefix - project:(FlutterDartProject*)projectOrNil + project:(FlutterDartProject*)project allowHeadlessExecution:(BOOL)allowHeadlessExecution { self = [super init]; NSAssert(self, @"Super init cannot be nil"); @@ -85,10 +85,10 @@ - (instancetype)initWithName:(NSString*)labelPrefix _weakFactory = std::make_unique>(self); - if (projectOrNil == nil) + if (project == nil) _dartProject.reset([[FlutterDartProject alloc] init]); else - _dartProject.reset([projectOrNil retain]); + _dartProject.reset([project retain]); _pluginPublications = [NSMutableDictionary new]; _platformViewsController.reset(new flutter::FlutterPlatformViewsController()); From 50aa44e0cc13bf34ce1e14d7c699e626fb6cc6f8 Mon Sep 17 00:00:00 2001 From: Xiao Yu Date: Wed, 4 Sep 2019 15:40:08 -0700 Subject: [PATCH 6/6] autoformat again --- shell/platform/darwin/ios/framework/Headers/FlutterEngine.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Headers/FlutterEngine.h b/shell/platform/darwin/ios/framework/Headers/FlutterEngine.h index 2a0509e4d32b3..ce0385f6672fb 100644 --- a/shell/platform/darwin/ios/framework/Headers/FlutterEngine.h +++ b/shell/platform/darwin/ios/framework/Headers/FlutterEngine.h @@ -60,8 +60,7 @@ FLUTTER_EXPORT * the threads used by this FlutterEngine. * @param project The `FlutterDartProject` to run. */ -- (instancetype)initWithName:(NSString*)labelPrefix - project:(nullable FlutterDartProject*)project; +- (instancetype)initWithName:(NSString*)labelPrefix project:(nullable FlutterDartProject*)project; /** * Initialize this FlutterEngine with a `FlutterDartProject`.