Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reland [iOS] Send connectionClosed message when resignFirstResponder to ensure framework focus state is correct. #41022

Merged
merged 1 commit into from
Apr 10, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion shell/platform/darwin/ios/framework/Source/FlutterEngine.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1095,7 +1095,14 @@ - (void)flutterTextInputView:(FlutterTextInputView*)textInputView
arguments:@[ @(client) ]];
}

- (void)flutterTextInputViewDidResignFirstResponder:(FlutterTextInputView*)textInputView {
- (void)flutterTextInputView:(FlutterTextInputView*)textInputView
didResignFirstResponderWithTextInputClient:(int)client {
// When flutter text input view resign first responder, send a message to
// framework to ensure the focus state is correct. This is useful when close
// keyboard from platform side.
[_textInputChannel.get() invokeMethod:@"TextInputClient.onConnectionClosed"
arguments:@[ @(client) ]];

// Platform view's first responder detection logic:
//
// All text input widgets (e.g. EditableText) are backed by a dummy UITextInput view
Expand Down
18 changes: 18 additions & 0 deletions shell/platform/darwin/ios/framework/Source/FlutterEngineTest.mm
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,14 @@
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterBinaryMessengerRelay.h"
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterDartProject_Internal.h"
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterEngine_Test.h"
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.h"

FLUTTER_ASSERT_ARC

@interface FlutterEngine () <FlutterTextInputDelegate>

@end

@interface FlutterEngineTest : XCTestCase
@end

Expand Down Expand Up @@ -313,4 +318,17 @@ - (void)testCanEnableDisableEmbedderAPIThroughInfoPlist {
}
}

- (void)testFlutterTextInputViewDidResignFirstResponderWillCallTextInputClientConnectionClosed {
id mockBinaryMessenger = OCMClassMock([FlutterBinaryMessengerRelay class]);
FlutterEngine* engine = [[FlutterEngine alloc] init];
[engine setBinaryMessenger:mockBinaryMessenger];
[engine runWithEntrypoint:FlutterDefaultDartEntrypoint initialRoute:@"test"];
[engine flutterTextInputView:nil didResignFirstResponderWithTextInputClient:1];
FlutterMethodCall* methodCall =
[FlutterMethodCall methodCallWithMethodName:@"TextInputClient.onConnectionClosed"
arguments:@[ @(1) ]];
NSData* encodedMethodCall = [[FlutterJSONMethodCodec sharedInstance] encodeMethodCall:methodCall];
OCMVerify([mockBinaryMessenger sendOnChannel:@"flutter/textinput" message:encodedMethodCall]);
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ typedef NS_ENUM(NSInteger, FlutterFloatingCursorDragState) {
insertTextPlaceholderWithSize:(CGSize)size
withClient:(int)client;
- (void)flutterTextInputView:(FlutterTextInputView*)textInputView removeTextPlaceholder:(int)client;
- (void)flutterTextInputViewDidResignFirstResponder:(FlutterTextInputView*)textInputView;

- (void)flutterTextInputView:(FlutterTextInputView*)textInputView
didResignFirstResponderWithTextInputClient:(int)client;
@end

#endif // SHELL_PLATFORM_IOS_FRAMEWORK_SOURCE_FLUTTERTEXTINPUTDELEGATE_H_
Original file line number Diff line number Diff line change
Expand Up @@ -1043,7 +1043,8 @@ - (BOOL)canBecomeFirstResponder {
- (BOOL)resignFirstResponder {
BOOL success = [super resignFirstResponder];
if (success) {
[self.textInputDelegate flutterTextInputViewDidResignFirstResponder:self];
[self.textInputDelegate flutterTextInputView:self
didResignFirstResponderWithTextInputClient:_textInputClient];
}
return success;
}
Expand Down