Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit f19b011

Browse files
committed
initial commit
1 parent 7b6be5c commit f19b011

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

shell/platform/darwin/ios/framework/Source/FlutterPlatformPlugin.mm

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,23 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
123123
} else if ([method isEqualToString:@"LookUp.invoke"]) {
124124
[self showLookUpViewController:args];
125125
result(nil);
126+
} else if ([method isEqualToString:@"Share.invoke"]) {
127+
[self showShareViewController:args];
128+
result(nil);
126129
} else {
127130
result(FlutterMethodNotImplemented);
128131
}
129132
}
130133

134+
- (void)showShareViewController:(NSString*)content {
135+
UIViewController* engineViewController = [_engine.get() viewController];
136+
NSArray *itemsToShare = @[content];
137+
UIActivityViewController *activityViewController = [[[UIActivityViewController alloc] initWithActivityItems:itemsToShare applicationActivities:nil] autorelease];
138+
[engineViewController presentViewController:activityViewController
139+
animated:YES
140+
completion:nil];
141+
}
142+
131143
- (void)searchWeb:(NSString*)searchTerm {
132144
NSString* escapedText = [searchTerm
133145
stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet
@@ -338,7 +350,6 @@ - (BOOL)isLiveTextInputAvailable {
338350

339351
- (void)showLookUpViewController:(NSString*)term {
340352
UIViewController* engineViewController = [_engine.get() viewController];
341-
FML_DCHECK(![engineViewController presentingViewController]);
342353
UIReferenceLibraryViewController* referenceLibraryViewController =
343354
[[[UIReferenceLibraryViewController alloc] initWithTerm:term] autorelease];
344355
[engineViewController presentViewController:referenceLibraryViewController

shell/platform/darwin/ios/framework/Source/FlutterPlatformPluginTest.mm

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ @interface FlutterPlatformPlugin ()
1919
- (BOOL)isLiveTextInputAvailable;
2020
- (void)searchWeb:(NSString*)searchTerm;
2121
- (void)showLookUpViewController:(NSString*)term;
22+
- (void)showShareViewController:(NSString*)content;
2223
@end
2324

2425
@interface UIViewController ()
@@ -83,6 +84,37 @@ - (void)testLookUpCallInitiated {
8384
[self waitForExpectationsWithTimeout:2 handler:nil];
8485
}
8586

87+
- (void)testShareScreenInvoked {
88+
FlutterEngine* engine = [[[FlutterEngine alloc] initWithName:@"test" project:nil] autorelease];
89+
[engine runWithEntrypoint:nil];
90+
std::unique_ptr<fml::WeakPtrFactory<FlutterEngine>> _weakFactory =
91+
std::make_unique<fml::WeakPtrFactory<FlutterEngine>>(engine);
92+
93+
XCTestExpectation* presentExpectation =
94+
[self expectationWithDescription:@"Share view controller presented"];
95+
96+
FlutterViewController* engineViewController =
97+
[[[FlutterViewController alloc] initWithEngine:engine nibName:nil bundle:nil] autorelease];
98+
FlutterViewController* mockEngineViewController = OCMPartialMock(engineViewController);
99+
100+
FlutterPlatformPlugin* plugin =
101+
[[[FlutterPlatformPlugin alloc] initWithEngine:_weakFactory->GetWeakPtr()] autorelease];
102+
FlutterPlatformPlugin* mockPlugin = OCMPartialMock(plugin);
103+
104+
FlutterMethodCall* methodCall = [FlutterMethodCall methodCallWithMethodName:@"Share.invoke"
105+
arguments:@"Test"];
106+
FlutterResult result = ^(id result) {
107+
OCMVerify([mockPlugin showShareViewController:@"Test"]);
108+
OCMVerify([mockEngineViewController
109+
presentViewController:[OCMArg isKindOfClass:[UIActivityViewController class]]
110+
animated:YES
111+
completion:nil]);
112+
[presentExpectation fulfill];
113+
};
114+
[mockPlugin handleMethodCall:methodCall result:result];
115+
[self waitForExpectationsWithTimeout:1 handler:nil];
116+
}
117+
86118
- (void)testClipboardHasCorrectStrings {
87119
[UIPasteboard generalPasteboard].string = nil;
88120
FlutterEngine* engine = [[[FlutterEngine alloc] initWithName:@"test" project:nil] autorelease];

0 commit comments

Comments
 (0)