From b82a8c291c44aa56d5b2f9cbb05daf67a377a4c1 Mon Sep 17 00:00:00 2001 From: Sarah Zakarias Date: Thu, 11 May 2017 12:31:59 +0200 Subject: [PATCH 1/3] Update share plugin to new plugin registration. --- packages/share/CHANGELOG.md | 4 ++ .../io/flutter/plugins/share/SharePlugin.java | 20 +++++----- .../plugins/share_example/MainActivity.java | 7 ++-- .../ios/Runner.xcodeproj/project.pbxproj | 14 +++---- .../share/example/ios/Runner/AppDelegate.m | 35 ++--------------- .../ios/Runner/GeneratedPluginRegistrant.h | 16 ++++++++ .../ios/Runner/GeneratedPluginRegistrant.m | 13 +++++++ packages/share/ios/Classes/SharePlugin.h | 6 +-- packages/share/ios/Classes/SharePlugin.m | 38 +++++++++---------- packages/share/pubspec.yaml | 2 +- 10 files changed, 77 insertions(+), 78 deletions(-) create mode 100644 packages/share/example/ios/Runner/GeneratedPluginRegistrant.h create mode 100644 packages/share/example/ios/Runner/GeneratedPluginRegistrant.m diff --git a/packages/share/CHANGELOG.md b/packages/share/CHANGELOG.md index 0cd6335d7cc6..6386661b2883 100644 --- a/packages/share/CHANGELOG.md +++ b/packages/share/CHANGELOG.md @@ -1,3 +1,7 @@ +## [0.2.0] - 2017-05-11 + +* Upgrade to new plugin registration. (https://groups.google.com/forum/#!topic/flutter-dev/zba1Ynf2OKM) + ## [0.1.0] - 2017-05-05 * Initial Open Source release. \ No newline at end of file diff --git a/packages/share/android/src/main/java/io/flutter/plugins/share/SharePlugin.java b/packages/share/android/src/main/java/io/flutter/plugins/share/SharePlugin.java index b8aeee532e6b..c296e39f6e93 100644 --- a/packages/share/android/src/main/java/io/flutter/plugins/share/SharePlugin.java +++ b/packages/share/android/src/main/java/io/flutter/plugins/share/SharePlugin.java @@ -4,30 +4,28 @@ package io.flutter.plugins.share; +import android.app.Activity; import android.content.Context; import android.content.Intent; -import io.flutter.app.FlutterActivity; import io.flutter.plugin.common.MethodChannel; -import io.flutter.plugin.common.MethodChannel.MethodCallHandler; -import io.flutter.plugin.common.MethodChannel.Result; import io.flutter.plugin.common.MethodCall; +import io.flutter.plugin.common.PluginRegistry.Registrar; /** Plugin method host for presenting a share sheet via Intent */ public class SharePlugin implements MethodChannel.MethodCallHandler { private static final String PLATFORM_CHANNEL = "plugins.flutter.io/share"; + private final Context context; - public static SharePlugin register(FlutterActivity flutterActivity) { - return new SharePlugin(flutterActivity); + public static void registerWith(Registrar registrar) { + MethodChannel channel = new MethodChannel(registrar.messenger(), PLATFORM_CHANNEL); + SharePlugin instance = new SharePlugin(registrar.activity()); + channel.setMethodCallHandler(instance); } - private Context context; - - private SharePlugin(FlutterActivity flutterActivity) { - context = flutterActivity; - new MethodChannel(flutterActivity.getFlutterView(), PLATFORM_CHANNEL) - .setMethodCallHandler(this); + private SharePlugin(Activity activity) { + context = activity; } @Override diff --git a/packages/share/example/android/app/src/main/java/io/flutter/plugins/share_example/MainActivity.java b/packages/share/example/android/app/src/main/java/io/flutter/plugins/share_example/MainActivity.java index eae7cfc6845e..85bc246b035e 100644 --- a/packages/share/example/android/app/src/main/java/io/flutter/plugins/share_example/MainActivity.java +++ b/packages/share/example/android/app/src/main/java/io/flutter/plugins/share_example/MainActivity.java @@ -6,15 +6,14 @@ import android.os.Bundle; import io.flutter.app.FlutterActivity; -import io.flutter.plugins.PluginRegistry; +import io.flutter.plugins.GeneratedPluginRegistrant; + public class MainActivity extends FlutterActivity { - PluginRegistry pluginRegistry; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - pluginRegistry = new PluginRegistry(); - pluginRegistry.registerAll(this); + GeneratedPluginRegistrant.registerWith(this); } } diff --git a/packages/share/example/ios/Runner.xcodeproj/project.pbxproj b/packages/share/example/ios/Runner.xcodeproj/project.pbxproj index 08d569a5d9eb..736ed59736fb 100644 --- a/packages/share/example/ios/Runner.xcodeproj/project.pbxproj +++ b/packages/share/example/ios/Runner.xcodeproj/project.pbxproj @@ -7,7 +7,7 @@ objects = { /* Begin PBXBuildFile section */ - 1498D2341E8E89220040F4C2 /* PluginRegistry.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* PluginRegistry.m */; }; + 2D9222511EC45DE6007564B0 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 2D9222501EC45DE6007564B0 /* GeneratedPluginRegistrant.m */; }; 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; }; 3B80C3941E831B6300D905FE /* App.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; }; 3B80C3951E831B6300D905FE /* App.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; @@ -40,8 +40,8 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ - 1498D2321E8E86230040F4C2 /* PluginRegistry.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PluginRegistry.h; sourceTree = ""; }; - 1498D2331E8E89220040F4C2 /* PluginRegistry.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PluginRegistry.m; sourceTree = ""; }; + 2D92224F1EC45DE6007564B0 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = ""; }; + 2D9222501EC45DE6007564B0 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = ""; }; 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = ""; }; 3B80C3931E831B6300D905FE /* App.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = App.framework; path = Flutter/App.framework; sourceTree = ""; }; 7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = ""; }; @@ -125,6 +125,8 @@ 97C146F01CF9000F007C117D /* Runner */ = { isa = PBXGroup; children = ( + 2D92224F1EC45DE6007564B0 /* GeneratedPluginRegistrant.h */, + 2D9222501EC45DE6007564B0 /* GeneratedPluginRegistrant.m */, 7AFFD8ED1D35381100E5BB4D /* AppDelegate.h */, 7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */, 97C146FA1CF9000F007C117D /* Main.storyboard */, @@ -132,8 +134,6 @@ 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */, 97C147021CF9000F007C117D /* Info.plist */, 97C146F11CF9000F007C117D /* Supporting Files */, - 1498D2321E8E86230040F4C2 /* PluginRegistry.h */, - 1498D2331E8E89220040F4C2 /* PluginRegistry.m */, ); path = Runner; sourceTree = ""; @@ -278,7 +278,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n"; + shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n"; showEnvVarsInLog = 0; }; 9740EEB61CF901F6004384FC /* Run Script */ = { @@ -304,7 +304,7 @@ files = ( 978B8F6F1D3862AE00F588F7 /* AppDelegate.m in Sources */, 97C146F31CF9000F007C117D /* main.m in Sources */, - 1498D2341E8E89220040F4C2 /* PluginRegistry.m in Sources */, + 2D9222511EC45DE6007564B0 /* GeneratedPluginRegistrant.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/packages/share/example/ios/Runner/AppDelegate.m b/packages/share/example/ios/Runner/AppDelegate.m index c42396303661..8882024dbad4 100644 --- a/packages/share/example/ios/Runner/AppDelegate.m +++ b/packages/share/example/ios/Runner/AppDelegate.m @@ -3,40 +3,13 @@ // found in the LICENSE file. #include "AppDelegate.h" -#include "PluginRegistry.h" +#include "GeneratedPluginRegistrant.h" -@implementation AppDelegate { - PluginRegistry *plugins; -} +@implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { - // Override point for customization after application launch. - FlutterViewController *flutterController = - (FlutterViewController *)self.window.rootViewController; - plugins = [[PluginRegistry alloc] initWithController:flutterController]; - return YES; -} - -- (void)applicationWillResignActive:(UIApplication *)application { - // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. - // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. -} - -- (void)applicationDidEnterBackground:(UIApplication *)application { - // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. - // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. -} - -- (void)applicationWillEnterForeground:(UIApplication *)application { - // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. -} - -- (void)applicationDidBecomeActive:(UIApplication *)application { - // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. -} - -- (void)applicationWillTerminate:(UIApplication *)application { - // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. + [GeneratedPluginRegistrant registerWithRegistry:self]; + return [super application:application didFinishLaunchingWithOptions:launchOptions]; } @end diff --git a/packages/share/example/ios/Runner/GeneratedPluginRegistrant.h b/packages/share/example/ios/Runner/GeneratedPluginRegistrant.h new file mode 100644 index 000000000000..42f2f69e974d --- /dev/null +++ b/packages/share/example/ios/Runner/GeneratedPluginRegistrant.h @@ -0,0 +1,16 @@ +// +// Generated file. Do not edit. +// + +#ifndef GeneratedPluginRegistrant_h +#define GeneratedPluginRegistrant_h + +#import + +#import "SharePlugin.h" + +@interface GeneratedPluginRegistrant : NSObject ++ (void)registerWithRegistry:(NSObject*)registry; +@end + +#endif /* GeneratedPluginRegistrant_h */ diff --git a/packages/share/example/ios/Runner/GeneratedPluginRegistrant.m b/packages/share/example/ios/Runner/GeneratedPluginRegistrant.m new file mode 100644 index 000000000000..fca65128b125 --- /dev/null +++ b/packages/share/example/ios/Runner/GeneratedPluginRegistrant.m @@ -0,0 +1,13 @@ +// +// Generated file. Do not edit. +// + +#import "GeneratedPluginRegistrant.h" + +@implementation GeneratedPluginRegistrant + ++ (void)registerWithRegistry:(NSObject*)registry { + [SharePlugin registerWithRegistrar:[registry registrarForPlugin:@"SharePlugin"]]; +} + +@end diff --git a/packages/share/ios/Classes/SharePlugin.h b/packages/share/ios/Classes/SharePlugin.h index 4114fb6e09a4..5194e253959a 100644 --- a/packages/share/ios/Classes/SharePlugin.h +++ b/packages/share/ios/Classes/SharePlugin.h @@ -4,7 +4,5 @@ #import -@interface SharePlugin : NSObject -- initWithController: - (FlutterViewController *)controller; -@end \ No newline at end of file +@interface SharePlugin : NSObject +@end diff --git a/packages/share/ios/Classes/SharePlugin.m b/packages/share/ios/Classes/SharePlugin.m index 1106d7c19148..1342c1869620 100644 --- a/packages/share/ios/Classes/SharePlugin.m +++ b/packages/share/ios/Classes/SharePlugin.m @@ -8,27 +8,25 @@ @implementation SharePlugin -- (instancetype)initWithController: - (FlutterViewController *)controller { - FlutterMethodChannel *shareChannel = [FlutterMethodChannel - methodChannelWithName:PLATFORM_CHANNEL - binaryMessenger:controller]; - - [shareChannel setMethodCallHandler:^(FlutterMethodCall *call, - FlutterResult result) { - if ([@"share" isEqualToString:call.method]) { - [self share:call.arguments withController:controller]; - result(nil); - } else { - result([FlutterError errorWithCode:@"UNKNOWN_METHOD" - message:@"Unknown share method called" - details:nil]); - } - }]; ++ (void)registerWithRegistrar:(NSObject *)registrar { + FlutterMethodChannel *shareChannel = [FlutterMethodChannel + methodChannelWithName:PLATFORM_CHANNEL + binaryMessenger:registrar.messenger]; + + [shareChannel setMethodCallHandler:^(FlutterMethodCall *call, + FlutterResult result) { + if ([@"share" isEqualToString:call.method]) { + [self share:call.arguments withController:[UIApplication sharedApplication].keyWindow.rootViewController]; + result(nil); + } else { + result([FlutterError errorWithCode:@"UNKNOWN_METHOD" + message:@"Unknown share method called" + details:nil]); + } + }]; } - -- (void)share:(id)sharedItems withController:(FlutterViewController *)controller { ++ (void)share:(id)sharedItems withController:(UIViewController *)controller { UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:@[sharedItems] applicationActivities:nil]; @@ -37,4 +35,4 @@ - (void)share:(id)sharedItems withController:(FlutterViewController *)controller completion:nil]; } -@end \ No newline at end of file +@end diff --git a/packages/share/pubspec.yaml b/packages/share/pubspec.yaml index 2dceb8913727..6246b4fd0b11 100644 --- a/packages/share/pubspec.yaml +++ b/packages/share/pubspec.yaml @@ -1,5 +1,5 @@ name: share -version: 0.1.0 +version: 0.2.0 description: A Flutter plugin for sharing content from the Flutter app via the platform share sheet author: Flutter Team homepage: https://github.com/flutter/plugins From 57ac9ba2b5f3f128396eb8040f6b2504c6edb4be Mon Sep 17 00:00:00 2001 From: Sarah Zakarias Date: Thu, 11 May 2017 12:41:21 +0200 Subject: [PATCH 2/3] formatting --- .../src/main/java/io/flutter/plugins/share/SharePlugin.java | 3 ++- .../java/io/flutter/plugins/share_example/MainActivity.java | 1 - packages/share/example/ios/Runner.xcodeproj/project.pbxproj | 4 ++-- packages/share/ios/Classes/SharePlugin.m | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/share/android/src/main/java/io/flutter/plugins/share/SharePlugin.java b/packages/share/android/src/main/java/io/flutter/plugins/share/SharePlugin.java index c296e39f6e93..d0dea70a6352 100644 --- a/packages/share/android/src/main/java/io/flutter/plugins/share/SharePlugin.java +++ b/packages/share/android/src/main/java/io/flutter/plugins/share/SharePlugin.java @@ -16,7 +16,6 @@ public class SharePlugin implements MethodChannel.MethodCallHandler { private static final String PLATFORM_CHANNEL = "plugins.flutter.io/share"; - private final Context context; public static void registerWith(Registrar registrar) { MethodChannel channel = new MethodChannel(registrar.messenger(), PLATFORM_CHANNEL); @@ -24,6 +23,8 @@ public static void registerWith(Registrar registrar) { channel.setMethodCallHandler(instance); } + private final Context context; + private SharePlugin(Activity activity) { context = activity; } diff --git a/packages/share/example/android/app/src/main/java/io/flutter/plugins/share_example/MainActivity.java b/packages/share/example/android/app/src/main/java/io/flutter/plugins/share_example/MainActivity.java index 85bc246b035e..758fb614f3bb 100644 --- a/packages/share/example/android/app/src/main/java/io/flutter/plugins/share_example/MainActivity.java +++ b/packages/share/example/android/app/src/main/java/io/flutter/plugins/share_example/MainActivity.java @@ -8,7 +8,6 @@ import io.flutter.app.FlutterActivity; import io.flutter.plugins.GeneratedPluginRegistrant; - public class MainActivity extends FlutterActivity { @Override diff --git a/packages/share/example/ios/Runner.xcodeproj/project.pbxproj b/packages/share/example/ios/Runner.xcodeproj/project.pbxproj index 736ed59736fb..b18e259f427e 100644 --- a/packages/share/example/ios/Runner.xcodeproj/project.pbxproj +++ b/packages/share/example/ios/Runner.xcodeproj/project.pbxproj @@ -437,7 +437,7 @@ "$(inherited)", "$(PROJECT_DIR)/Flutter", ); - PRODUCT_BUNDLE_IDENTIFIER = com.yourcompany.shareExample; + PRODUCT_BUNDLE_IDENTIFIER = io.flutter.plugins.shareExample; PRODUCT_NAME = "$(TARGET_NAME)"; }; name = Debug; @@ -459,7 +459,7 @@ "$(inherited)", "$(PROJECT_DIR)/Flutter", ); - PRODUCT_BUNDLE_IDENTIFIER = com.yourcompany.shareExample; + PRODUCT_BUNDLE_IDENTIFIER = io.flutter.plugins.shareExample; PRODUCT_NAME = "$(TARGET_NAME)"; }; name = Release; diff --git a/packages/share/ios/Classes/SharePlugin.m b/packages/share/ios/Classes/SharePlugin.m index 1342c1869620..fbb244fe15fe 100644 --- a/packages/share/ios/Classes/SharePlugin.m +++ b/packages/share/ios/Classes/SharePlugin.m @@ -31,8 +31,8 @@ + (void)share:(id)sharedItems withController:(UIViewController *)controller { [[UIActivityViewController alloc] initWithActivityItems:@[sharedItems] applicationActivities:nil]; [controller presentViewController:activityViewController - animated:YES - completion:nil]; + animated:YES + completion:nil]; } @end From 1c1c0664544d1722e969c995e84bf4a65de5f4cc Mon Sep 17 00:00:00 2001 From: Sarah Zakarias Date: Thu, 11 May 2017 13:08:50 +0200 Subject: [PATCH 3/3] comments --- .../main/java/io/flutter/plugins/share/SharePlugin.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/packages/share/android/src/main/java/io/flutter/plugins/share/SharePlugin.java b/packages/share/android/src/main/java/io/flutter/plugins/share/SharePlugin.java index d0dea70a6352..1a24d4b5874d 100644 --- a/packages/share/android/src/main/java/io/flutter/plugins/share/SharePlugin.java +++ b/packages/share/android/src/main/java/io/flutter/plugins/share/SharePlugin.java @@ -4,7 +4,6 @@ package io.flutter.plugins.share; -import android.app.Activity; import android.content.Context; import android.content.Intent; @@ -15,18 +14,18 @@ /** Plugin method host for presenting a share sheet via Intent */ public class SharePlugin implements MethodChannel.MethodCallHandler { - private static final String PLATFORM_CHANNEL = "plugins.flutter.io/share"; + private static final String CHANNEL = "plugins.flutter.io/share"; public static void registerWith(Registrar registrar) { - MethodChannel channel = new MethodChannel(registrar.messenger(), PLATFORM_CHANNEL); + MethodChannel channel = new MethodChannel(registrar.messenger(), CHANNEL); SharePlugin instance = new SharePlugin(registrar.activity()); channel.setMethodCallHandler(instance); } private final Context context; - private SharePlugin(Activity activity) { - context = activity; + private SharePlugin(Context context) { + this.context = context; } @Override