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

Commit de9233c

Browse files
authored
Update share plugin to new plugin registration. (#35)
1 parent be545f4 commit de9233c

File tree

10 files changed

+80
-82
lines changed

10 files changed

+80
-82
lines changed

packages/share/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## [0.2.0] - 2017-05-11
2+
3+
* Upgrade to new plugin registration. (https://groups.google.com/forum/#!topic/flutter-dev/zba1Ynf2OKM)
4+
15
## [0.1.0] - 2017-05-05
26

37
* Initial Open Source release.

packages/share/android/src/main/java/io/flutter/plugins/share/SharePlugin.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,25 @@
77
import android.content.Context;
88
import android.content.Intent;
99

10-
import io.flutter.app.FlutterActivity;
1110
import io.flutter.plugin.common.MethodChannel;
12-
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
13-
import io.flutter.plugin.common.MethodChannel.Result;
1411
import io.flutter.plugin.common.MethodCall;
12+
import io.flutter.plugin.common.PluginRegistry.Registrar;
1513

1614
/** Plugin method host for presenting a share sheet via Intent */
1715
public class SharePlugin implements MethodChannel.MethodCallHandler {
1816

19-
private static final String PLATFORM_CHANNEL = "plugins.flutter.io/share";
17+
private static final String CHANNEL = "plugins.flutter.io/share";
2018

21-
public static SharePlugin register(FlutterActivity flutterActivity) {
22-
return new SharePlugin(flutterActivity);
19+
public static void registerWith(Registrar registrar) {
20+
MethodChannel channel = new MethodChannel(registrar.messenger(), CHANNEL);
21+
SharePlugin instance = new SharePlugin(registrar.activity());
22+
channel.setMethodCallHandler(instance);
2323
}
2424

25-
private Context context;
25+
private final Context context;
2626

27-
private SharePlugin(FlutterActivity flutterActivity) {
28-
context = flutterActivity;
29-
new MethodChannel(flutterActivity.getFlutterView(), PLATFORM_CHANNEL)
30-
.setMethodCallHandler(this);
27+
private SharePlugin(Context context) {
28+
this.context = context;
3129
}
3230

3331
@Override

packages/share/example/android/app/src/main/java/io/flutter/plugins/share_example/MainActivity.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,13 @@
66

77
import android.os.Bundle;
88
import io.flutter.app.FlutterActivity;
9-
import io.flutter.plugins.PluginRegistry;
9+
import io.flutter.plugins.GeneratedPluginRegistrant;
1010

1111
public class MainActivity extends FlutterActivity {
12-
PluginRegistry pluginRegistry;
1312

1413
@Override
1514
protected void onCreate(Bundle savedInstanceState) {
1615
super.onCreate(savedInstanceState);
17-
pluginRegistry = new PluginRegistry();
18-
pluginRegistry.registerAll(this);
16+
GeneratedPluginRegistrant.registerWith(this);
1917
}
2018
}

packages/share/example/ios/Runner.xcodeproj/project.pbxproj

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10-
1498D2341E8E89220040F4C2 /* PluginRegistry.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* PluginRegistry.m */; };
10+
2D9222511EC45DE6007564B0 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 2D9222501EC45DE6007564B0 /* GeneratedPluginRegistrant.m */; };
1111
3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; };
1212
3B80C3941E831B6300D905FE /* App.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; };
1313
3B80C3951E831B6300D905FE /* App.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
@@ -40,8 +40,8 @@
4040
/* End PBXCopyFilesBuildPhase section */
4141

4242
/* Begin PBXFileReference section */
43-
1498D2321E8E86230040F4C2 /* PluginRegistry.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PluginRegistry.h; sourceTree = "<group>"; };
44-
1498D2331E8E89220040F4C2 /* PluginRegistry.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PluginRegistry.m; sourceTree = "<group>"; };
43+
2D92224F1EC45DE6007564B0 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = "<group>"; };
44+
2D9222501EC45DE6007564B0 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = "<group>"; };
4545
3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = "<group>"; };
4646
3B80C3931E831B6300D905FE /* App.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = App.framework; path = Flutter/App.framework; sourceTree = "<group>"; };
4747
7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = "<group>"; };
@@ -125,15 +125,15 @@
125125
97C146F01CF9000F007C117D /* Runner */ = {
126126
isa = PBXGroup;
127127
children = (
128+
2D92224F1EC45DE6007564B0 /* GeneratedPluginRegistrant.h */,
129+
2D9222501EC45DE6007564B0 /* GeneratedPluginRegistrant.m */,
128130
7AFFD8ED1D35381100E5BB4D /* AppDelegate.h */,
129131
7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */,
130132
97C146FA1CF9000F007C117D /* Main.storyboard */,
131133
97C146FD1CF9000F007C117D /* Assets.xcassets */,
132134
97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */,
133135
97C147021CF9000F007C117D /* Info.plist */,
134136
97C146F11CF9000F007C117D /* Supporting Files */,
135-
1498D2321E8E86230040F4C2 /* PluginRegistry.h */,
136-
1498D2331E8E89220040F4C2 /* PluginRegistry.m */,
137137
);
138138
path = Runner;
139139
sourceTree = "<group>";
@@ -278,7 +278,7 @@
278278
);
279279
runOnlyForDeploymentPostprocessing = 0;
280280
shellPath = /bin/sh;
281-
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";
281+
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";
282282
showEnvVarsInLog = 0;
283283
};
284284
9740EEB61CF901F6004384FC /* Run Script */ = {
@@ -304,7 +304,7 @@
304304
files = (
305305
978B8F6F1D3862AE00F588F7 /* AppDelegate.m in Sources */,
306306
97C146F31CF9000F007C117D /* main.m in Sources */,
307-
1498D2341E8E89220040F4C2 /* PluginRegistry.m in Sources */,
307+
2D9222511EC45DE6007564B0 /* GeneratedPluginRegistrant.m in Sources */,
308308
);
309309
runOnlyForDeploymentPostprocessing = 0;
310310
};
@@ -437,7 +437,7 @@
437437
"$(inherited)",
438438
"$(PROJECT_DIR)/Flutter",
439439
);
440-
PRODUCT_BUNDLE_IDENTIFIER = com.yourcompany.shareExample;
440+
PRODUCT_BUNDLE_IDENTIFIER = io.flutter.plugins.shareExample;
441441
PRODUCT_NAME = "$(TARGET_NAME)";
442442
};
443443
name = Debug;
@@ -459,7 +459,7 @@
459459
"$(inherited)",
460460
"$(PROJECT_DIR)/Flutter",
461461
);
462-
PRODUCT_BUNDLE_IDENTIFIER = com.yourcompany.shareExample;
462+
PRODUCT_BUNDLE_IDENTIFIER = io.flutter.plugins.shareExample;
463463
PRODUCT_NAME = "$(TARGET_NAME)";
464464
};
465465
name = Release;

