From 7c8036349d834ac75d9c82775bdf1ca4024b739f Mon Sep 17 00:00:00 2001 From: Matej Knopp Date: Thu, 9 Feb 2023 22:08:48 +0100 Subject: [PATCH] Reland "[macos] Move TextInputPlugin outside of visible area" (flutter/engine#39194) --- .../framework/Source/FlutterTextInputPlugin.mm | 5 +++-- .../Source/FlutterTextInputPluginTest.mm | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterTextInputPlugin.mm b/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterTextInputPlugin.mm index c5bdca27ce..09b7f7a7c2 100644 --- a/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterTextInputPlugin.mm +++ b/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterTextInputPlugin.mm @@ -303,8 +303,9 @@ static char markerKey; } - (instancetype)initWithViewController:(FlutterViewController*)viewController { - // The view needs a non-zero frame. - self = [super initWithFrame:NSMakeRect(0, 0, 1, 1)]; + // The view needs an empty frame otherwise it is visible on dark background. + // https://github.com/flutter/flutter/issues/118504 + self = [super initWithFrame:NSZeroRect]; if (self != nil) { _flutterViewController = viewController; _channel = [FlutterMethodChannel methodChannelWithName:kTextInputChannel diff --git a/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterTextInputPluginTest.mm b/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterTextInputPluginTest.mm index 1efc461b08..3bf1bef645 100644 --- a/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterTextInputPluginTest.mm +++ b/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterTextInputPluginTest.mm @@ -1778,4 +1778,21 @@ TEST(FlutterTextInputPluginTest, IsAddedAndRemovedFromViewHierarchy) { ASSERT_FALSE(window.firstResponder == viewController.textInputPlugin); } +TEST(FlutterTextInputPluginTest, HasZeroSize) { + id engineMock = flutter::testing::CreateMockFlutterEngine(@""); + 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