Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 894506e

Browse files
committed
[use dyanmic offscreen position based on UIScreen
1 parent 32f4780 commit 894506e

File tree

2 files changed

+23
-28
lines changed

2 files changed

+23
-28
lines changed

shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,6 @@
3434
// returns kInvalidFirstRect, iOS will not show the IME candidates view.
3535
const CGRect kInvalidFirstRect = {{-1, -1}, {9999, 9999}};
3636

37-
// Position FlutterTextInputView outside of the screen (if scribble is disabled).
38-
// This is to fix a bug where native auto-correction highlight is displayed on
39-
// top left corner of the screen (See: https://github.com/flutter/flutter/issues/131695)
40-
// and a bug where the native auto-correction suggestion menu displayed (See:
41-
// https://github.com/flutter/flutter/issues/130818).
42-
const CGRect kNonScribbleInputHiderOffScreenRect = {{0, -2000}, {0, 0}};
43-
4437
#pragma mark - TextInput channel method names.
4538
// See https://api.flutter.dev/flutter/services/SystemChannels/textInput-constant.html
4639
static NSString* const kShowMethod = @"TextInput.show";
@@ -2259,7 +2252,6 @@ - (instancetype)initWithDelegate:(id<FlutterTextInputDelegate>)textInputDelegate
22592252
_textInputDelegate = textInputDelegate;
22602253
_autofillContext = [[NSMutableDictionary alloc] init];
22612254
_inputHider = [[FlutterTextInputViewAccessibilityHider alloc] init];
2262-
_inputHider.frame = kNonScribbleInputHiderOffScreenRect;
22632255
_scribbleElements = [[NSMutableDictionary alloc] init];
22642256
_keyboardViewContainer = [[UIView alloc] init];
22652257

@@ -2470,7 +2462,15 @@ - (void)setEditableSizeAndTransform:(NSDictionary*)dictionary {
24702462
CGRectMake(0, 0, [dictionary[@"width"] intValue], [dictionary[@"height"] intValue]);
24712463
_activeView.tintColor = [UIColor clearColor];
24722464
} else {
2473-
_inputHider.frame = kNonScribbleInputHiderOffScreenRect;
2465+
// Screen must be loaded at this point.
2466+
UIScreen* screen = _viewController.flutterScreenIfViewLoaded;
2467+
2468+
// Position FlutterTextInputView outside of the screen (if scribble is disabled).
2469+
// This is to fix a bug where native auto-correction highlight is displayed on
2470+
// top left corner of the screen (See: https://github.com/flutter/flutter/issues/131695)
2471+
// and a bug where the native auto-correction suggestion menu displayed (See:
2472+
// https://github.com/flutter/flutter/issues/130818).
2473+
_inputHider.frame = CGRectMake(0, -screen.bounds.size.height, 0, 0);
24742474
}
24752475
}
24762476

shell/platform/darwin/ios/framework/Source/FlutterTextInputPluginTest.mm

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2305,26 +2305,22 @@ - (void)testInitialActiveViewCantAccessTextInputDelegate {
23052305
XCTAssertNil(textInputPlugin.activeView.textInputDelegate);
23062306
}
23072307

2308-
- (void)testInputHiderIsInitiallyOffScreen {
2309-
FlutterTextInputPlugin* myInputPlugin =
2310-
[[FlutterTextInputPlugin alloc] initWithDelegate:OCMClassMock([FlutterEngine class])];
2311-
2312-
FlutterMethodCall* setClientCall =
2313-
[FlutterMethodCall methodCallWithMethodName:@"TextInput.setClient"
2314-
arguments:@[ @(123), self.mutableTemplateCopy ]];
2315-
[myInputPlugin handleMethodCall:setClientCall
2316-
result:^(id _Nullable result){
2317-
}];
2318-
2319-
CGRect offScreenRect = {{0, -2000}, {0, 0}};
2320-
2321-
XCTAssert(CGRectEqualToRect(myInputPlugin.inputHider.frame, offScreenRect),
2322-
@"The initial input hider should be offScreen.");
2323-
}
2324-
23252308
- (void)testInputHiderIsOffScreenWhenScribbleIsDisabled {
23262309
FlutterTextInputPlugin* myInputPlugin =
23272310
[[FlutterTextInputPlugin alloc] initWithDelegate:OCMClassMock([FlutterEngine class])];
2311+
myInputPlugin.viewController = viewController;
2312+
2313+
NSSet<UIScene*>* scenes = UIApplication.sharedApplication.connectedScenes;
2314+
XCTAssertEqual(scenes.count, 1UL, @"There must only be 1 scene for test");
2315+
UIScene* scene = scenes.anyObject;
2316+
XCTAssert([scene isKindOfClass:[UIWindowScene class]], @"Must be a window scene for test");
2317+
UIWindowScene* windowScene = (UIWindowScene*)scene;
2318+
XCTAssert(windowScene.windows.count > 0, @"There must be at least 1 window for test");
2319+
UIWindow* window = windowScene.windows[0];
2320+
[window addSubview:viewController.view];
2321+
[viewController loadView];
2322+
UIScreen* screen = viewController.flutterScreenIfViewLoaded;
2323+
XCTAssertNotNil(screen, @"Screen must be present at this point");
23282324

23292325
FlutterMethodCall* setClientCall =
23302326
[FlutterMethodCall methodCallWithMethodName:@"TextInput.setClient"
@@ -2333,8 +2329,6 @@ - (void)testInputHiderIsOffScreenWhenScribbleIsDisabled {
23332329
result:^(id _Nullable result){
23342330
}];
23352331

2336-
CGRect offScreenRect = {{0, -2000}, {0, 0}};
2337-
23382332
FlutterTextInputView* mockInputView = OCMPartialMock(myInputPlugin.activeView);
23392333
OCMStub([mockInputView isScribbleAvailable]).andReturn(NO);
23402334

@@ -2348,6 +2342,7 @@ - (void)testInputHiderIsOffScreenWhenScribbleIsDisabled {
23482342
result:^(id _Nullable result){
23492343
}];
23502344

2345+
CGRect offScreenRect = CGRectMake(0, -screen.bounds.size.height, 0, 0);
23512346
XCTAssert(CGRectEqualToRect(myInputPlugin.inputHider.frame, offScreenRect),
23522347
@"The input hider should stay offScreen if scribble is disabled.");
23532348
}

0 commit comments

Comments
 (0)