packages/share/example/ios/Runner/AppDelegate.m

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,13 @@
33
// found in the LICENSE file.
44

55
#include "AppDelegate.h"
6-
#include "PluginRegistry.h"
6+
#include "GeneratedPluginRegistrant.h"
77

8-
@implementation AppDelegate {
9-
PluginRegistry *plugins;
10-
}
8+
@implementation AppDelegate
119

1210
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
13-
// Override point for customization after application launch.
14-
FlutterViewController *flutterController =
15-
(FlutterViewController *)self.window.rootViewController;
16-
plugins = [[PluginRegistry alloc] initWithController:flutterController];
17-
return YES;
18-
}
19-
20-
- (void)applicationWillResignActive:(UIApplication *)application {
21-
// 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.
22-
// 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.
23-
}
24-
25-
- (void)applicationDidEnterBackground:(UIApplication *)application {
26-
// 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.
27-
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
28-
}
29-
30-
- (void)applicationWillEnterForeground:(UIApplication *)application {
31-
// 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.
32-
}
33-
34-
- (void)applicationDidBecomeActive:(UIApplication *)application {
35-
// 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.
36-
}
37-
38-
- (void)applicationWillTerminate:(UIApplication *)application {
39-
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
11+
[GeneratedPluginRegistrant registerWithRegistry:self];
12+
return [super application:application didFinishLaunchingWithOptions:launchOptions];
4013
}
4114

