Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add share to selection controls #44554

Merged
merged 13 commits into from
Aug 17, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,23 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
} else if ([method isEqualToString:@"LookUp.invoke"]) {
[self showLookUpViewController:args];
result(nil);
} else if ([method isEqualToString:@"Share.invoke"]) {
[self showShareViewController:args];
result(nil);
} else {
result(FlutterMethodNotImplemented);
}
}

- (void)showShareViewController:(NSString*)content {
UIViewController* engineViewController = [_engine.get() viewController];
NSArray* itemsToShare = @[ content ];
UIActivityViewController* activityViewController =
[[[UIActivityViewController alloc] initWithActivityItems:itemsToShare
applicationActivities:nil] autorelease];
[engineViewController presentViewController:activityViewController animated:YES completion:nil];
}

- (void)searchWeb:(NSString*)searchTerm {
NSString* escapedText = [searchTerm
stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet
Expand Down Expand Up @@ -338,7 +350,6 @@ - (BOOL)isLiveTextInputAvailable {

- (void)showLookUpViewController:(NSString*)term {
UIViewController* engineViewController = [_engine.get() viewController];
FML_DCHECK(![engineViewController presentingViewController]);
UIReferenceLibraryViewController* referenceLibraryViewController =
[[[UIReferenceLibraryViewController alloc] initWithTerm:term] autorelease];
[engineViewController presentViewController:referenceLibraryViewController
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ @interface FlutterPlatformPlugin ()
- (BOOL)isLiveTextInputAvailable;
- (void)searchWeb:(NSString*)searchTerm;
- (void)showLookUpViewController:(NSString*)term;
- (void)showShareViewController:(NSString*)content;
@end

@interface UIViewController ()
Expand Down Expand Up @@ -122,6 +123,37 @@ - (void)testLookUpCallInitiated {
[self waitForExpectationsWithTimeout:2 handler:nil];
}

- (void)testShareScreenInvoked {
FlutterEngine* engine = [[[FlutterEngine alloc] initWithName:@"test" project:nil] autorelease];
[engine runWithEntrypoint:nil];
std::unique_ptr<fml::WeakPtrFactory<FlutterEngine>> _weakFactory =
std::make_unique<fml::WeakPtrFactory<FlutterEngine>>(engine);

XCTestExpectation* presentExpectation =
[self expectationWithDescription:@"Share view controller presented"];

FlutterViewController* engineViewController =
[[[FlutterViewController alloc] initWithEngine:engine nibName:nil bundle:nil] autorelease];
FlutterViewController* mockEngineViewController = OCMPartialMock(engineViewController);

FlutterPlatformPlugin* plugin =
[[[FlutterPlatformPlugin alloc] initWithEngine:_weakFactory->GetWeakPtr()] autorelease];
FlutterPlatformPlugin* mockPlugin = OCMPartialMock(plugin);

FlutterMethodCall* methodCall = [FlutterMethodCall methodCallWithMethodName:@"Share.invoke"
arguments:@"Test"];
FlutterResult result = ^(id result) {
OCMVerify([mockPlugin showShareViewController:@"Test"]);
OCMVerify([mockEngineViewController
presentViewController:[OCMArg isKindOfClass:[UIActivityViewController class]]
animated:YES
completion:nil]);
[presentExpectation 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