From d1b71ddeeb45b83a866871e15808a198b752d4e5 Mon Sep 17 00:00:00 2001 From: Matej Knopp Date: Fri, 20 Jan 2023 14:49:30 +0100 Subject: [PATCH 1/2] [macos] Move TextInputPlugin outside of visible area --- .../darwin/macos/framework/Source/FlutterTextInputPlugin.mm | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/shell/platform/darwin/macos/framework/Source/FlutterTextInputPlugin.mm b/shell/platform/darwin/macos/framework/Source/FlutterTextInputPlugin.mm index d6687772bc7f5..5c471108229a8 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterTextInputPlugin.mm +++ b/shell/platform/darwin/macos/framework/Source/FlutterTextInputPlugin.mm @@ -245,8 +245,9 @@ @implementation FlutterTextInputPlugin { } - (instancetype)initWithViewController:(FlutterViewController*)viewController { - // The view needs a non-zero frame. - self = [super initWithFrame:NSMakeRect(0, 0, 1, 1)]; + // The view needs a non-zero frame and must be placed outside of visible area. + // https://github.com/flutter/flutter/issues/118504 + self = [super initWithFrame:NSMakeRect(-100, -100, 1, 1)]; if (self != nil) { _flutterViewController = viewController; _channel = [FlutterMethodChannel methodChannelWithName:kTextInputChannel From 942cfbc4a08829413849938ac24a3bb3fc63bb00 Mon Sep 17 00:00:00 2001 From: Matej Knopp Date: Mon, 23 Jan 2023 13:01:00 +0100 Subject: [PATCH 2/2] Make plugin empty and add test --- .../framework/Source/FlutterTextInputPlugin.mm | 4 ++-- .../Source/FlutterTextInputPluginTest.mm | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/shell/platform/darwin/macos/framework/Source/FlutterTextInputPlugin.mm b/shell/platform/darwin/macos/framework/Source/FlutterTextInputPlugin.mm index 5c471108229a8..2c314b92ada11 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterTextInputPlugin.mm +++ b/shell/platform/darwin/macos/framework/Source/FlutterTextInputPlugin.mm @@ -245,9 +245,9 @@ @implementation FlutterTextInputPlugin { } - (instancetype)initWithViewController:(FlutterViewController*)viewController { - // The view needs a non-zero frame and must be placed outside of visible area. + // The view needs an empty frame otherwise it is visible on dark background. // https://github.com/flutter/flutter/issues/118504 - self = [super initWithFrame:NSMakeRect(-100, -100, 1, 1)]; + self = [super initWithFrame:NSZeroRect]; if (self != nil) { _flutterViewController = viewController; _channel = [FlutterMethodChannel methodChannelWithName:kTextInputChannel diff --git a/shell/platform/darwin/macos/framework/Source/FlutterTextInputPluginTest.mm b/shell/platform/darwin/macos/framework/Source/FlutterTextInputPluginTest.mm index 9f4a39d4b3818..3d0caab367756 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterTextInputPluginTest.mm +++ b/shell/platform/darwin/macos/framework/Source/FlutterTextInputPluginTest.mm @@ -1554,4 +1554,20 @@ - (bool)testSelectorsAreForwardedToFramework { ASSERT_FALSE(window.firstResponder == viewController.textInputPlugin); } +TEST(FlutterTextInputPluginTest, HasZeroSize) { + id engineMock = OCMClassMock([FlutterEngine class]); + id binaryMessengerMock = OCMProtocolMock(@protocol(FlutterBinaryMessenger)); + OCMStub( // NOLINT(google-objc-avoid-throwing-exception) + [engineMock binaryMessenger]) + .andReturn(binaryMessengerMock); + FlutterViewController* viewController = [[FlutterViewController alloc] initWithEngine:engineMock + nibName:@"" + bundle:nil]; + + FlutterTextInputPlugin* plugin = + [[FlutterTextInputPlugin alloc] initWithViewController:viewController]; + + ASSERT_TRUE(NSIsEmptyRect(plugin.frame)); +} + } // namespace flutter::testing