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

Commit 0e23698

Browse files
authored
[ios] Fix hold and drag spacebar does not move cursor when obscureText is true. (#40216)
Fixes [flutter/flutter#122139](flutter/flutter#122139) with flutter pr [flutter/flutter#122383](flutter/flutter#122383)
1 parent 36730dd commit 0e23698

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
static NSString* const kDeprecatedSetSelectionRectsMethod = @"TextInput.setSelectionRects";
5757
static NSString* const kSetSelectionRectsMethod = @"Scribble.setSelectionRects";
5858
static NSString* const kStartLiveTextInputMethod = @"TextInput.startLiveTextInput";
59+
static NSString* const kUpdateConfigMethod = @"TextInput.updateConfig";
5960

6061
#pragma mark - TextInputConfiguration Field Names
6162
static NSString* const kSecureTextEntry = @"obscureText";
@@ -2124,6 +2125,9 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
21242125
} else if ([method isEqualToString:kStartLiveTextInputMethod]) {
21252126
[self startLiveTextInput];
21262127
result(nil);
2128+
} else if ([method isEqualToString:kUpdateConfigMethod]) {
2129+
[self updateConfig:args];
2130+
result(nil);
21272131
} else {
21282132
result(FlutterMethodNotImplemented);
21292133
}
@@ -2463,6 +2467,23 @@ - (void)clearTextInputClient {
24632467
_activeView.frame = CGRectZero;
24642468
}
24652469

2470+
- (void)updateConfig:(NSDictionary*)dictionary {
2471+
BOOL isSecureTextEntry = [dictionary[kSecureTextEntry] boolValue];
2472+
for (UIView* view in self.textInputViews) {
2473+
if ([view isKindOfClass:[FlutterTextInputView class]]) {
2474+
FlutterTextInputView* inputView = (FlutterTextInputView*)view;
2475+
// The feature of holding and draging spacebar to move cursor is affected by
2476+
// secureTextEntry, so when obscureText is updated, we need to update secureTextEntry
2477+
// and call reloadInputViews.
2478+
// https://github.com/flutter/flutter/issues/122139
2479+
if (inputView.isSecureTextEntry != isSecureTextEntry) {
2480+
inputView.secureTextEntry = isSecureTextEntry;
2481+
[inputView reloadInputViews];
2482+
}
2483+
}
2484+
}
2485+
}
2486+
24662487
#pragma mark UIIndirectScribbleInteractionDelegate
24672488

24682489
- (BOOL)indirectScribbleInteraction:(UIIndirectScribbleInteraction*)interaction

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,14 @@ - (FlutterTextRange*)getLineRangeFromTokenizer:(id<UITextInputTokenizer>)tokeniz
164164
return (FlutterTextRange*)range;
165165
}
166166

167+
- (void)updateConfig:(NSDictionary*)config {
168+
FlutterMethodCall* updateConfigCall =
169+
[FlutterMethodCall methodCallWithMethodName:@"TextInput.updateConfig" arguments:config];
170+
[textInputPlugin handleMethodCall:updateConfigCall
171+
result:^(id _Nullable result){
172+
}];
173+
}
174+
167175
#pragma mark - Tests
168176

169177
- (void)testWillNotCrashWhenViewControllerIsNil {
@@ -647,6 +655,29 @@ - (void)testPropagatePressEventsToViewController2 {
647655
withEvent:[OCMArg isNotNil]]);
648656
}
649657

658+
- (void)testUpdateSecureTextEntry {
659+
NSDictionary* config = self.mutableTemplateCopy;
660+
[config setValue:@"YES" forKey:@"obscureText"];
661+
[self setClientId:123 configuration:config];
662+
663+
NSArray<FlutterTextInputView*>* inputFields = self.installedInputViews;
664+
FlutterTextInputView* inputView = OCMPartialMock(inputFields[0]);
665+
666+
__block int callCount = 0;
667+
OCMStub([inputView reloadInputViews]).andDo(^(NSInvocation* invocation) {
668+
callCount++;
669+
});
670+
671+
XCTAssertTrue(inputView.isSecureTextEntry);
672+
673+
config = self.mutableTemplateCopy;
674+
[config setValue:@"NO" forKey:@"obscureText"];
675+
[self updateConfig:config];
676+
677+
XCTAssertEqual(callCount, 1);
678+
XCTAssertFalse(inputView.isSecureTextEntry);
679+
}
680+
650681
#pragma mark - TextEditingDelta tests
651682
- (void)testTextEditingDeltasAreGeneratedOnTextInput {
652683
FlutterTextInputView* inputView = [[FlutterTextInputView alloc] initWithOwner:textInputPlugin];

0 commit comments

Comments
 (0)