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

Commit 11b553b

Browse files
[iOS text input] do not forward press events to the engine (#29464)
1 parent 5785bc4 commit 11b553b

File tree

4 files changed

+15
-89
lines changed

4 files changed

+15
-89
lines changed

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -720,13 +720,6 @@ - (void)notifyLowMemory {
720720

721721
#pragma mark - Text input delegate
722722

723-
- (void)handlePressEvent:(FlutterUIPressProxy*)press
724-
nextAction:(void (^)())next API_AVAILABLE(ios(13.4)) {
725-
if (_viewController.get() != nullptr) {
726-
[_viewController.get() handlePressEvent:press nextAction:next];
727-
}
728-
}
729-
730723
- (void)updateEditingClient:(int)client withState:(NSDictionary*)state {
731724
[_textInputChannel.get() invokeMethod:@"TextInputClient.updateEditingState"
732725
arguments:@[ @(client), state ]];

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#define SHELL_PLATFORM_IOS_FRAMEWORK_SOURCE_FLUTTERTEXTINPUTDELEGATE_H_
77

88
#import <Foundation/Foundation.h>
9-
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterUIPressProxy.h"
109

1110
typedef NS_ENUM(NSInteger, FlutterTextInputAction) {
1211
FlutterTextInputActionUnspecified,
@@ -29,8 +28,6 @@ typedef NS_ENUM(NSInteger, FlutterFloatingCursorDragState) {
2928
};
3029

3130
@protocol FlutterTextInputDelegate <NSObject>
32-
- (void)handlePressEvent:(FlutterUIPressProxy*)press
33-
nextAction:(void (^)())next API_AVAILABLE(ios(13.4));
3431
- (void)updateEditingClient:(int)client withState:(NSDictionary*)state;
3532
- (void)updateEditingClient:(int)client withState:(NSDictionary*)state withTag:(NSString*)tag;
3633
- (void)updateEditingClient:(int)client withDelta:(NSDictionary*)state;

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

Lines changed: 0 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -776,85 +776,6 @@ - (void)setTextInputState:(NSDictionary*)state {
776776
}
777777
}
778778

779-
// The documentation for presses* handlers (implemented below) is entirely
780-
// unclear about how to handle the case where some, but not all, of the presses
781-
// are handled here. I've elected to call super separately for each of the
782-
// presses that aren't handled, but it's not clear if this is correct. It may be
783-
// that iOS intends for us to either handle all or none of the presses, and pass
784-
// the original set to super. I have not yet seen multiple presses in the set in
785-
// the wild, however, so I suspect that the API is built for a tvOS remote or
786-
// something, and perhaps only one ever appears in the set on iOS from a
787-
// keyboard.
788-
789-
// If you substantially change these presses overrides, consider also changing
790-
// the similar ones in FlutterViewController. They need to be overridden in both
791-
// places to capture keys both inside and outside of a text field, but have
792-
// slightly different implmentations.
793-
794-
- (void)pressesBegan:(NSSet<UIPress*>*)presses
795-
withEvent:(UIPressesEvent*)event API_AVAILABLE(ios(9.0)) {
796-
if (@available(iOS 13.4, *)) {
797-
for (UIPress* press in presses) {
798-
[_textInputDelegate
799-
handlePressEvent:[[[FlutterUIPressProxy alloc] initWithPress:press
800-
withEvent:event] autorelease]
801-
nextAction:^() {
802-
[super pressesBegan:[NSSet setWithObject:press] withEvent:event];
803-
}];
804-
}
805-
} else {
806-
[super pressesBegan:presses withEvent:event];
807-
}
808-
}
809-
810-
- (void)pressesChanged:(NSSet<UIPress*>*)presses
811-
withEvent:(UIPressesEvent*)event API_AVAILABLE(ios(9.0)) {
812-
if (@available(iOS 13.4, *)) {
813-
for (UIPress* press in presses) {
814-
[_textInputDelegate
815-
handlePressEvent:[[[FlutterUIPressProxy alloc] initWithPress:press
816-
withEvent:event] autorelease]
817-
nextAction:^() {
818-
[super pressesChanged:[NSSet setWithObject:press] withEvent:event];
819-
}];
820-
}
821-
} else {
822-
[super pressesChanged:presses withEvent:event];
823-
}
824-
}
825-
826-
- (void)pressesEnded:(NSSet<UIPress*>*)presses
827-
withEvent:(UIPressesEvent*)event API_AVAILABLE(ios(9.0)) {
828-
if (@available(iOS 13.4, *)) {
829-
for (UIPress* press in presses) {
830-
[_textInputDelegate
831-
handlePressEvent:[[[FlutterUIPressProxy alloc] initWithPress:press
832-
withEvent:event] autorelease]
833-
nextAction:^() {
834-
[super pressesEnded:[NSSet setWithObject:press] withEvent:event];
835-
}];
836-
}
837-
} else {
838-
[super pressesEnded:presses withEvent:event];
839-
}
840-
}
841-
842-
- (void)pressesCancelled:(NSSet<UIPress*>*)presses
843-
withEvent:(UIPressesEvent*)event API_AVAILABLE(ios(9.0)) {
844-
if (@available(iOS 13.4, *)) {
845-
for (UIPress* press in presses) {
846-
[_textInputDelegate
847-
handlePressEvent:[[[FlutterUIPressProxy alloc] initWithPress:press
848-
withEvent:event] autorelease]
849-
nextAction:^() {
850-
[super pressesCancelled:[NSSet setWithObject:press] withEvent:event];
851-
}];
852-
}
853-
} else {
854-
[super pressesCancelled:presses withEvent:event];
855-
}
856-
}
857-
858779
// Extracts the selection information from the editing state dictionary.
859780
//
860781
// The state may contain an invalid selection, such as when no selection was

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,21 @@ - (void)ensureOnlyActiveViewCanBecomeFirstResponder {
357357
}
358358
}
359359

360+
- (void)testPropagatePressEventsToNextResponder {
361+
NSDictionary* config = self.mutableTemplateCopy;
362+
[self setClientId:123 configuration:config];
363+
364+
FlutterTextInputView* currentView = textInputPlugin.activeView;
365+
UIView* mockCurrentView = OCMPartialMock(currentView);
366+
367+
[mockCurrentView pressesBegan:[NSSet setWithObjects:OCMClassMock([UIPress class]), nil]
368+
withEvent:OCMClassMock([UIPressesEvent class])];
369+
370+
// The event should be propagated to the next responder instead
371+
// of the engine.
372+
OCMVerify([mockCurrentView nextResponder]);
373+
}
374+
360375
#pragma mark - TextEditingDelta tests
361376
- (void)testTextEditingDeltasAreGeneratedOnTextInput {
362377
FlutterTextInputView* inputView = [[FlutterTextInputView alloc] init];

0 commit comments

Comments
 (0)