Add share to selection controls (flutter/engine#44554)
In native iOS, users are able to select text and initiate a share menu, which provides several standard services, such as copy, sharing to social media, direct ability to send to various contacts through messaging apps, etc. https://github.com/flutter/engine/assets/36148254/d0af7034-31fd-412e-8636-a06bbff54765 This PR is the engine portion of the changes that will allow Share to be implemented This PR addresses https://github.com/flutter/flutter/issues/107578 More details are available in this [design doc](https://github.com/flutter/engine/pull/flutter.dev/go/add-missing-features-to-selection-controls)
This commit is contained in:
@@ -123,11 +123,23 @@ using namespace flutter;
|
||||
} 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
|
||||
@@ -338,7 +350,6 @@ using namespace flutter;
|
||||
|
||||
- (void)showLookUpViewController:(NSString*)term {
|
||||
UIViewController* engineViewController = [_engine.get() viewController];
|
||||
FML_DCHECK(![engineViewController presentingViewController]);
|
||||
UIReferenceLibraryViewController* referenceLibraryViewController =
|
||||
[[[UIReferenceLibraryViewController alloc] initWithTerm:term] autorelease];
|
||||
[engineViewController presentViewController:referenceLibraryViewController
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
- (BOOL)isLiveTextInputAvailable;
|
||||
- (void)searchWeb:(NSString*)searchTerm;
|
||||
- (void)showLookUpViewController:(NSString*)term;
|
||||
- (void)showShareViewController:(NSString*)content;
|
||||
@end
|
||||
|
||||
@interface UIViewController ()
|
||||
@@ -122,6 +123,36 @@
|
||||
[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([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];
|
||||
|
||||
Reference in New Issue
Block a user