Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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
Comment on lines +2474 to +2477
Copy link
Contributor

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?

Copy link
Member Author

@LinXunFeng LinXunFeng Apr 13, 2023

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 secureTextEntry is 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 update secureTextEntry in time when switching obscureText. I did not find a description of whether this space bar cursor interaction is affected by secureTextEntry in Apple's official documentation, this is just the conclusion obtained after testing.

Then, when the value of the secureTextEntry is changed, the interaction and style of the keyboard are still before the secureTextEntry is changed, so here I call the reloadInputViews method to refresh keyboard.

if (inputView.isSecureTextEntry != isSecureTextEntry) {
inputView.secureTextEntry = isSecureTextEntry;
[inputView reloadInputViews];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The document of reloadInputViews this method says:
You can use this method to refresh the custom input view or input accessory view associated with the current object when it’s the first responder. The views are replaced immediately, without animating them into place. If the current object isn’t the first responder, this method has no effect.
(https://developer.apple.com/documentation/uikit/uiresponder/1621110-reloadinputviews?language=objc)

"The views are replaced immediately" sounds like the some view inside the inputView is replaced? What are other side effects of replacing the view? Do we not need to restore any state of the view?

Copy link
Member Author

@LinXunFeng LinXunFeng Mar 25, 2023

Choose a reason for hiding this comment

The 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 reloadInputViews method simply refreshes the keyboard view and does not cause other side effects. And when switching secureTextEntry to true, the keyboard will not have input accessory view, so there is no need to save the state.

In addition, I did a test in a native project, calling the reloadInputViews method directly will not affect the state in input accessory view and caps lock state.

reloadInputViews1.mov

}
}
}
}

#pragma mark UIIndirectScribbleInteractionDelegate

- (BOOL)indirectScribbleInteraction:(UIIndirectScribbleInteraction*)interaction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we also test if [inputView reloadInputViews]; is called?

Copy link
Member Author

Choose a reason for hiding this comment

The 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];
Expand Down