Skip to content

Commit

Permalink
feat: create instagramIsAvailableToShare in IOS side
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrohsampaioo committed Aug 2, 2022
1 parent 5c9eaa0 commit 35cec41
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 13 deletions.
17 changes: 14 additions & 3 deletions ios/Classes/SwiftCremeSharingPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@ public class SwiftCremeSharingPlugin: NSObject, FlutterPlugin {

public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
switch (call.method){
case "instagramIsAvailableToShare":
if let storiesUrl = URL(string: "instagram-stories://share") {
if UIApplication.shared.canOpenURL(storiesUrl) {
if #available(iOS 10.0, *) {
return result(true)
}
return result(false)
} else {
return result(false)
}
}
case "shareToInstagramStories":
if let storiesUrl = URL(string: "instagram-stories://share") {
if UIApplication.shared.canOpenURL(storiesUrl) {
Expand Down Expand Up @@ -45,11 +56,11 @@ public class SwiftCremeSharingPlugin: NSObject, FlutterPlugin {
]
UIPasteboard.general.setItems([pasteboardItems], options: pasteboardOptions)
UIApplication.shared.open(storiesUrl, options: [:], completionHandler: nil)
return result("User have instagram on their device.")
return result(nil)
}
return result("work only in IOS 10.0 or newer")
return result(nil)
} else {
result("User doesn't have instagram on their device.")
return result(nil)
}
}
default:
Expand Down
39 changes: 29 additions & 10 deletions lib/creme_sharing.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,42 @@ class CremeSharing {
_httpClient.close(force: true);
}

/// This method will check is the user have the Instagram available to share
Future<bool> instagramIsAvailableToShare({
Color? backgroundTopColor,
Color? backgroundBottomColor,
String? stickerImage,
String? backgroundVideo,
String? backgroundImage,
String? contentURL,
}) =>
CremeSharingPlatform.instance.instagramIsAvailableToShare();

/// All the arguments are the same of the documentation in https://developers.facebook.com/docs/sharing/sharing-to-stories
/// but in the IOS side you can:
/// - [backgroundTopColor] : will be transformed to a String in hex color
/// - [backgroundBottomColor] : will be transformed to a String in hex color
/// - [stickerImage] : will be transformed to an image if the value be a URL or an image encoded 64 as String
/// - [backgroundImage] : will be transformed to an image if the value be an URL or an image encoded 64 as String
/// - [backgroundVideo] : will be transformed to an image if the value be an URL
/// - [contentURL] : it will be a string (that don't work because the app need to be a partner of Instagram)
/// but in the Android will be implemented (WIP)
Future<void> shareToInstagramStories({
Color? backgroundTopColor,
Color? backgroundBottomColor,
String? stickerImage,
String? backgroundVideo,
String? backgroundImage,
String? contentURL,
}) {
return CremeSharingPlatform.instance.shareToInstagramStories(
backgroundTopColor: backgroundTopColor,
backgroundBottomColor: backgroundBottomColor,
stickerImage: stickerImage,
backgroundVideo: backgroundVideo,
backgroundImage: backgroundImage,
contentURL: contentURL,
);
}
}) =>
CremeSharingPlatform.instance.shareToInstagramStories(
backgroundTopColor: backgroundTopColor,
backgroundBottomColor: backgroundBottomColor,
stickerImage: stickerImage,
backgroundVideo: backgroundVideo,
backgroundImage: backgroundImage,
contentURL: contentURL,
);

/// This method should be used to share some creator to Instagram stories
/// and the mockup can be found on: https://www.figma.com/file/r5ox3y5gRNFXPDb1KcsQS3/CREME-2022?node-id=2316%3A217770
Expand Down
14 changes: 14 additions & 0 deletions lib/creme_sharing_method_channel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@ class MethodChannelCremeSharing extends CremeSharingPlatform {
@visibleForTesting
final methodChannel = const MethodChannel('creme_sharing');

@override
Future<bool> instagramIsAvailableToShare() async {
if (Platform.isIOS) {
return (await methodChannel
.invokeMethod<bool>('instagramIsAvailableToShare') ??
false);
}

/// TODO: implement Android
return super.instagramIsAvailableToShare();
}

@override
Future<void> shareToInstagramStories({
Color? backgroundTopColor,
Expand All @@ -38,6 +50,8 @@ class MethodChannelCremeSharing extends CremeSharingPlatform {
},
);
}

/// TODO: implement Android
return super.shareToInstagramStories(
contentURL: contentURL,
backgroundTopColor: backgroundTopColor,
Expand Down
4 changes: 4 additions & 0 deletions lib/creme_sharing_platform_interface.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ abstract class CremeSharingPlatform extends PlatformInterface {
_instance = instance;
}

Future<bool> instagramIsAvailableToShare() {
throw UnimplementedError('platformVersion() has not been implemented.');
}

Future<void> shareToInstagramStories({
Color? backgroundTopColor,
Color? backgroundBottomColor,
Expand Down

0 comments on commit 35cec41

Please sign in to comment.