-
Notifications
You must be signed in to change notification settings - Fork 6k
[macos] expose runWithEngine constructor in FlutterViewController (#7… #36410
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,6 +23,7 @@ - (bool)testFlagsChangedEventsArePropagatedIfNotHandled; | |
| - (bool)testKeyboardIsRestartedOnEngineRestart; | ||
| - (bool)testTrackpadGesturesAreSentToFramework; | ||
| - (bool)testViewWillAppearCalledMultipleTimes; | ||
| - (bool)testFlutterViewIsConfigured; | ||
|
|
||
| + (void)respondFalseForSendEvent:(const FlutterKeyEvent&)event | ||
| callback:(nullable FlutterKeyEventCallback)callback | ||
|
|
@@ -145,6 +146,10 @@ + (void)respondFalseForSendEvent:(const FlutterKeyEvent&)event | |
| ASSERT_TRUE([[FlutterViewControllerTestObjC alloc] testViewWillAppearCalledMultipleTimes]); | ||
| } | ||
|
|
||
| TEST(FlutterViewControllerTest, testFlutterViewIsConfigured) { | ||
| ASSERT_TRUE([[FlutterViewControllerTestObjC alloc] testFlutterViewIsConfigured]); | ||
| } | ||
|
|
||
| } // namespace flutter::testing | ||
|
|
||
| @implementation FlutterViewControllerTestObjC | ||
|
|
@@ -242,6 +247,27 @@ - (bool)testKeyEventsArePropagatedIfNotHandled { | |
| return true; | ||
| } | ||
|
|
||
| - (bool)testFlutterViewIsConfigured { | ||
| id engineMock = OCMClassMock([FlutterEngine class]); | ||
|
|
||
| id renderer_ = [[FlutterMetalRenderer alloc] initWithFlutterEngine:engineMock]; | ||
| OCMStub([engineMock renderer]).andReturn(renderer_); | ||
|
|
||
| FlutterViewController* viewController = [[FlutterViewController alloc] initWithEngine:engineMock | ||
| nibName:@"" | ||
| bundle:nil]; | ||
| [viewController loadView]; | ||
|
|
||
| @try { | ||
| // Make sure "renderer" was called during "loadView", which means "flutterView" is created | ||
| OCMVerify([engineMock renderer]); | ||
| } @catch (...) { | ||
| return false; | ||
| } | ||
|
Comment on lines
+264
to
+266
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (note for @cbracken not @dubik) I know this pattern was copied from the other tests in this file but why are these tests returning
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's an excellent question that'll involve some archaeology. We should leave this for now and I'll follow-up with a cleanup PR once I figure out what the history of this was. |
||
|
|
||
| return true; | ||
| } | ||
|
|
||
| - (bool)testFlagsChangedEventsArePropagatedIfNotHandled { | ||
| id engineMock = OCMClassMock([FlutterEngine class]); | ||
| id binaryMessengerMock = OCMProtocolMock(@protocol(FlutterBinaryMessenger)); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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.
Bypassing the initialization logic by using
.viewController =instead ofsetViewControllerseems very hacky. I'm surprised thatviewControlleris not readonly (I suggest we make it so).It feels to me that this PR complexes the relationship between
FVCandFlutterEngine, which can be seen from the threeinitializeKeyboardcalls throughout the file. It's hard to track how many ways are there we expect to useFVCand whether a line is executed by each, as well as how to add a new line to the initialization.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.
Commenting only about
That's just Objective-C, they are completely identical under the covers. The dot notation
.viewController =is a more idiomatic way to set a property.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.
It does. When the existing engine is passed, it can be running or not. So that increases the complexity of the initializer and the patch adds basically one
ifwhich loadsFlutterViewand initializes the keyboard if it's running. So to me the added complexity doesn't look excessive.There is
CommonInitand all initializers use it.initWithEnginehandles the case when the engine is running and I could extract that into the method, but I couldn't come up with a good name and it doesn't clarify anything in that context.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.
To me, the story with the keyboard is rather complicated. There are quite a few cases to handle, and I'm not sure controller is the best place for that. There is a
TODOcomment ininitializeKeyboardwhich I guess, could solve some of the problems. But fixing thatTODOgoes way beyond my capabilities/knowledge of the engine's internals.FVCis created (displayingFVCwill start the engine)FVCis createdFVCis created, and the engine is started by the user, and laterFVCis shown (not handled by this patch, butviewWillAppearperhaps should check if the keyboard was correctly configured before)One solution could be that the engine would fire an event when it's started, and
FVCwould subscribe to that. This can simplify keyboard initialization for cases 1. and 3.