Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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.initiate"]) {
[self showLookUpView:args];
result(nil);
} else {
result(FlutterMethodNotImplemented);
}
Expand Down Expand Up @@ -307,6 +310,13 @@ - (BOOL)isLiveTextInputAvailable {
return [[self textField] canPerformAction:@selector(captureTextFromCamera:) withSender:nil];
}

- (void)showLookUpView:(NSString*)term {
UIViewController* engineViewController = [_engine.get() viewController];
UIReferenceLibraryViewController* refVC =
[[UIReferenceLibraryViewController alloc] initWithTerm:term];
[engineViewController presentViewController:refVC animated:YES completion:nil];
}

- (UITextField*)textField {
if (_textField == nil) {
_textField = [[UITextField alloc] init];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,29 @@ @interface FlutterPlatformPluginTest : XCTestCase

@interface FlutterPlatformPlugin ()
- (BOOL)isLiveTextInputAvailable;
- (void)showLookUpView:(NSString*)term;
@end

@implementation FlutterPlatformPluginTest

- (void)testLookUpCallInitiated {
FlutterEngine* engine = [[[FlutterEngine alloc] initWithName:@"test" project:nil] autorelease];
std::unique_ptr<fml::WeakPtrFactory<FlutterEngine>> _weakFactory =
std::make_unique<fml::WeakPtrFactory<FlutterEngine>>(engine);
XCTestExpectation* invokeExpectation = [self expectationWithDescription:@"isLookUpInvoked"];
FlutterPlatformPlugin* plugin =
[[[FlutterPlatformPlugin alloc] initWithEngine:_weakFactory->GetWeakPtr()] autorelease];
FlutterPlatformPlugin* mockPlugin = OCMPartialMock(plugin);
FlutterMethodCall* methodCall = [FlutterMethodCall methodCallWithMethodName:@"LookUp.initiate"
arguments:@"Test"];
FlutterResult result = ^(id result) {
OCMVerify([mockPlugin showLookUpView:@"Test"]);
[invokeExpectation fulfill];
};
[mockPlugin handleMethodCall:methodCall result:result];
[self waitForExpectationsWithTimeout:1 handler:nil];
}

- (void)testClipboardHasCorrectStrings {
[UIPasteboard generalPasteboard].string = nil;
FlutterEngine* engine = [[[FlutterEngine alloc] initWithName:@"test" project:nil] autorelease];
Expand Down