Skip to content

Commit 894f27e

Browse files
Make FlutterSceneLifeCycleProvider.sceneLifeCycleDelegate readonly (flutter#177240)
And add documentation that says it should not change because the delegate implementation is stateful. ## Pre-launch Checklist - [ ] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [ ] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [ ] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [ ] I signed the [CLA]. - [ ] I listed at least one issue that this PR fixes in the description above. - [ ] I updated/added relevant documentation (doc comments with `///`). - [ ] I added new tests to check the change I am making, or this PR is [test-exempt]. - [ ] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [ ] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
1 parent 3d3e2eb commit 894f27e

File tree

4 files changed

+29
-7
lines changed

4 files changed

+29
-7
lines changed

dev/integration_tests/ios_add2app_uiscene/native/SceneDelegate-FlutterSceneLifeCycleProvider.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ import UIKit
88
class SceneDelegate: UIResponder, UIWindowSceneDelegate,
99
FlutterSceneLifeCycleProvider
1010
{
11-
var sceneLifeCycleDelegate: FlutterPluginSceneLifeCycleDelegate =
12-
FlutterPluginSceneLifeCycleDelegate()
11+
let sceneLifeCycleDelegate = FlutterPluginSceneLifeCycleDelegate()
1312

1413
var window: UIWindow?
1514

dev/integration_tests/ios_add2app_uiscene/native/SwiftUIApp-FlutterSceneLifeCycleProvider.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate,
3838
FlutterSceneLifeCycleProvider
3939
{
4040

41-
var sceneLifeCycleDelegate: FlutterPluginSceneLifeCycleDelegate =
42-
FlutterPluginSceneLifeCycleDelegate()
41+
let sceneLifeCycleDelegate = FlutterPluginSceneLifeCycleDelegate()
4342

4443
var window: UIWindow?
4544

engine/src/flutter/shell/platform/darwin/ios/framework/Headers/FlutterSceneLifeCycle.h

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,11 +207,25 @@ API_AVAILABLE(ios(13.0))
207207
* `FlutterPluginSceneLifeCycleDelegate` that can be used to forward scene life-cycle events to
208208
* Flutter plugins.
209209
*
210-
* This is typically implemented by the app's `SceneDelegate`.
210+
* This is typically implemented by the app's `SceneDelegate`, as a `FlutterSceneLifeCycleProvider`
211+
* is associated with one and only one `UIScene`.
211212
*/
212213
API_AVAILABLE(ios(13.0))
213214
@protocol FlutterSceneLifeCycleProvider
214-
@property(nonatomic, strong) FlutterPluginSceneLifeCycleDelegate* sceneLifeCycleDelegate;
215+
216+
/**
217+
* The `FlutterPluginSceneLifeCycleDelegate` instance for forwarding `UIScene` events
218+
* to plugins associated with this `UIScene`.
219+
*
220+
* The implementer of this protocol is responsible for creating the
221+
* `FlutterPluginSceneLifeCycleDelegate` object, as well as forwarding `UIScene` events
222+
* to plugins by calling the corresponding methods defined on
223+
* `FlutterPluginSceneLifeCycleDelegate`.
224+
*
225+
* The `FlutterPluginSceneLifeCycleDelegate` implementation is stateful. For this reason,
226+
* this property getter should typically always return the same object.
227+
*/
228+
@property(nonatomic, readonly) FlutterPluginSceneLifeCycleDelegate* sceneLifeCycleDelegate;
215229
@end
216230

217231
NS_ASSUME_NONNULL_END

engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterSceneLifeCycleTest.mm

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
// This class is meant to mimic the SceneDelegate class generated by SwiftUI that does not conform
2222
// FlutterSceneLifeCycleProvider but actually does.
2323
@interface FlutterSwiftUIAppSceneDelegate : NSObject
24-
@property(nonatomic, strong) FlutterPluginSceneLifeCycleDelegate* sceneLifeCycleDelegate;
24+
@property(nonatomic, readonly) FlutterPluginSceneLifeCycleDelegate* sceneLifeCycleDelegate;
2525
@end
2626

2727
@implementation FlutterSwiftUIAppSceneDelegate
@@ -36,6 +36,16 @@ - (instancetype)init {
3636
}
3737
@end
3838

39+
// This class is not referenced in test because it's a test itself. The implementation
40+
// verifies that sceneLifeCycleDelegate is a readonly property.
41+
@interface TestSceneLifecycleProvider : NSObject <FlutterSceneLifeCycleProvider>
42+
@end
43+
@implementation TestSceneLifecycleProvider
44+
- (FlutterPluginSceneLifeCycleDelegate*)sceneLifeCycleDelegate {
45+
return [[FlutterPluginSceneLifeCycleDelegate alloc] init];
46+
}
47+
@end
48+
3949
@interface FlutterSceneLifecycleTest : XCTestCase
4050
@end
4151

0 commit comments

Comments
 (0)