Skip to content

Commit

Permalink
[macOS] Rename FlutterViewController.id to viewId (flutter#40323)
Browse files Browse the repository at this point in the history
[macOS] Rename FlutterViewController.id to viewId
  • Loading branch information
cbracken authored Mar 15, 2023
1 parent fc88310 commit 903ea2e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ FLUTTER_DARWIN_EXPORT
* If the view controller is unattached (see FlutterViewController#attached),
* reading this property throws an assertion.
*/
@property(nonatomic, readonly) uint64_t id;
@property(nonatomic, readonly) uint64_t viewId;

/**
* The style of mouse tracking to use for the view. Defaults to
Expand Down
14 changes: 7 additions & 7 deletions shell/platform/darwin/macos/framework/Source/FlutterEngine.mm
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ - (void)registerViewController:(FlutterViewController*)controller forId:(uint64_
@"The incoming view controller is already attached to an engine.");
NSAssert([_viewControllers objectForKey:@(viewId)] == nil, @"The requested view ID is occupied.");
[controller attachToEngine:self withId:viewId];
NSAssert(controller.id == viewId, @"Failed to assign view ID.");
NSAssert(controller.viewId == viewId, @"Failed to assign view ID.");
[_viewControllers setObject:controller forKey:@(viewId)];
}

Expand All @@ -576,7 +576,7 @@ - (void)shutDownIfNeeded {

- (FlutterViewController*)viewControllerForId:(uint64_t)viewId {
FlutterViewController* controller = [_viewControllers objectForKey:@(viewId)];
NSAssert(controller == nil || controller.id == viewId,
NSAssert(controller == nil || controller.viewId == viewId,
@"The stored controller has unexpected view ID.");
return controller;
}
Expand All @@ -598,8 +598,8 @@ - (void)setViewController:(FlutterViewController*)controller {
controller.engine);
[self registerViewController:controller forId:kFlutterDefaultViewId];
} else if (currentController != nil && controller == nil) {
NSAssert(currentController.id == kFlutterDefaultViewId,
@"The default controller has an unexpected ID %llu", currentController.id);
NSAssert(currentController.viewId == kFlutterDefaultViewId,
@"The default controller has an unexpected ID %llu", currentController.viewId);
// From non-nil to nil.
[self deregisterViewControllerForId:kFlutterDefaultViewId];
[self shutDownIfNeeded];
Expand Down Expand Up @@ -669,7 +669,7 @@ - (void)addViewController:(FlutterViewController*)controller {
- (void)removeViewController:(nonnull FlutterViewController*)viewController {
NSAssert([viewController attached] && viewController.engine == self,
@"The given view controller is not associated with this engine.");
[self deregisterViewControllerForId:viewController.id];
[self deregisterViewControllerForId:viewController.viewId];
[self shutDownIfNeeded];
}

Expand Down Expand Up @@ -733,7 +733,7 @@ - (nonnull NSString*)executableName {
}

- (void)updateWindowMetricsForViewController:(FlutterViewController*)viewController {
if (viewController.id != kFlutterDefaultViewId) {
if (viewController.viewId != kFlutterDefaultViewId) {
// TODO(dkwingsmt): The embedder API only supports single-view for now. As
// embedder APIs are converted to multi-view, this method should support any
// views.
Expand All @@ -742,7 +742,7 @@ - (void)updateWindowMetricsForViewController:(FlutterViewController*)viewControl
if (!_engine || !viewController || !viewController.viewLoaded) {
return;
}
NSAssert([self viewControllerForId:viewController.id] == viewController,
NSAssert([self viewControllerForId:viewController.viewId] == viewController,
@"The provided view controller is not attached to this engine.");
NSView* view = viewController.flutterView;
CGRect scaledBounds = [view convertRectToBacking:view.bounds];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ - (nonnull NSView*)createWithViewIdentifier:(int64_t)viewId arguments:(nullable
@autoreleasepool {
// Create FVC1.
viewController1 = [[FlutterViewController alloc] initWithProject:project];
EXPECT_EQ(viewController1.id, 0ull);
EXPECT_EQ(viewController1.viewId, 0ull);

engine = viewController1.engine;
engine.viewController = nil;
Expand All @@ -663,7 +663,7 @@ - (nonnull NSView*)createWithViewIdentifier:(int64_t)viewId arguments:(nullable

engine.viewController = viewController1;
EXPECT_EQ(engine.viewController, viewController1);
EXPECT_EQ(viewController1.id, 0ull);
EXPECT_EQ(viewController1.viewId, 0ull);
}

TEST_F(FlutterEngineTest, ManageControllersIfInitiatedByEngine) {
Expand All @@ -677,15 +677,15 @@ - (nonnull NSView*)createWithViewIdentifier:(int64_t)viewId arguments:(nullable

@autoreleasepool {
viewController1 = [[FlutterViewController alloc] initWithEngine:engine nibName:nil bundle:nil];
EXPECT_EQ(viewController1.id, 0ull);
EXPECT_EQ(viewController1.viewId, 0ull);
EXPECT_EQ(engine.viewController, viewController1);

engine.viewController = nil;

FlutterViewController* viewController2 = [[FlutterViewController alloc] initWithEngine:engine
nibName:nil
bundle:nil];
EXPECT_EQ(viewController2.id, 0ull);
EXPECT_EQ(viewController2.viewId, 0ull);
EXPECT_EQ(engine.viewController, viewController2);
}
// FVC2 is deallocated but FVC1 is retained.
Expand All @@ -694,7 +694,7 @@ - (nonnull NSView*)createWithViewIdentifier:(int64_t)viewId arguments:(nullable

engine.viewController = viewController1;
EXPECT_EQ(engine.viewController, viewController1);
EXPECT_EQ(viewController1.id, 0ull);
EXPECT_EQ(viewController1.viewId, 0ull);
}

TEST_F(FlutterEngineTest, HandlesTerminationRequest) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,11 +315,9 @@ @implementation FlutterViewController {
FlutterDartProject* _project;

std::shared_ptr<flutter::AccessibilityBridgeMac> _bridge;

uint64_t _id;
}

@dynamic id;
@synthesize viewId = _viewId;
@dynamic view;
@dynamic accessibilityBridge;

Expand All @@ -341,7 +339,7 @@ static void CommonInit(FlutterViewController* controller, FlutterEngine* engine)
@"The FlutterViewController unexpectedly stays unattached after initialization. "
@"In unit tests, this is likely because either the FlutterViewController or "
@"the FlutterEngine is mocked. Please subclass these classes instead.",
controller.engine, controller.id);
controller.engine, controller.viewId);
controller->_mouseTrackingMode = FlutterMouseTrackingModeInKeyWindow;
controller->_textInputPlugin = [[FlutterTextInputPlugin alloc] initWithViewController:controller];
[controller initializeKeyboard];
Expand Down Expand Up @@ -457,9 +455,9 @@ - (void)setBackgroundColor:(NSColor*)color {
[_flutterView setBackgroundColor:_backgroundColor];
}

- (uint64_t)id {
- (uint64_t)viewId {
NSAssert([self attached], @"This view controller is not attched.");
return _id;
return _viewId;
}

- (void)onPreEngineRestart {
Expand Down Expand Up @@ -489,7 +487,7 @@ - (void)notifySemanticsEnabledChanged {
- (void)attachToEngine:(nonnull FlutterEngine*)engine withId:(uint64_t)viewId {
NSAssert(_engine == nil, @"Already attached to an engine %@.", _engine);
_engine = engine;
_id = viewId;
_viewId = viewId;
}

- (void)detachFromEngine {
Expand Down

0 comments on commit 903ea2e

Please sign in to comment.