Skip to content
This repository has been archived by the owner on Apr 2, 2021. It is now read-only.

Commit

Permalink
react-native-fbsdk-0.5.1
Browse files Browse the repository at this point in the history
  • Loading branch information
dzhuowen committed Jun 16, 2017
1 parent e7df8ac commit a5bf87c
Show file tree
Hide file tree
Showing 22 changed files with 1,769 additions and 150 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ ShareApi.canShare(this.state.shareLinkContent).then(
}
);
```
### [Analytics](https://developers.facebook.com/docs/app-events)
### [Analytics for Apps](https://developers.facebook.com/docs/app-events)
#### App events
```js
const FBSDK = require('react-native-fbsdk');
Expand Down
10 changes: 7 additions & 3 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 25
compileSdkVersion 23
buildToolsVersion "23.0.1"

defaultConfig {
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
Expand All @@ -17,7 +19,9 @@ android {
}

dependencies {
compile 'com.android.support:appcompat-v7:25.0.0'
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.0'
compile 'com.facebook.react:react-native:+' // support react-native-v0.22-rc+
compile('com.facebook.android:facebook-android-sdk:4.+')
compile('com.facebook.android:facebook-android-sdk:4.22.1')
}
Original file line number Diff line number Diff line change
Expand Up @@ -171,23 +171,13 @@ public void logEvent(String eventName, double valueToSum, ReadableMap parameters
* one purchase event to the next.
*/
@ReactMethod
public void logPurchase(double purchaseAmount, String currencyCode,
@Nullable ReadableMap parameters) {
public void logPurchase(double purchaseAmount, String currencyCode, @Nullable ReadableMap parameters) {
mAppEventLogger.logPurchase(
BigDecimal.valueOf(purchaseAmount),
Currency.getInstance(currencyCode),
Arguments.toBundle(parameters));
}

/**
* Logs an app event that tracks that the application was open via Push Notification.
* @param payload Notification payload received.
*/
@ReactMethod
public void logPushNotificationOpen(@Nullable ReadableMap payload) {
mAppEventLogger.logPushNotificationOpen(Arguments.toBundle(payload));
}

/**
* Explicitly flush any stored events to the server. Implicit flushes may happen depending on
* the value of getFlushBehavior. This method allows for explicit, app invoked flushing.
Expand All @@ -196,13 +186,4 @@ public void logPushNotificationOpen(@Nullable ReadableMap payload) {
public void flush() {
mAppEventLogger.flush();
}

/**
* Sets and sends registration id to register the current app for push notifications.
* @param registrationId RegistrationId received from GCM.
*/
@ReactMethod
public void setPushNotificationsRegistrationId(String registrationId) {
AppEventsLogger.setPushNotificationsRegistrationId(registrationId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

public class FBSDKPackage implements ReactPackage {

public static final String VERSION_TO_RELEASE = "ReactNative-v0.6.0";
public static final String VERSION_TO_RELEASE = "ReactNative-v0.5.1";

private CallbackManager mCallbackManager;
public FBSDKPackage(CallbackManager callbackManager) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ public final class Utility {
public static AccessToken buildAccessToken(ReadableMap accessTokenMap) {
AccessTokenSource accessTokenSource = AccessTokenSource
.valueOf(accessTokenMap.getString("accessTokenSource"));
Date expirationTime = new Date((long) accessTokenMap.getDouble("expirationTime"));
Date lastRefreshTime = new Date((long) accessTokenMap.getDouble("lastRefreshTime"));
Date expirationTime = new Date((long)accessTokenMap.getDouble("expirationTime"));
Date lastRefreshTime = new Date((long)accessTokenMap.getDouble("lastRefreshTime"));
return new AccessToken(
accessTokenMap.getString("accessToken"),
accessTokenMap.getString("applicationID"),
Expand All @@ -78,12 +78,10 @@ public static WritableMap accessTokenToReactMap(AccessToken accessToken) {
map.putString("accessToken", accessToken.getToken());
map.putString("applicationID", accessToken.getApplicationId());
map.putString("userID", accessToken.getUserId());
map.putArray(
"permissions",
Arguments.fromJavaArgs(setToStringArray(accessToken.getPermissions())));
map.putArray(
"declinedPermissions",
Arguments.fromJavaArgs(setToStringArray(accessToken.getDeclinedPermissions())));
map.putArray("permissions",
Arguments.fromJavaArgs(setToStringArray(accessToken.getPermissions())));
map.putArray("declinedPermissions",
Arguments.fromJavaArgs(setToStringArray(accessToken.getDeclinedPermissions())));
map.putString("accessTokenSource", accessToken.getSource().name());
map.putDouble("expirationTime", (double) accessToken.getExpires().getTime());
map.putDouble("lastRefreshTime", (double) accessToken.getLastRefresh().getTime());
Expand Down Expand Up @@ -113,11 +111,6 @@ public static AppInviteContent buildAppInviteContent(ReadableMap appInviteConten
if (appInviteContentMap.hasKey("previewImageUrl")) {
appInviteContentBuilder.setPreviewImageUrl(appInviteContentMap.getString("previewImageUrl"));
}
String promotionText = getValueOrNull(appInviteContentMap, "promotionText");
String promotionCode = getValueOrNull(appInviteContentMap, "promotionCode");
if (promotionText != null && promotionCode != null) {
appInviteContentBuilder.setPromotionDetails(promotionText, promotionCode);
}
return appInviteContentBuilder.build();
}

Expand All @@ -126,10 +119,12 @@ public static AppGroupCreationContent buildAppGroupCreationContent(ReadableMap a
appGroupCreationContentBuilder.setName(appGroupCreationContenMap.getString("name"));
appGroupCreationContentBuilder.setDescription(appGroupCreationContenMap.getString("description"));
appGroupCreationContentBuilder.setAppGroupPrivacy(
AppGroupCreationContent.AppGroupPrivacy.valueOf(appGroupCreationContenMap.getString("privacy")));
AppGroupCreationContent.AppGroupPrivacy.valueOf(appGroupCreationContenMap.getString("privacy"))
);
return appGroupCreationContentBuilder.build();
}


public static GameRequestContent buildGameRequestContent(ReadableMap gameRequestContentMap) {
GameRequestContent.Builder gameRequestContentBuilder = new GameRequestContent.Builder();
String actionType = getValueOrNull(gameRequestContentMap, "actionType");
Expand Down Expand Up @@ -188,6 +183,7 @@ public static SharePhoto buildSharePhoto(ReadableMap photoMap) {
return photoBuilder.build();
}


public static ShareContent buildShareVideoContent(ReadableMap shareVideoContent) {
ShareVideoContent.Builder contentBuilder = new ShareVideoContent.Builder();
String url = getValueOrNull(shareVideoContent, "contentUrl");
Expand Down Expand Up @@ -235,7 +231,7 @@ public static ShareOpenGraphObject buildShareOpenGraphObject(ReadableMap entry)
while (keySetIterator.hasNextKey()) {
String key = keySetIterator.nextKey();
ReadableMap subEntry = value.getMap(key);
switch (subEntry.getString("type")) {
switch (subEntry.getString("type")){
case "number":
contentBuilder.putDouble(key, subEntry.getDouble("value"));
break;
Expand Down
103 changes: 103 additions & 0 deletions ios/BUCK
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
if THIS_IS_FBOBJC:
ios_library(
name = 'RNSDKCoreKit',
inherited_buck_flags = STATIC_LIBRARY_IOS_FLAGS,
configs = fbobjc_configs(
FBOBJC_STATIC_LIBRARY,
extra_target_config={
'HEADER_SEARCH_PATHS': '$(inherited) $(REPO_ROOT)/ios-sdk/FBSDKCoreKit/** \
$(REPO_ROOT)/Libraries/FBReactKit/js/react-native-github/React/**',
},
),
preprocessor_flags = OBJC_ARC_PREPROCESSOR_FLAGS + DEBUG_PREPROCESSOR_FLAGS,
compiler_flags = ['-w'],
srcs = glob([
'RCTFBSDK/core/*.m',
]),
exported_headers = glob([
'RCTFBSDK/core/*.h'
]),
frameworks = [
'$SDKROOT/System/Library/Frameworks/Foundation.framework',
],
deps = [
'//Libraries/FBReactKit:RCTNetwork',
'//Libraries/FBReactKit:RCTText',
'//Libraries/FBReactKit:React',
'//ios-sdk:FacebookSDK',
],
visibility = [ 'PUBLIC' ],
)

ios_library(
name = 'RNSDKLoginKit',
inherited_buck_flags = STATIC_LIBRARY_IOS_FLAGS,
configs = fbobjc_configs(FBOBJC_STATIC_LIBRARY),
preprocessor_flags = OBJC_ARC_PREPROCESSOR_FLAGS + DEBUG_PREPROCESSOR_FLAGS,
compiler_flags = ['-w'],
srcs = glob([
'RCTFBSDK/login/*.m'
]),
exported_headers = glob([
'RCTFBSDK/login/*.h',
]),
frameworks = [
'$SDKROOT/System/Library/Frameworks/Foundation.framework',
],
deps = [
':RNSDKCoreKit',
],
visibility = [ 'PUBLIC' ],
)

ios_library(
name = 'RNSDKShareKit',
inherited_buck_flags = STATIC_LIBRARY_IOS_FLAGS,
configs = fbobjc_configs(FBOBJC_STATIC_LIBRARY),
preprocessor_flags = OBJC_ARC_PREPROCESSOR_FLAGS + DEBUG_PREPROCESSOR_FLAGS,
compiler_flags = ['-w'],
srcs = glob([
'RCTFBSDK/share/*.m',
]),
exported_headers = glob([
'RCTFBSDK/share/*.h',
]),
frameworks = [
'$SDKROOT/System/Library/Frameworks/Foundation.framework',
],
deps = [
':RNSDKCoreKit',
],
visibility = [ 'PUBLIC' ],
)

ios_library(
name = 'RNSDK',
inherited_buck_flags = STATIC_LIBRARY_IOS_FLAGS,
configs = fbobjc_configs(FBOBJC_STATIC_LIBRARY),
preprocessor_flags = OBJC_ARC_PREPROCESSOR_FLAGS + DEBUG_PREPROCESSOR_FLAGS,
compiler_flags = ['-w'],
srcs = [],
frameworks = [
'$SDKROOT/System/Library/Frameworks/Foundation.framework',
],
deps = [
':RNSDKCoreKit',
':RNSDKLoginKit',
':RNSDKShareKit',
],
visibility = [ 'PUBLIC' ],
)

elif THIS_IS_FBANDROID:
android_library(
name = 'RNSDK',
srcs = [],
provided_deps = [
],
deps = [
],
visibility = [
'PUBLIC',
],
)
10 changes: 0 additions & 10 deletions ios/RCTFBSDK/core/RCTFBSDKAppEvents.m
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,6 @@ - (dispatch_queue_t)methodQueue
accessToken:nil];
}

RCT_EXPORT_METHOD(logPushNotificationOpen:(NSDictionary *)payload)
{
[FBSDKAppEvents logPushNotificationOpen:payload];
}

RCT_EXPORT_METHOD(setFlushBehavior:(FBSDKAppEventsFlushBehavior)flushBehavior)
{
[FBSDKAppEvents setFlushBehavior:flushBehavior];
Expand All @@ -75,9 +70,4 @@ - (dispatch_queue_t)methodQueue
[FBSDKAppEvents flush];
}

RCT_EXPORT_METHOD(setPushNotificationsDeviceToken:(NSString *)deviceToken)
{
[FBSDKAppEvents setPushNotificationsDeviceToken:[RCTConvert NSData:deviceToken]];
}

@end
2 changes: 1 addition & 1 deletion ios/RCTFBSDK/core/RCTFBSDKInitializer.m
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ @implementation RCTFBSDKInitializer
- (instancetype)init
{
if ((self = [super init])) {
[FBSDKSettings setUserAgentSuffix:@"ReactNative-v0.6.0"];
[FBSDKSettings setUserAgentSuffix:@"ReactNative-v0.5.1"];
}
return self;
}
Expand Down
3 changes: 3 additions & 0 deletions ios/RCTFBSDK/share/RCTConvert+FBSDKSharingContent.m
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ static void RCTAppendGenericContent(RCTFBSDKSharingContent contentObject, NSDict
{
FBSDKShareLinkContent *linkContent = [[FBSDKShareLinkContent alloc] init];
linkContent.contentURL = [RCTConvert NSURL:contentData[@"contentUrl"]];
linkContent.contentDescription = [RCTConvert NSString:contentData[@"contentDescription"]];
linkContent.contentTitle = [RCTConvert NSString:contentData[@"contentTitle"]];
linkContent.imageURL = [RCTConvert NSURL:contentData[@"imageUrl"]];
linkContent.quote = [RCTConvert NSString:contentData[@"quote"]];
return linkContent;
}
Expand Down
4 changes: 1 addition & 3 deletions ios/RCTFBSDK/share/RCTFBSDKAppInviteDialog.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ + (FBSDKAppInviteContent *)FBSDKAppInviteContent:(id)json
FBSDKAppInviteContent *content = [[FBSDKAppInviteContent alloc] init];
content.appInvitePreviewImageURL = [RCTConvert NSURL:RCTNilIfNull(contentData[@"previewImageUrl"])];
content.appLinkURL = [RCTConvert NSURL:contentData[@"applinkUrl"]];
content.promotionCode = [RCTConvert NSString:RCTNilIfNull(contentData[@"promotionCode"])];
content.promotionText = [RCTConvert NSString:RCTNilIfNull(contentData[@"promotionText"])];
return content;
}

Expand Down Expand Up @@ -68,7 +66,7 @@ - (instancetype)init

RCT_EXPORT_METHOD(canShow:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
{
resolve(@([_dialog canShow]));
resolve([NSNumber numberWithBool:[_dialog canShow]]);
}

RCT_EXPORT_METHOD(show:(FBSDKAppInviteContent *)content
Expand Down
Loading

0 comments on commit a5bf87c

Please sign in to comment.