[ios] Fix hold and drag spacebar does not move cursor when obscureText is true. (flutter/engine#40216)
Fixes [flutter/flutter#122139](https://github.com/flutter/flutter/issues/122139) with flutter pr [flutter/flutter#122383](https://github.com/flutter/flutter/pull/122383)
This commit is contained in:
@@ -56,6 +56,7 @@ static NSString* const kFinishAutofillContextMethod = @"TextInput.finishAutofill
|
||||
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";
|
||||
@@ -2124,6 +2125,9 @@ static BOOL IsSelectionRectCloserToPoint(CGPoint point,
|
||||
} else if ([method isEqualToString:kStartLiveTextInputMethod]) {
|
||||
[self startLiveTextInput];
|
||||
result(nil);
|
||||
} else if ([method isEqualToString:kUpdateConfigMethod]) {
|
||||
[self updateConfig:args];
|
||||
result(nil);
|
||||
} else {
|
||||
result(FlutterMethodNotImplemented);
|
||||
}
|
||||
@@ -2463,6 +2467,23 @@ static BOOL IsSelectionRectCloserToPoint(CGPoint point,
|
||||
_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];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark UIIndirectScribbleInteractionDelegate
|
||||
|
||||
- (BOOL)indirectScribbleInteraction:(UIIndirectScribbleInteraction*)interaction
|
||||
|
||||
@@ -164,6 +164,14 @@ FLUTTER_ASSERT_ARC
|
||||
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 @@ FLUTTER_ASSERT_ARC
|
||||
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);
|
||||
}
|
||||
|
||||
#pragma mark - TextEditingDelta tests
|
||||
- (void)testTextEditingDeltasAreGeneratedOnTextInput {
|
||||
FlutterTextInputView* inputView = [[FlutterTextInputView alloc] initWithOwner:textInputPlugin];
|
||||
|
||||
Reference in New Issue
Block a user