From cabd4fcacd5e5ec722060b1269594047c38c04a2 Mon Sep 17 00:00:00 2001 From: hellohuanlin <41930132+hellohuanlin@users.noreply.github.com> Date: Mon, 22 Apr 2024 16:36:18 -0700 Subject: [PATCH] [ios_edit_menu]add native edit menu (flutter/engine#50095) Support native edit menu on the engine side. Design doc: https://docs.google.com/document/d/16-8kn58h_oD902e7vPSh6W20aHRBJKyNOdSe5rbAe_g/edit?resourcekey=0-gVdJ3fbOybV70ZKeHU7fkQ&tab=t.0 *List which issues are fixed by this PR. You must list at least one issue.* https://github.com/flutter/flutter/issues/103163 *If you had to change anything in the [flutter/tests] repo, include a link to the migration guide as per the [breaking change policy].* [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style --- .../flutter/lib/ui/platform_dispatcher.dart | 16 +++ engine/src/flutter/lib/ui/window.dart | 7 ++ .../lib/web_ui/lib/platform_dispatcher.dart | 2 + .../lib/web_ui/lib/src/engine/window.dart | 3 + engine/src/flutter/lib/web_ui/lib/window.dart | 2 + .../ios/framework/Source/FlutterEngine.mm | 6 + .../framework/Source/FlutterPlatformPlugin.mm | 25 ++++ .../Source/FlutterTextInputDelegate.h | 2 + .../framework/Source/FlutterTextInputPlugin.h | 7 +- .../Source/FlutterTextInputPlugin.mm | 57 ++++++++- .../Source/FlutterTextInputPluginTest.mm | 111 ++++++++++++++++++ .../framework/Source/FlutterViewController.mm | 11 +- .../Source/FlutterViewControllerTest.mm | 14 +++ .../Source/FlutterViewController_Internal.h | 2 + 14 files changed, 262 insertions(+), 3 deletions(-) diff --git a/engine/src/flutter/lib/ui/platform_dispatcher.dart b/engine/src/flutter/lib/ui/platform_dispatcher.dart index 63d7211dcc..4b07bdb711 100644 --- a/engine/src/flutter/lib/ui/platform_dispatcher.dart +++ b/engine/src/flutter/lib/ui/platform_dispatcher.dart @@ -1075,6 +1075,14 @@ class PlatformDispatcher { bool get nativeSpellCheckServiceDefined => _nativeSpellCheckServiceDefined; bool _nativeSpellCheckServiceDefined = false; + /// Whether showing system context menu is supported on the current platform. + /// + /// This option is used by [AdaptiveTextSelectionToolbar] to decide whether + /// to show system context menu, or to fallback to the default Flutter context + /// menu. + bool get supportsShowingSystemContextMenu => _supportsShowingSystemContextMenu; + bool _supportsShowingSystemContextMenu = false; + /// Whether briefly displaying the characters as you type in obscured text /// fields is enabled in system settings. /// @@ -1142,6 +1150,14 @@ class PlatformDispatcher { } else { _nativeSpellCheckServiceDefined = false; } + + final bool? supportsShowingSystemContextMenu = data['supportsShowingSystemContextMenu'] as bool?; + if (supportsShowingSystemContextMenu != null) { + _supportsShowingSystemContextMenu = supportsShowingSystemContextMenu; + } else { + _supportsShowingSystemContextMenu = false; + } + // This field is optional. final bool? brieflyShowPassword = data['brieflyShowPassword'] as bool?; if (brieflyShowPassword != null) { diff --git a/engine/src/flutter/lib/ui/window.dart b/engine/src/flutter/lib/ui/window.dart index c33a068125..6bb26674b6 100644 --- a/engine/src/flutter/lib/ui/window.dart +++ b/engine/src/flutter/lib/ui/window.dart @@ -561,6 +561,13 @@ class SingletonFlutterWindow extends FlutterView { /// service is specified. bool get nativeSpellCheckServiceDefined => platformDispatcher.nativeSpellCheckServiceDefined; + /// Whether the spell check service is supported on the current platform. + /// + /// This option is used by [EditableTextState] to define its + /// [SpellCheckConfiguration] when a default spell check service + /// is requested. + bool get supportsShowingSystemContextMenu => platformDispatcher.supportsShowingSystemContextMenu; + /// Whether briefly displaying the characters as you type in obscured text /// fields is enabled in system settings. /// diff --git a/engine/src/flutter/lib/web_ui/lib/platform_dispatcher.dart b/engine/src/flutter/lib/web_ui/lib/platform_dispatcher.dart index 9180ef6b22..d6995d7ee2 100644 --- a/engine/src/flutter/lib/web_ui/lib/platform_dispatcher.dart +++ b/engine/src/flutter/lib/web_ui/lib/platform_dispatcher.dart @@ -124,6 +124,8 @@ abstract class PlatformDispatcher { bool get nativeSpellCheckServiceDefined => false; + bool get supportsShowingSystemContextMenu => false; + bool get brieflyShowPassword => true; VoidCallback? get onTextScaleFactorChanged; diff --git a/engine/src/flutter/lib/web_ui/lib/src/engine/window.dart b/engine/src/flutter/lib/web_ui/lib/src/engine/window.dart index 59c6f37cc4..79d888e785 100644 --- a/engine/src/flutter/lib/web_ui/lib/src/engine/window.dart +++ b/engine/src/flutter/lib/web_ui/lib/src/engine/window.dart @@ -390,6 +390,9 @@ final class EngineFlutterWindow extends EngineFlutterView implements ui.Singleto @override bool get nativeSpellCheckServiceDefined => platformDispatcher.nativeSpellCheckServiceDefined; + @override + bool get supportsShowingSystemContextMenu => platformDispatcher.supportsShowingSystemContextMenu; + @override bool get brieflyShowPassword => platformDispatcher.brieflyShowPassword; diff --git a/engine/src/flutter/lib/web_ui/lib/window.dart b/engine/src/flutter/lib/web_ui/lib/window.dart index 1f4e10aac2..d42bbf7854 100644 --- a/engine/src/flutter/lib/web_ui/lib/window.dart +++ b/engine/src/flutter/lib/web_ui/lib/window.dart @@ -46,6 +46,8 @@ abstract class SingletonFlutterWindow extends FlutterView { bool get nativeSpellCheckServiceDefined; + bool get supportsShowingSystemContextMenu; + bool get brieflyShowPassword; bool get alwaysUse24HourFormat; 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 f0fa9c8be5..e2f355dca4 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 @@ -1080,6 +1080,12 @@ static void SetEntryPoint(flutter::Settings* settings, NSString* entrypoint, NSS arguments:@[ @(client), @(start), @(end) ]]; } +- (void)flutterTextInputView:(FlutterTextInputView*)textInputView + willDismissEditMenuWithTextInputClient:(int)client { + [_platformChannel.get() invokeMethod:@"ContextMenu.onDismissSystemContextMenu" + arguments:@[ @(client) ]]; +} + #pragma mark - FlutterViewEngineDelegate - (void)flutterTextInputView:(FlutterTextInputView*)textInputView showToolbar:(int)client { diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformPlugin.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformPlugin.mm index 281ab64092..2cbf76d15e 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformPlugin.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformPlugin.mm @@ -149,11 +149,36 @@ static void SetStatusBarStyleForSharedApplication(UIStatusBarStyle style) { } else if ([method isEqualToString:@"Share.invoke"]) { [self showShareViewController:args]; result(nil); + } else if ([method isEqualToString:@"ContextMenu.showSystemContextMenu"]) { + [self showSystemContextMenu:args]; + result(nil); + } else if ([method isEqualToString:@"ContextMenu.hideSystemContextMenu"]) { + [self hideSystemContextMenu]; + result(nil); } else { result(FlutterMethodNotImplemented); } } +- (void)showSystemContextMenu:(NSDictionary*)args { + if (@available(iOS 16.0, *)) { + FlutterTextInputPlugin* textInputPlugin = [_engine.get() textInputPlugin]; + BOOL shownEditMenu = [textInputPlugin showEditMenu:args]; + if (!shownEditMenu) { + FML_LOG(ERROR) << "Only text input supports system context menu for now. Ensure the system " + "context menu is shown with an active text input connection. See " + "https://github.com/flutter/flutter/issues/143033."; + } + } +} + +- (void)hideSystemContextMenu { + if (@available(iOS 16.0, *)) { + FlutterTextInputPlugin* textInputPlugin = [_engine.get() textInputPlugin]; + [textInputPlugin hideEditMenu]; + } +} + - (void)showShareViewController:(NSString*)content { UIViewController* engineViewController = [_engine.get() viewController]; 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 2b5c76f77a..0bf715a880 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 @@ -65,6 +65,8 @@ typedef NS_ENUM(NSInteger, FlutterFloatingCursorDragState) { - (void)flutterTextInputView:(FlutterTextInputView*)textInputView removeTextPlaceholder:(int)client; - (void)flutterTextInputView:(FlutterTextInputView*)textInputView didResignFirstResponderWithTextInputClient:(int)client; +- (void)flutterTextInputView:(FlutterTextInputView*)textInputView + willDismissEditMenuWithTextInputClient:(int)client; @end #endif // FLUTTER_SHELL_PLATFORM_DARWIN_IOS_FRAMEWORK_SOURCE_FLUTTERTEXTINPUTDELEGATE_H_ diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.h b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.h index dcf4f69010..3f30494457 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.h +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.h @@ -60,6 +60,8 @@ typedef NS_ENUM(NSInteger, FlutterScribbleInteractionStatus) { */ - (void)setUpIndirectScribbleInteraction:(id)viewResponder; - (void)resetViewResponder; +- (BOOL)showEditMenu:(NSDictionary*)args API_AVAILABLE(ios(16.0)); +- (void)hideEditMenu API_AVAILABLE(ios(16.0)); @end @@ -128,7 +130,8 @@ API_AVAILABLE(ios(13.0)) @interface FlutterTextPlaceholder : UITextPlaceholder #if FLUTTER_RUNTIME_MODE == FLUTTER_RUNTIME_MODE_DEBUG FLUTTER_DARWIN_EXPORT #endif -@interface FlutterTextInputView : UIView +@interface FlutterTextInputView + : UIView // UITextInput @property(nonatomic, readonly) NSMutableString* text; @@ -158,6 +161,8 @@ FLUTTER_DARWIN_EXPORT @property(nonatomic, weak) id viewResponder; @property(nonatomic) FlutterScribbleFocusStatus scribbleFocusStatus; @property(nonatomic, strong) NSArray* selectionRects; + +@property(nonatomic, strong) UIEditMenuInteraction* editMenuInteraction API_AVAILABLE(ios(16.0)); - (void)resetScribbleInteractionStatusIfEnding; - (BOOL)isScribbleAvailable; 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 ea36de564d..87be4ee9bf 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 @@ -794,6 +794,7 @@ static BOOL IsSelectionRectBoundaryCloserToPoint(CGPoint point, // This is cleared at the start of each keyboard interaction. (Enter a character, delete a character // etc) @property(nonatomic, copy) NSString* temporarilyDeletedComposedCharacter; +@property(nonatomic, assign) CGRect editMenuTargetRect; - (void)setEditableTransform:(NSArray*)matrix; @end @@ -859,9 +860,44 @@ static BOOL IsSelectionRectBoundaryCloserToPoint(CGPoint point, } } + if (@available(iOS 16.0, *)) { + _editMenuInteraction = [[UIEditMenuInteraction alloc] initWithDelegate:self]; + [self addInteraction:_editMenuInteraction]; + } + return self; } +- (UIMenu*)editMenuInteraction:(UIEditMenuInteraction*)interaction + menuForConfiguration:(UIEditMenuConfiguration*)configuration + suggestedActions:(NSArray*)suggestedActions API_AVAILABLE(ios(16.0)) { + return [UIMenu menuWithChildren:suggestedActions]; +} + +- (void)editMenuInteraction:(UIEditMenuInteraction*)interaction + willDismissMenuForConfiguration:(UIEditMenuConfiguration*)configuration + animator:(id)animator + API_AVAILABLE(ios(16.0)) { + [self.textInputDelegate flutterTextInputView:self + willDismissEditMenuWithTextInputClient:_textInputClient]; +} + +- (CGRect)editMenuInteraction:(UIEditMenuInteraction*)interaction + targetRectForConfiguration:(UIEditMenuConfiguration*)configuration API_AVAILABLE(ios(16.0)) { + return _editMenuTargetRect; +} + +- (void)showEditMenuWithTargetRect:(CGRect)targetRect API_AVAILABLE(ios(16.0)) { + _editMenuTargetRect = targetRect; + UIEditMenuConfiguration* config = + [UIEditMenuConfiguration configurationWithIdentifier:nil sourcePoint:CGPointZero]; + [self.editMenuInteraction presentEditMenuWithConfiguration:config]; +} + +- (void)hideEditMenu API_AVAILABLE(ios(16.0)) { + [self.editMenuInteraction dismissMenu]; +} + - (void)configureWithDictionary:(NSDictionary*)configuration { NSDictionary* inputType = configuration[kKeyboardType]; NSString* keyboardAppearance = configuration[kKeyboardAppearance]; @@ -1148,8 +1184,10 @@ static BOOL IsSelectionRectBoundaryCloserToPoint(CGPoint point, if (action == @selector(paste:)) { // Forbid pasting images, memojis, or other non-string content. return [UIPasteboard generalPasteboard].hasStrings; + } else if (action == @selector(copy:) || action == @selector(cut:) || + action == @selector(delete:)) { + return [self textInRange:_selectedTextRange].length > 0; } - return [super canPerformAction:action withSender:sender]; } @@ -2511,6 +2549,23 @@ static BOOL IsSelectionRectBoundaryCloserToPoint(CGPoint point, _keyboardViewContainer.frame = _keyboardRect; } +- (BOOL)showEditMenu:(NSDictionary*)args API_AVAILABLE(ios(16.0)) { + if (!self.activeView.isFirstResponder) { + return NO; + } + NSDictionary* encodedTargetRect = args[@"targetRect"]; + CGRect globalTargetRect = CGRectMake( + [encodedTargetRect[@"x"] doubleValue], [encodedTargetRect[@"y"] doubleValue], + [encodedTargetRect[@"width"] doubleValue], [encodedTargetRect[@"height"] doubleValue]); + CGRect localTargetRect = [self.hostView convertRect:globalTargetRect toView:self.activeView]; + [self.activeView showEditMenuWithTargetRect:localTargetRect]; + return YES; +} + +- (void)hideEditMenu { + [self.activeView hideEditMenu]; +} + - (void)setEditableSizeAndTransform:(NSDictionary*)dictionary { NSArray* transform = dictionary[@"transform"]; [_activeView setEditableTransform:transform]; 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 724def096d..46bffc9228 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 @@ -2847,6 +2847,117 @@ FLUTTER_ASSERT_ARC XCTAssertNil(activeView.superview, @"activeView must be removed from view hierarchy."); } +- (void)testEditMenu_shouldSetupEditMenuDelegateCorrectly { + if (@available(iOS 16.0, *)) { + FlutterTextInputView* inputView = [[FlutterTextInputView alloc] initWithOwner:textInputPlugin]; + [UIApplication.sharedApplication.keyWindow addSubview:inputView]; + XCTAssertEqual(inputView.editMenuInteraction.delegate, inputView, + @"editMenuInteraction setup delegate correctly"); + } +} + +- (void)testEditMenu_shouldNotPresentEditMenuIfNotFirstResponder { + if (@available(iOS 16.0, *)) { + FlutterTextInputPlugin* myInputPlugin = + [[FlutterTextInputPlugin alloc] initWithDelegate:OCMClassMock([FlutterEngine class])]; + BOOL shownEditMenu = [myInputPlugin showEditMenu:@{}]; + XCTAssertFalse(shownEditMenu, @"Should not show edit menu if not first responder."); + } +} + +- (void)testEditMenu_shouldPresentEditMenuWithCorrectConfiguration { + if (@available(iOS 16.0, *)) { + FlutterTextInputPlugin* myInputPlugin = + [[FlutterTextInputPlugin alloc] initWithDelegate:OCMClassMock([FlutterEngine class])]; + FlutterViewController* myViewController = [[FlutterViewController alloc] init]; + myInputPlugin.viewController = myViewController; + [myViewController loadView]; + FlutterMethodCall* setClientCall = + [FlutterMethodCall methodCallWithMethodName:@"TextInput.setClient" + arguments:@[ @(123), self.mutableTemplateCopy ]]; + [myInputPlugin handleMethodCall:setClientCall + result:^(id _Nullable result){ + }]; + + FlutterTextInputView* myInputView = myInputPlugin.activeView; + FlutterTextInputView* mockInputView = OCMPartialMock(myInputView); + + OCMStub([mockInputView isFirstResponder]).andReturn(YES); + + XCTestExpectation* expectation = [[XCTestExpectation alloc] + initWithDescription:@"presentEditMenuWithConfiguration must be called."]; + + id mockInteraction = OCMClassMock([UIEditMenuInteraction class]); + OCMStub([mockInputView editMenuInteraction]).andReturn(mockInteraction); + OCMStub([mockInteraction presentEditMenuWithConfiguration:[OCMArg any]]) + .andDo(^(NSInvocation* invocation) { + // arguments are released once invocation is released. + [invocation retainArguments]; + UIEditMenuConfiguration* config; + [invocation getArgument:&config atIndex:2]; + XCTAssertEqual(config.preferredArrowDirection, UIEditMenuArrowDirectionAutomatic, + @"UIEditMenuConfiguration must use automatic arrow direction."); + XCTAssert(CGPointEqualToPoint(config.sourcePoint, CGPointZero), + @"UIEditMenuConfiguration must have the correct point."); + [expectation fulfill]; + }); + + NSDictionary* encodedTargetRect = + @{@"x" : @(0), @"y" : @(0), @"width" : @(0), @"height" : @(0)}; + + BOOL shownEditMenu = [myInputPlugin showEditMenu:@{@"targetRect" : encodedTargetRect}]; + XCTAssertTrue(shownEditMenu, @"Should show edit menu with correct configuration."); + [self waitForExpectations:@[ expectation ] timeout:1.0]; + } +} + +- (void)testEditMenu_shouldPresentEditMenuWithCorectTargetRect { + if (@available(iOS 16.0, *)) { + FlutterTextInputPlugin* myInputPlugin = + [[FlutterTextInputPlugin alloc] initWithDelegate:OCMClassMock([FlutterEngine class])]; + FlutterViewController* myViewController = [[FlutterViewController alloc] init]; + myInputPlugin.viewController = myViewController; + [myViewController loadView]; + + FlutterMethodCall* setClientCall = + [FlutterMethodCall methodCallWithMethodName:@"TextInput.setClient" + arguments:@[ @(123), self.mutableTemplateCopy ]]; + [myInputPlugin handleMethodCall:setClientCall + result:^(id _Nullable result){ + }]; + + FlutterTextInputView* myInputView = myInputPlugin.activeView; + + FlutterTextInputView* mockInputView = OCMPartialMock(myInputView); + OCMStub([mockInputView isFirstResponder]).andReturn(YES); + + XCTestExpectation* expectation = [[XCTestExpectation alloc] + initWithDescription:@"presentEditMenuWithConfiguration must be called."]; + + id mockInteraction = OCMClassMock([UIEditMenuInteraction class]); + OCMStub([mockInputView editMenuInteraction]).andReturn(mockInteraction); + OCMStub([mockInteraction presentEditMenuWithConfiguration:[OCMArg any]]) + .andDo(^(NSInvocation* invocation) { + [expectation fulfill]; + }); + + myInputView.frame = CGRectMake(10, 20, 30, 40); + NSDictionary* encodedTargetRect = + @{@"x" : @(100), @"y" : @(200), @"width" : @(300), @"height" : @(400)}; + + BOOL shownEditMenu = [myInputPlugin showEditMenu:@{@"targetRect" : encodedTargetRect}]; + XCTAssertTrue(shownEditMenu, @"Should show edit menu with correct configuration."); + [self waitForExpectations:@[ expectation ] timeout:1.0]; + + CGRect targetRect = + [myInputView editMenuInteraction:mockInteraction + targetRectForConfiguration:OCMClassMock([UIEditMenuConfiguration class])]; + // the encoded target rect is in global coordinate space. + XCTAssert(CGRectEqualToRect(targetRect, CGRectMake(90, 180, 300, 400)), + @"targetRectForConfiguration must return the correct target rect."); + } +} + - (void)testInteractiveKeyboardAfterUserScrollWillResignFirstResponder { FlutterTextInputView* inputView = [[FlutterTextInputView alloc] initWithOwner:textInputPlugin]; [UIApplication.sharedApplication.keyWindow addSubview:inputView]; diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm index 4bf66d112e..b8911bed34 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm @@ -2134,7 +2134,8 @@ static flutter::PointerData::DeviceKind DeviceKindFromTouchType(UITouch* touch) @"alwaysUse24HourFormat" : @([self isAlwaysUse24HourFormat]), @"platformBrightness" : [self brightnessMode], @"platformContrast" : [self contrastMode], - @"nativeSpellCheckServiceDefined" : @true + @"nativeSpellCheckServiceDefined" : @true, + @"supportsShowingSystemContextMenu" : @([self supportsShowingSystemContextMenu]) }]; } @@ -2196,6 +2197,14 @@ static flutter::PointerData::DeviceKind DeviceKindFromTouchType(UITouch* touch) #endif } +- (BOOL)supportsShowingSystemContextMenu { + if (@available(iOS 16.0, *)) { + return YES; + } else { + return NO; + } +} + - (BOOL)isAlwaysUse24HourFormat { // iOS does not report its "24-Hour Time" user setting in the API. Instead, it applies // it automatically to NSDateFormatter when used with [NSLocale currentLocale]. It is diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterViewControllerTest.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterViewControllerTest.mm index c0c66796dc..99bb2efc2a 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterViewControllerTest.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterViewControllerTest.mm @@ -2204,4 +2204,18 @@ extern NSNotificationName const FlutterViewControllerWillDealloc; XCTAssertNil(viewController.keyboardAnimationVSyncClient); } +- (void)testSupportsShowingSystemContextMenuForIOS16AndAbove { + FlutterEngine* engine = [[FlutterEngine alloc] init]; + [engine runWithEntrypoint:nil]; + FlutterViewController* viewController = [[FlutterViewController alloc] initWithEngine:engine + nibName:nil + bundle:nil]; + BOOL supportsShowingSystemContextMenu = [viewController supportsShowingSystemContextMenu]; + if (@available(iOS 16.0, *)) { + XCTAssertTrue(supportsShowingSystemContextMenu); + } else { + XCTAssertFalse(supportsShowingSystemContextMenu); + } +} + @end diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterViewController_Internal.h b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterViewController_Internal.h index c1dc2f61cf..fea1a9d50f 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterViewController_Internal.h +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterViewController_Internal.h @@ -69,6 +69,8 @@ typedef void (^FlutterKeyboardAnimationCallback)(fml::TimePoint); - (void)deregisterNotifications; - (int32_t)accessibilityFlags; +- (BOOL)supportsShowingSystemContextMenu; + @end #endif // FLUTTER_SHELL_PLATFORM_DARWIN_IOS_FRAMEWORK_SOURCE_FLUTTERVIEWCONTROLLER_INTERNAL_H_