diff --git a/shell/platform/darwin/ios/framework/Source/FlutterPlatformPlugin.mm b/shell/platform/darwin/ios/framework/Source/FlutterPlatformPlugin.mm index 6d79dcee5179b..1785923100c89 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterPlatformPlugin.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterPlatformPlugin.mm @@ -115,6 +115,9 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result { result([self clipboardHasStrings]); } else if ([method isEqualToString:@"LiveText.isLiveTextInputAvailable"]) { result(@([self isLiveTextInputAvailable])); + } else if ([method isEqualToString:@"LookUp.invoke"]) { + [self showLookUpViewController:args]; + result(nil); } else { result(FlutterMethodNotImplemented); } @@ -307,6 +310,16 @@ - (BOOL)isLiveTextInputAvailable { return [[self textField] canPerformAction:@selector(captureTextFromCamera:) withSender:nil]; } +- (void)showLookUpViewController:(NSString*)term { + UIViewController* engineViewController = [_engine.get() viewController]; + FML_DCHECK(![engineViewController presentingViewController]); + UIReferenceLibraryViewController* referenceLibraryViewController = + [[[UIReferenceLibraryViewController alloc] initWithTerm:term] autorelease]; + [engineViewController presentViewController:referenceLibraryViewController + animated:YES + completion:nil]; +} + - (UITextField*)textField { if (_textField == nil) { _textField = [[UITextField alloc] init]; diff --git a/shell/platform/darwin/ios/framework/Source/FlutterPlatformPluginTest.mm b/shell/platform/darwin/ios/framework/Source/FlutterPlatformPluginTest.mm index b07261352abaf..2c0279902745e 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterPlatformPluginTest.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterPlatformPluginTest.mm @@ -17,10 +17,48 @@ @interface FlutterPlatformPluginTest : XCTestCase @interface FlutterPlatformPlugin () - (BOOL)isLiveTextInputAvailable; +- (void)showLookUpViewController:(NSString*)term; +@end + +@interface UIViewController () +- (void)presentViewController:(UIViewController*)viewControllerToPresent + animated:(BOOL)flag + completion:(void (^)(void))completion; @end @implementation FlutterPlatformPluginTest +- (void)testLookUpCallInitiated { + FlutterEngine* engine = [[[FlutterEngine alloc] initWithName:@"test" project:nil] autorelease]; + [engine runWithEntrypoint:nil]; + std::unique_ptr> _weakFactory = + std::make_unique>(engine); + + XCTestExpectation* presentExpectation = + [self expectationWithDescription:@"Look Up view controller presented"]; + + FlutterViewController* engineViewController = [[FlutterViewController alloc] initWithEngine:engine + nibName:nil + bundle:nil]; + FlutterViewController* mockEngineViewController = OCMPartialMock(engineViewController); + + FlutterPlatformPlugin* plugin = + [[[FlutterPlatformPlugin alloc] initWithEngine:_weakFactory->GetWeakPtr()] autorelease]; + FlutterPlatformPlugin* mockPlugin = OCMPartialMock(plugin); + + FlutterMethodCall* methodCall = [FlutterMethodCall methodCallWithMethodName:@"LookUp.invoke" + arguments:@"Test"]; + FlutterResult result = ^(id result) { + OCMVerify([mockEngineViewController + presentViewController:[OCMArg isKindOfClass:[UIReferenceLibraryViewController class]] + animated:YES + completion:nil]); + [presentExpectation fulfill]; + }; + [mockPlugin handleMethodCall:methodCall result:result]; + [self waitForExpectationsWithTimeout:2 handler:nil]; +} + - (void)testClipboardHasCorrectStrings { [UIPasteboard generalPasteboard].string = nil; FlutterEngine* engine = [[[FlutterEngine alloc] initWithName:@"test" project:nil] autorelease];