4215
@end
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//
2+
// Generated file. Do not edit.
3+
//
4+
5+
#ifndef GeneratedPluginRegistrant_h
6+
#define GeneratedPluginRegistrant_h
7+
8+
#import <Flutter/Flutter.h>
9+
10+
#import "SharePlugin.h"
11+
12+
@interface GeneratedPluginRegistrant : NSObject
13+
+ (void)registerWithRegistry:(NSObject<FlutterPluginRegistry>*)registry;
14+
@end
15+
16+
#endif /* GeneratedPluginRegistrant_h */
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//
2+
// Generated file. Do not edit.
3+
//
4+
5+
#import "GeneratedPluginRegistrant.h"
6+
7+
@implementation GeneratedPluginRegistrant
8+
9+
+ (void)registerWithRegistry:(NSObject<FlutterPluginRegistry>*)registry {
10+
[SharePlugin registerWithRegistrar:[registry registrarForPlugin:@"SharePlugin"]];
11+
}
12+
13+
@end

packages/share/ios/Classes/SharePlugin.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,5 @@
44

55
#import <Flutter/Flutter.h>
66

7-
@interface SharePlugin : NSObject
8-
- initWithController:
9-
(FlutterViewController *)controller;
10-
@end
7+
@interface SharePlugin : NSObject<FlutterPlugin>
8+
@end

packages/share/ios/Classes/SharePlugin.m

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,33 +8,31 @@
88

99
@implementation SharePlugin
1010

11-
- (instancetype)initWithController:
12-
(FlutterViewController *)controller {
13-
FlutterMethodChannel *shareChannel = [FlutterMethodChannel
14-
methodChannelWithName:PLATFORM_CHANNEL
15-
binaryMessenger:controller];
16-
17-
[shareChannel setMethodCallHandler:^(FlutterMethodCall *call,
18-
FlutterResult result) {
19-
if ([@"share" isEqualToString:call.method]) {
20-
[self share:call.arguments withController:controller];
21-
result(nil);
22-
} else {
23-
result([FlutterError errorWithCode:@"UNKNOWN_METHOD"
24-
message:@"Unknown share method called"
25-
details:nil]);
26-
}
27-
}];
11+
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar> *)registrar {
12+
FlutterMethodChannel *shareChannel = [FlutterMethodChannel
13+
methodChannelWithName:PLATFORM_CHANNEL
14+
binaryMessenger:registrar.messenger];
15+
16+
[shareChannel setMethodCallHandler:^(FlutterMethodCall *call,
17+
FlutterResult result) {
18+
if ([@"share" isEqualToString:call.method]) {
19+
[self share:call.arguments withController:[UIApplication sharedApplication].keyWindow.rootViewController];
20+
result(nil);
21+
} else {
22+
result([FlutterError errorWithCode:@"UNKNOWN_METHOD"
23+
message:@"Unknown share method called"
24+
details:nil]);
25+
}
26+
}];
2827
}
2928

30-
31-
- (void)share:(id)sharedItems withController:(FlutterViewController *)controller {
29+
+ (void)share:(id)sharedItems withController:(UIViewController *)controller {
3230
UIActivityViewController *activityViewController =
3331
[[UIActivityViewController alloc] initWithActivityItems:@[sharedItems]
3432
applicationActivities:nil];
3533
[controller presentViewController:activityViewController
36-
animated:YES
37-
completion:nil];
34+
animated:YES
35+
completion:nil];
3836
}
3937

40-
@end
38+
@end

packages/share/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: share
2-
version: 0.1.0
2+
version: 0.2.0
33
description: A Flutter plugin for sharing content from the Flutter app via the platform share sheet
44
author: Flutter Team <[email protected]>
55
homepage: https://github.com/flutter/plugins

0 commit comments

Comments
 (0)