Skip to content

Commit

Permalink
Creative kit share sticker updates
Browse files Browse the repository at this point in the history
  • Loading branch information
maxbbb committed May 13, 2021
1 parent 68f02d9 commit 8142544
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 2 deletions.
10 changes: 8 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
requireNativeComponent,
} from "react-native";

const { LoginKit } = NativeModules;
const { LoginKit, CreativeKit } = NativeModules;

class BitmojiStickerPicker extends React.Component {
render() {
Expand Down Expand Up @@ -74,7 +74,13 @@ class RNLoginKit {
}
}

class RNCreativeKit {}
class RNCreativeKit {
static async shareSticker(options) {
// options: stickerUrl, swipeUpUrl, caption
const { result } = await CreativeKit.shareSticker(options);
return result;
}
}

class RNBitmojiKit {}

Expand Down
89 changes: 89 additions & 0 deletions ios/CreativeKit.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#import "CreativeKit.h"
#import <SCSDKCreativeKit/SCSDKCreativeKit.h>

@implementation CreativeKit {
SCSDKSnapAPI *_scSdkSnapApi;
}

- (dispatch_queue_t)methodQueue
{
return dispatch_get_main_queue();
}

-(id)init
{
self = [super init];
if(self)
{
if (!_scSdkSnapApi) {
_scSdkSnapApi = [[SCSDKSnapAPI alloc] init];
NSLog(@"hi");
}
}
return self;
}

RCT_EXPORT_MODULE()

RCT_EXPORT_METHOD(shareSticker: (NSDictionary *)options
resolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject)
{
if ([[UIApplication sharedApplication] canOpenURL: [NSURL URLWithString:@"snapchat://"]]) {

SCSDKSnapSticker *sticker;

if (options[@"stickerFileUrl"]) {
UIImage *stickerImage = [UIImage imageWithContentsOfFile:options[@"stickerFileUrl"]];
sticker = [[SCSDKSnapSticker alloc] initWithStickerImage:stickerImage];
} else if ( options[@"stickerUrl"]) {
NSURL *stickerImageUrl = [NSURL URLWithString: options[@"stickerUrl"]];
sticker = [[SCSDKSnapSticker alloc] initWithStickerUrl:stickerImageUrl isAnimated:NO];
}

/* Stickers to be used in Snap */
// UIImage *stickerImage = /* Prepare a sticker image */;
// SCSDKSnapSticker *sticker = [[SCSDKSnapSticker alloc] initWithStickerImage:stickerImage];
/* Alternatively, use a URL instead */
// SCSDKSnapSticker *sticker = [[SCSDKSnapSticker alloc] initWithStickerUrl:stickerImageUrl isAnimated:NO];

/* Modeling a Snap using SCSDKNoSnapContent*/
SCSDKNoSnapContent *snap = [[SCSDKNoSnapContent alloc] init];

snap.sticker = sticker; /* Optional */

if (options[@"caption"]) {
snap.caption = options[@"caption"]; /* Optional */
}

if (options[@"swipeUpUrl"]) {
snap.attachmentUrl = options[@"swipeUpUrl"];
}

[_scSdkSnapApi startSendingContent:snap completionHandler:^(NSError *error) {
/* Handle response */
if (error) {
reject(@"error", error.localizedDescription, error);
} else {
resolve(@{@"result": @(YES)});
}
}];

// [NSThread sleepForTimeInterval:1.0f];

} else {
// Cannot open snapchat
NSString *stringURL = @"http://itunes.apple.com/app/snapchat/id447188370";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];

// NSString *errorMessage = @"Not installed";
// NSDictionary *userInfo = @{NSLocalizedFailureReasonErrorKey: NSLocalizedString(errorMessage, nil)};
// NSError *error = [NSError errorWithDomain:@"com.rnshare" code:1 userInfo:userInfo];

// failureCallback(error);
}

}

@end
2 changes: 2 additions & 0 deletions react-native-snapkit.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,7 @@ Pod::Spec.new do |s|

s.dependency "React"
s.dependency "SnapSDK/SCSDKLoginKit", '1.6.9'
s.dependency "SnapSDK/SCSDKCreativeKit", '1.6.9'

end

0 comments on commit 8142544

Please sign in to comment.