From f6e2c34275ec0aa09e8500a6e27b37296e676f9e Mon Sep 17 00:00:00 2001 From: LongCatIsLooong <31859944+LongCatIsLooong@users.noreply.github.com> Date: Tue, 2 Nov 2021 10:58:01 -0700 Subject: [PATCH] [iOS text input] do not forward press events to the engine (flutter/engine#29464) --- .../ios/framework/Source/FlutterEngine.mm | 7 -- .../Source/FlutterTextInputDelegate.h | 3 - .../Source/FlutterTextInputPlugin.mm | 79 ------------------- .../Source/FlutterTextInputPluginTest.mm | 15 ++++ 4 files changed, 15 insertions(+), 89 deletions(-) diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm index de4f4c20ec..8f5da97990 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm @@ -720,13 +720,6 @@ static void SetEntryPoint(flutter::Settings* settings, NSString* entrypoint, NSS #pragma mark - Text input delegate -- (void)handlePressEvent:(FlutterUIPressProxy*)press - nextAction:(void (^)())next API_AVAILABLE(ios(13.4)) { - if (_viewController.get() != nullptr) { - [_viewController.get() handlePressEvent:press nextAction:next]; - } -} - - (void)updateEditingClient:(int)client withState:(NSDictionary*)state { [_textInputChannel.get() invokeMethod:@"TextInputClient.updateEditingState" arguments:@[ @(client), state ]]; diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputDelegate.h b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputDelegate.h index b6f2ac5ca9..c2bce5f65f 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputDelegate.h +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputDelegate.h @@ -6,7 +6,6 @@ #define SHELL_PLATFORM_IOS_FRAMEWORK_SOURCE_FLUTTERTEXTINPUTDELEGATE_H_ #import -#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterUIPressProxy.h" typedef NS_ENUM(NSInteger, FlutterTextInputAction) { FlutterTextInputActionUnspecified, @@ -29,8 +28,6 @@ typedef NS_ENUM(NSInteger, FlutterFloatingCursorDragState) { }; @protocol FlutterTextInputDelegate -- (void)handlePressEvent:(FlutterUIPressProxy*)press - nextAction:(void (^)())next API_AVAILABLE(ios(13.4)); - (void)updateEditingClient:(int)client withState:(NSDictionary*)state; - (void)updateEditingClient:(int)client withState:(NSDictionary*)state withTag:(NSString*)tag; - (void)updateEditingClient:(int)client withDelta:(NSDictionary*)state; diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm index f218350960..a65743026f 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm @@ -776,85 +776,6 @@ static FlutterAutofillType autofillTypeOf(NSDictionary* configuration) { } } -// The documentation for presses* handlers (implemented below) is entirely -// unclear about how to handle the case where some, but not all, of the presses -// are handled here. I've elected to call super separately for each of the -// presses that aren't handled, but it's not clear if this is correct. It may be -// that iOS intends for us to either handle all or none of the presses, and pass -// the original set to super. I have not yet seen multiple presses in the set in -// the wild, however, so I suspect that the API is built for a tvOS remote or -// something, and perhaps only one ever appears in the set on iOS from a -// keyboard. - -// If you substantially change these presses overrides, consider also changing -// the similar ones in FlutterViewController. They need to be overridden in both -// places to capture keys both inside and outside of a text field, but have -// slightly different implmentations. - -- (void)pressesBegan:(NSSet*)presses - withEvent:(UIPressesEvent*)event API_AVAILABLE(ios(9.0)) { - if (@available(iOS 13.4, *)) { - for (UIPress* press in presses) { - [_textInputDelegate - handlePressEvent:[[[FlutterUIPressProxy alloc] initWithPress:press - withEvent:event] autorelease] - nextAction:^() { - [super pressesBegan:[NSSet setWithObject:press] withEvent:event]; - }]; - } - } else { - [super pressesBegan:presses withEvent:event]; - } -} - -- (void)pressesChanged:(NSSet*)presses - withEvent:(UIPressesEvent*)event API_AVAILABLE(ios(9.0)) { - if (@available(iOS 13.4, *)) { - for (UIPress* press in presses) { - [_textInputDelegate - handlePressEvent:[[[FlutterUIPressProxy alloc] initWithPress:press - withEvent:event] autorelease] - nextAction:^() { - [super pressesChanged:[NSSet setWithObject:press] withEvent:event]; - }]; - } - } else { - [super pressesChanged:presses withEvent:event]; - } -} - -- (void)pressesEnded:(NSSet*)presses - withEvent:(UIPressesEvent*)event API_AVAILABLE(ios(9.0)) { - if (@available(iOS 13.4, *)) { - for (UIPress* press in presses) { - [_textInputDelegate - handlePressEvent:[[[FlutterUIPressProxy alloc] initWithPress:press - withEvent:event] autorelease] - nextAction:^() { - [super pressesEnded:[NSSet setWithObject:press] withEvent:event]; - }]; - } - } else { - [super pressesEnded:presses withEvent:event]; - } -} - -- (void)pressesCancelled:(NSSet*)presses - withEvent:(UIPressesEvent*)event API_AVAILABLE(ios(9.0)) { - if (@available(iOS 13.4, *)) { - for (UIPress* press in presses) { - [_textInputDelegate - handlePressEvent:[[[FlutterUIPressProxy alloc] initWithPress:press - withEvent:event] autorelease] - nextAction:^() { - [super pressesCancelled:[NSSet setWithObject:press] withEvent:event]; - }]; - } - } else { - [super pressesCancelled:presses withEvent:event]; - } -} - // Extracts the selection information from the editing state dictionary. // // The state may contain an invalid selection, such as when no selection was diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPluginTest.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPluginTest.mm index bf223cdae6..3f71c6ca6b 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPluginTest.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPluginTest.mm @@ -357,6 +357,21 @@ FLUTTER_ASSERT_ARC } } +- (void)testPropagatePressEventsToNextResponder { + NSDictionary* config = self.mutableTemplateCopy; + [self setClientId:123 configuration:config]; + + FlutterTextInputView* currentView = textInputPlugin.activeView; + UIView* mockCurrentView = OCMPartialMock(currentView); + + [mockCurrentView pressesBegan:[NSSet setWithObjects:OCMClassMock([UIPress class]), nil] + withEvent:OCMClassMock([UIPressesEvent class])]; + + // The event should be propagated to the next responder instead + // of the engine. + OCMVerify([mockCurrentView nextResponder]); +} + #pragma mark - TextEditingDelta tests - (void)testTextEditingDeltasAreGeneratedOnTextInput { FlutterTextInputView* inputView = [[FlutterTextInputView alloc] init];