[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:
林洵锋
2023-04-26 01:56:56 +08:00
committed by GitHub
parent 63e04a3814
commit 2c3afe9b15
2 changed files with 52 additions and 0 deletions

View File

@@ -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

View File

@@ -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];