From d0d2e88d001955ae06d50a2831401b8ccaeaf6e8 Mon Sep 17 00:00:00 2001 From: Louise Hsu Date: Wed, 9 Aug 2023 11:35:09 -0700 Subject: [PATCH 1/7] initial commit --- .../framework/Source/FlutterPlatformPlugin.mm | 13 +++++++- .../Source/FlutterPlatformPluginTest.mm | 32 +++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterPlatformPlugin.mm b/shell/platform/darwin/ios/framework/Source/FlutterPlatformPlugin.mm index 8a3688cb11ba6..728a5bada58d2 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterPlatformPlugin.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterPlatformPlugin.mm @@ -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 @@ -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 diff --git a/shell/platform/darwin/ios/framework/Source/FlutterPlatformPluginTest.mm b/shell/platform/darwin/ios/framework/Source/FlutterPlatformPluginTest.mm index 6ccbd8dd19a29..691ad2bd8a7c4 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterPlatformPluginTest.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterPlatformPluginTest.mm @@ -19,6 +19,7 @@ @interface FlutterPlatformPlugin () - (BOOL)isLiveTextInputAvailable; - (void)searchWeb:(NSString*)searchTerm; - (void)showLookUpViewController:(NSString*)term; +- (void)showShareViewController:(NSString*)content; @end @interface UIViewController () @@ -83,6 +84,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> _weakFactory = + std::make_unique>(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]; From 4d25f7146df3b9cd975316dc4cf12ba30909e591 Mon Sep 17 00:00:00 2001 From: Louise Hsu Date: Wed, 9 Aug 2023 11:37:05 -0700 Subject: [PATCH 2/7] formatting --- .../ios/framework/Source/FlutterPlatformPlugin.mm | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterPlatformPlugin.mm b/shell/platform/darwin/ios/framework/Source/FlutterPlatformPlugin.mm index 728a5bada58d2..3ac744381db25 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterPlatformPlugin.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterPlatformPlugin.mm @@ -133,11 +133,11 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result { - (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]; + NSArray* itemsToShare = @[ content ]; + UIActivityViewController* activityViewController = + [[[UIActivityViewController alloc] initWithActivityItems:itemsToShare + applicationActivities:nil] autorelease]; + [engineViewController presentViewController:activityViewController animated:YES completion:nil]; } - (void)searchWeb:(NSString*)searchTerm { From c0e19198003c32ea54df544434d4b67d5f9582d8 Mon Sep 17 00:00:00 2001 From: Louise Hsu Date: Wed, 9 Aug 2023 11:35:09 -0700 Subject: [PATCH 3/7] initial commit --- .../framework/Source/FlutterPlatformPlugin.mm | 13 +++++++- .../Source/FlutterPlatformPluginTest.mm | 32 +++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterPlatformPlugin.mm b/shell/platform/darwin/ios/framework/Source/FlutterPlatformPlugin.mm index 8a3688cb11ba6..728a5bada58d2 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterPlatformPlugin.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterPlatformPlugin.mm @@ -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 @@ -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 diff --git a/shell/platform/darwin/ios/framework/Source/FlutterPlatformPluginTest.mm b/shell/platform/darwin/ios/framework/Source/FlutterPlatformPluginTest.mm index 6ccbd8dd19a29..691ad2bd8a7c4 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterPlatformPluginTest.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterPlatformPluginTest.mm @@ -19,6 +19,7 @@ @interface FlutterPlatformPlugin () - (BOOL)isLiveTextInputAvailable; - (void)searchWeb:(NSString*)searchTerm; - (void)showLookUpViewController:(NSString*)term; +- (void)showShareViewController:(NSString*)content; @end @interface UIViewController () @@ -83,6 +84,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> _weakFactory = + std::make_unique>(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]; From a7d60097e4ee1758500f7820668d9987850b14ef Mon Sep 17 00:00:00 2001 From: Louise Hsu Date: Wed, 9 Aug 2023 11:37:05 -0700 Subject: [PATCH 4/7] formatting --- .../ios/framework/Source/FlutterPlatformPlugin.mm | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterPlatformPlugin.mm b/shell/platform/darwin/ios/framework/Source/FlutterPlatformPlugin.mm index 728a5bada58d2..3ac744381db25 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterPlatformPlugin.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterPlatformPlugin.mm @@ -133,11 +133,11 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result { - (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]; + NSArray* itemsToShare = @[ content ]; + UIActivityViewController* activityViewController = + [[[UIActivityViewController alloc] initWithActivityItems:itemsToShare + applicationActivities:nil] autorelease]; + [engineViewController presentViewController:activityViewController animated:YES completion:nil]; } - (void)searchWeb:(NSString*)searchTerm { From db08079ea7c3d0f65cda87545d56c59bf374102a Mon Sep 17 00:00:00 2001 From: Louise Hsu Date: Wed, 9 Aug 2023 11:35:09 -0700 Subject: [PATCH 5/7] initial commit --- .../framework/Source/FlutterPlatformPlugin.mm | 13 +++++++- .../Source/FlutterPlatformPluginTest.mm | 32 +++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterPlatformPlugin.mm b/shell/platform/darwin/ios/framework/Source/FlutterPlatformPlugin.mm index 8a3688cb11ba6..728a5bada58d2 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterPlatformPlugin.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterPlatformPlugin.mm @@ -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 @@ -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 diff --git a/shell/platform/darwin/ios/framework/Source/FlutterPlatformPluginTest.mm b/shell/platform/darwin/ios/framework/Source/FlutterPlatformPluginTest.mm index 6ccbd8dd19a29..691ad2bd8a7c4 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterPlatformPluginTest.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterPlatformPluginTest.mm @@ -19,6 +19,7 @@ @interface FlutterPlatformPlugin () - (BOOL)isLiveTextInputAvailable; - (void)searchWeb:(NSString*)searchTerm; - (void)showLookUpViewController:(NSString*)term; +- (void)showShareViewController:(NSString*)content; @end @interface UIViewController () @@ -83,6 +84,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> _weakFactory = + std::make_unique>(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]; From 1e2520f2526e312c671a3bc258d7a38d857c6d41 Mon Sep 17 00:00:00 2001 From: Louise Hsu Date: Wed, 9 Aug 2023 11:37:05 -0700 Subject: [PATCH 6/7] formatting --- .../ios/framework/Source/FlutterPlatformPlugin.mm | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterPlatformPlugin.mm b/shell/platform/darwin/ios/framework/Source/FlutterPlatformPlugin.mm index 728a5bada58d2..3ac744381db25 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterPlatformPlugin.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterPlatformPlugin.mm @@ -133,11 +133,11 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result { - (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]; + NSArray* itemsToShare = @[ content ]; + UIActivityViewController* activityViewController = + [[[UIActivityViewController alloc] initWithActivityItems:itemsToShare + applicationActivities:nil] autorelease]; + [engineViewController presentViewController:activityViewController animated:YES completion:nil]; } - (void)searchWeb:(NSString*)searchTerm { From 11fcfe9b9115df46333e553b7be003b9145e98f6 Mon Sep 17 00:00:00 2001 From: Louise Hsu Date: Wed, 16 Aug 2023 17:08:03 -0700 Subject: [PATCH 7/7] fix test --- .../darwin/ios/framework/Source/FlutterPlatformPluginTest.mm | 1 - 1 file changed, 1 deletion(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterPlatformPluginTest.mm b/shell/platform/darwin/ios/framework/Source/FlutterPlatformPluginTest.mm index 90c471446282b..3e19665973e96 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterPlatformPluginTest.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterPlatformPluginTest.mm @@ -143,7 +143,6 @@ - (void)testShareScreenInvoked { 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