This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
[macOS] Consolidate view management #52254
Merged
dkwingsmt
merged 7 commits into
flutter:main
from
dkwingsmt:consolidate-view-management
Apr 19, 2024
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f783266
Impl
dkwingsmt 26f6b0f
Remove useless code
dkwingsmt a778212
Better doc
dkwingsmt 850a468
Remove extra changes
dkwingsmt 84ba335
Better doc
dkwingsmt 6f459e7
Remove extra space
dkwingsmt 6e810f1
Fix some docs
dkwingsmt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -456,9 +456,6 @@ @implementation FlutterEngine { | |||||||
|
|
||||||||
| FlutterThreadSynchronizer* _threadSynchronizer; | ||||||||
|
|
||||||||
| // The next available view ID. | ||||||||
| int _nextviewIdentifier; | ||||||||
|
|
||||||||
| // Whether the application is currently the active application. | ||||||||
| BOOL _active; | ||||||||
|
|
||||||||
|
|
@@ -515,8 +512,6 @@ - (instancetype)initWithName:(NSString*)labelPrefix | |||||||
| _binaryMessenger = [[FlutterBinaryMessengerRelay alloc] initWithParent:self]; | ||||||||
| _isResponseValid = [[NSMutableArray alloc] initWithCapacity:1]; | ||||||||
| [_isResponseValid addObject:@YES]; | ||||||||
| // kFlutterImplicitViewId is reserved for the implicit view. | ||||||||
| _nextviewIdentifier = kFlutterImplicitViewId + 1; | ||||||||
|
|
||||||||
| _embedderAPI.struct_size = sizeof(FlutterEngineProcTable); | ||||||||
| FlutterEngineGetProcAddresses(&_embedderAPI); | ||||||||
|
|
@@ -736,15 +731,21 @@ - (void)loadAOTData:(NSString*)assetsDir { | |||||||
| - (void)registerViewController:(FlutterViewController*)controller | ||||||||
| forIdentifier:(FlutterViewIdentifier)viewIdentifier { | ||||||||
| NSAssert(controller != nil, @"The controller must not be nil."); | ||||||||
| NSAssert(![controller attached], | ||||||||
| @"The incoming view controller is already attached to an engine."); | ||||||||
| NSAssert(controller.engine == nil, | ||||||||
| @"The FlutterViewController is unexpectedly attached to " | ||||||||
| @"engine %@ before initialization.", | ||||||||
| controller.engine); | ||||||||
| NSAssert([_viewControllers objectForKey:@(viewIdentifier)] == nil, | ||||||||
| @"The requested view ID is occupied."); | ||||||||
| [_viewControllers setObject:controller forKey:@(viewIdentifier)]; | ||||||||
| [controller setUpWithEngine:self | ||||||||
| viewIdentifier:viewIdentifier | ||||||||
| threadSynchronizer:_threadSynchronizer]; | ||||||||
| NSAssert(controller.viewIdentifier == viewIdentifier, @"Failed to assign view ID."); | ||||||||
| [_viewControllers setObject:controller forKey:@(viewIdentifier)]; | ||||||||
| NSAssert(controller.attached && controller.engine == self, | ||||||||
| @"The FlutterViewController unexpectedly stays unattached after being added. " | ||||||||
|
||||||||
| @"In unit tests, this is likely because either the FlutterViewController or " | ||||||||
| @"the FlutterEngine is mocked. Please subclass these classes instead."); | ||||||||
|
|
||||||||
| if (controller.viewLoaded) { | ||||||||
| [self viewControllerViewDidLoad:controller]; | ||||||||
|
|
@@ -779,11 +780,17 @@ - (void)viewControllerViewDidLoad:(FlutterViewController*)viewController { | |||||||
| } | ||||||||
|
|
||||||||
| - (void)deregisterViewControllerForIdentifier:(FlutterViewIdentifier)viewIdentifier { | ||||||||
| FlutterViewController* oldController = [self viewControllerForIdentifier:viewIdentifier]; | ||||||||
| if (oldController != nil) { | ||||||||
| [oldController detachFromEngine]; | ||||||||
| [_viewControllers removeObjectForKey:@(viewIdentifier)]; | ||||||||
| FlutterViewController* controller = [self viewControllerForIdentifier:viewIdentifier]; | ||||||||
| // The controller might be nil, because the engine only stores a weak ref, and | ||||||||
| // this method might have been called from the controller's dealloc. | ||||||||
|
||||||||
| // The controller might be nil, because the engine only stores a weak ref, and | |
| // this method might have been called from the controller's dealloc. | |
| // The controller can be nil. The engine stores only a weak ref, this method could have been called from the controller's dealloc. |
I don't feel strongly, feel free to keep as is
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we separate the "attached to an unexpected engine" to a separate assertion? Currently, the assertion message you'll get for this scenario would be confusing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I combined them initially because the "suggestion" part is too long. I now moved the "suggestion" part to in-code comment and only left the symptom to the assertion. Let me know if they still feel off.