-
Notifications
You must be signed in to change notification settings - Fork 6k
[ios] Fix hold and drag spacebar does not move cursor when obscureText is true. #40216
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 |
|---|---|---|
|
|
@@ -56,6 +56,7 @@ | |
| static NSString* const kDeprecatedSetSelectionRectsMethod = @"TextInput.setSelectionRects"; | ||
| static NSString* const kSetSelectionRectsMethod = @"Scribble.setSelectionRects"; | ||
| static NSString* const kStartLiveTextInputMethod = @"TextInput.startLiveTextInput"; | ||
| static NSString* const kUpdateConfigMethod = @"TextInput.updateConfig"; | ||
|
|
||
| #pragma mark - TextInputConfiguration Field Names | ||
| static NSString* const kSecureTextEntry = @"obscureText"; | ||
|
|
@@ -2123,6 +2124,9 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result { | |
| } else if ([method isEqualToString:kStartLiveTextInputMethod]) { | ||
| [self startLiveTextInput]; | ||
| result(nil); | ||
| } else if ([method isEqualToString:kUpdateConfigMethod]) { | ||
| [self updateConfig:args]; | ||
| result(nil); | ||
| } else { | ||
| result(FlutterMethodNotImplemented); | ||
| } | ||
|
|
@@ -2462,6 +2466,23 @@ - (void)clearTextInputClient { | |
| _activeView.frame = CGRectZero; | ||
| } | ||
|
|
||
| - (void)updateConfig:(NSDictionary*)dictionary { | ||
| BOOL isSecureTextEntry = [dictionary[kSecureTextEntry] boolValue]; | ||
| for (UIView* view in self.textInputViews) { | ||
| if ([view isKindOfClass:[FlutterTextInputView class]]) { | ||
| FlutterTextInputView* inputView = (FlutterTextInputView*)view; | ||
| // The feature of holding and draging spacebar to move cursor is affected by | ||
| // secureTextEntry, so when obscureText is updated, we need to update secureTextEntry | ||
| // and call reloadInputViews. | ||
| // https://github.com/flutter/flutter/issues/122139 | ||
| if (inputView.isSecureTextEntry != isSecureTextEntry) { | ||
| inputView.secureTextEntry = isSecureTextEntry; | ||
| [inputView reloadInputViews]; | ||
|
Contributor
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. The document of "The views are replaced immediately" sounds like the some view inside the
Member
Author
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. I didn't find any relevant side effect descriptions, and there was no problem after testing, so I think that the In addition, I did a test in a native project, calling the reloadInputViews1.mov |
||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #pragma mark UIIndirectScribbleInteractionDelegate | ||
|
|
||
| - (BOOL)indirectScribbleInteraction:(UIIndirectScribbleInteraction*)interaction | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -164,6 +164,14 @@ - (FlutterTextRange*)getLineRangeFromTokenizer:(id<UITextInputTokenizer>)tokeniz | |
| return (FlutterTextRange*)range; | ||
| } | ||
|
|
||
| - (void)updateConfig:(NSDictionary*)config { | ||
| FlutterMethodCall* updateConfigCall = | ||
| [FlutterMethodCall methodCallWithMethodName:@"TextInput.updateConfig" arguments:config]; | ||
| [textInputPlugin handleMethodCall:updateConfigCall | ||
| result:^(id _Nullable result){ | ||
| }]; | ||
| } | ||
|
|
||
| #pragma mark - Tests | ||
|
|
||
| - (void)testWillNotCrashWhenViewControllerIsNil { | ||
|
|
@@ -647,6 +655,29 @@ - (void)testPropagatePressEventsToViewController2 { | |
| withEvent:[OCMArg isNotNil]]); | ||
| } | ||
|
|
||
| - (void)testUpdateSecureTextEntry { | ||
| NSDictionary* config = self.mutableTemplateCopy; | ||
| [config setValue:@"YES" forKey:@"obscureText"]; | ||
| [self setClientId:123 configuration:config]; | ||
|
|
||
| NSArray<FlutterTextInputView*>* inputFields = self.installedInputViews; | ||
| FlutterTextInputView* inputView = OCMPartialMock(inputFields[0]); | ||
|
|
||
| __block int callCount = 0; | ||
| OCMStub([inputView reloadInputViews]).andDo(^(NSInvocation* invocation) { | ||
| callCount++; | ||
| }); | ||
|
|
||
| XCTAssertTrue(inputView.isSecureTextEntry); | ||
|
|
||
| config = self.mutableTemplateCopy; | ||
| [config setValue:@"NO" forKey:@"obscureText"]; | ||
| [self updateConfig:config]; | ||
|
|
||
| XCTAssertEqual(callCount, 1); | ||
| XCTAssertFalse(inputView.isSecureTextEntry); | ||
|
Contributor
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. Can we also test if
Member
Author
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. done |
||
| } | ||
|
|
||
| #pragma mark - TextEditingDelta tests | ||
| - (void)testTextEditingDeltasAreGeneratedOnTextInput { | ||
| FlutterTextInputView* inputView = [[FlutterTextInputView alloc] initWithOwner:textInputPlugin]; | ||
|
|
||
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.
not sure if i follow this. can you explain more why setting secrueTextEntry and the reload fixes the space bar cursor interaction? Or is it an undocumented behavior by apple here?
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.
First of all, it is clear that when
secureTextEntryis true, the space bar cursor interaction is not allowed, otherwise it is allowed. This is the correct interaction behavior on iOS native, so we need to updatesecureTextEntryin time when switchingobscureText. I did not find a description of whether this space bar cursor interaction is affected bysecureTextEntryin Apple's official documentation, this is just the conclusion obtained after testing.Then, when the value of the
secureTextEntryis changed, the interaction and style of the keyboard are still before thesecureTextEntryis changed, so here I call thereloadInputViewsmethod to refresh keyboard.