Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit d02da0e

Browse files
authored
Revert "Revert "[iOS] Send connectionClosed message when resignFirstResponder to ensure framework focus state is correct. (#40703)" (#40777)"
This reverts commit 75fabbe.
1 parent 58ab7ea commit d02da0e

File tree

4 files changed

+30
-4
lines changed

4 files changed

+30
-4
lines changed

shell/platform/darwin/ios/framework/Source/FlutterEngine.mm

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1095,7 +1095,14 @@ - (void)flutterTextInputView:(FlutterTextInputView*)textInputView
10951095
arguments:@[ @(client) ]];
10961096
}
10971097

1098-
- (void)flutterTextInputViewDidResignFirstResponder:(FlutterTextInputView*)textInputView {
1098+
- (void)flutterTextInputView:(FlutterTextInputView*)textInputView
1099+
didResignFirstResponderWithTextInputClient:(int)client {
1100+
// When flutter text input view resign first responder, send a message to
1101+
// framework to ensure the focus state is correct. This is useful when close
1102+
// keyboard from platform side.
1103+
[_textInputChannel.get() invokeMethod:@"TextInputClient.onConnectionClosed"
1104+
arguments:@[ @(client) ]];
1105+
10991106
// Platform view's first responder detection logic:
11001107
//
11011108
// All text input widgets (e.g. EditableText) are backed by a dummy UITextInput view

shell/platform/darwin/ios/framework/Source/FlutterEngineTest.mm

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,14 @@
1313
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterBinaryMessengerRelay.h"
1414
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterDartProject_Internal.h"
1515
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterEngine_Test.h"
16+
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.h"
1617

1718
FLUTTER_ASSERT_ARC
1819

20+
@interface FlutterEngine () <FlutterTextInputDelegate>
21+
22+
@end
23+
1924
@interface FlutterEngineTest : XCTestCase
2025
@end
2126

@@ -313,4 +318,17 @@ - (void)testCanEnableDisableEmbedderAPIThroughInfoPlist {
313318
}
314319
}
315320

321+
- (void)testFlutterTextInputViewDidResignFirstResponderWillCallTextInputClientConnectionClosed {
322+
id mockBinaryMessenger = OCMClassMock([FlutterBinaryMessengerRelay class]);
323+
FlutterEngine* engine = [[FlutterEngine alloc] init];
324+
[engine setBinaryMessenger:mockBinaryMessenger];
325+
[engine runWithEntrypoint:FlutterDefaultDartEntrypoint initialRoute:@"test"];
326+
[engine flutterTextInputView:nil didResignFirstResponderWithTextInputClient:1];
327+
FlutterMethodCall* methodCall =
328+
[FlutterMethodCall methodCallWithMethodName:@"TextInputClient.onConnectionClosed"
329+
arguments:@[ @(1) ]];
330+
NSData* encodedMethodCall = [[FlutterJSONMethodCodec sharedInstance] encodeMethodCall:methodCall];
331+
OCMVerify([mockBinaryMessenger sendOnChannel:@"flutter/textinput" message:encodedMethodCall]);
332+
}
333+
316334
@end

shell/platform/darwin/ios/framework/Source/FlutterTextInputDelegate.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ typedef NS_ENUM(NSInteger, FlutterFloatingCursorDragState) {
5959
insertTextPlaceholderWithSize:(CGSize)size
6060
withClient:(int)client;
6161
- (void)flutterTextInputView:(FlutterTextInputView*)textInputView removeTextPlaceholder:(int)client;
62-
- (void)flutterTextInputViewDidResignFirstResponder:(FlutterTextInputView*)textInputView;
63-
62+
- (void)flutterTextInputView:(FlutterTextInputView*)textInputView
63+
didResignFirstResponderWithTextInputClient:(int)client;
6464
@end
6565

6666
#endif // SHELL_PLATFORM_IOS_FRAMEWORK_SOURCE_FLUTTERTEXTINPUTDELEGATE_H_

shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1043,7 +1043,8 @@ - (BOOL)canBecomeFirstResponder {
10431043
- (BOOL)resignFirstResponder {
10441044
BOOL success = [super resignFirstResponder];
10451045
if (success) {
1046-
[self.textInputDelegate flutterTextInputViewDidResignFirstResponder:self];
1046+
[self.textInputDelegate flutterTextInputView:self
1047+
didResignFirstResponderWithTextInputClient:_textInputClient];
10471048
}
10481049
return success;
10491050
}

0 commit comments

Comments
 (0)