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.6.1
Browse files Browse the repository at this point in the history
  • Loading branch information
dzhuowen committed Jun 16, 2017
1 parent a5bf87c commit f27d028
Show file tree
Hide file tree
Showing 19 changed files with 127 additions and 54 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 for Apps](https://developers.facebook.com/docs/app-events)
### [Analytics](https://developers.facebook.com/docs/app-events)
#### App events
```js
const FBSDK = require('react-native-fbsdk');
Expand Down
8 changes: 2 additions & 6 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 23
compileSdkVersion 25
buildToolsVersion "23.0.1"

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

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.0'
compile 'com.android.support:appcompat-v7:25.0.0'
compile 'com.facebook.react:react-native:+' // support react-native-v0.22-rc+
compile('com.facebook.android:facebook-android-sdk:4.22.1')
}
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,23 @@ 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 @@ -186,4 +196,13 @@ public void logPurchase(double purchaseAmount, String currencyCode, @Nullable Re
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.5.1";
public static final String VERSION_TO_RELEASE = "ReactNative-v0.6.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,10 +78,12 @@ 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 @@ -111,6 +113,11 @@ 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 @@ -119,12 +126,10 @@ 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 @@ -183,7 +188,6 @@ 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 @@ -231,7 +235,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
10 changes: 10 additions & 0 deletions ios/RCTFBSDK/core/RCTFBSDKAppEvents.m
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ - (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 @@ -70,4 +75,9 @@ - (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.5.1"];
[FBSDKSettings setUserAgentSuffix:@"ReactNative-v0.6.1"];
}
return self;
}
Expand Down
3 changes: 0 additions & 3 deletions ios/RCTFBSDK/share/RCTConvert+FBSDKSharingContent.m
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,6 @@ 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: 3 additions & 1 deletion ios/RCTFBSDK/share/RCTFBSDKAppInviteDialog.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ + (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 @@ -66,7 +68,7 @@ - (instancetype)init

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

RCT_EXPORT_METHOD(show:(FBSDKAppInviteContent *)content
Expand Down
24 changes: 24 additions & 0 deletions js/FBAppEventsLogger.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,34 @@ module.exports = {
AppEventsLogger.logPurchase(purchaseAmount, currencyCode, parameters);
},

/**
* Logs an app event that tracks that the application was open via Push Notification.
*/
logPushNotificationOpen(payload: ?Object) {
AppEventsLogger.logPushNotificationOpen(payload);
},

/**
* Explicitly kicks off flushing of events to Facebook.
*/
flush() {
AppEventsLogger.flush();
},

/**
* For iOS only, sets and sends device token to register the current application for push notifications.
* @platform ios
*/
setPushNotificationsDeviceToken(deviceToken: string) {
AppEventsLogger.setPushNotificationsDeviceToken(deviceToken);
},

/**
* For Android only, sets and sends registration id to register the current app for push notifications.
* @platform Android
*/
setPushNotificationsRegistrationId(registrationId: string) {
AppEventsLogger.setPushNotificationsRegistrationId(registrationId);
},

};
11 changes: 6 additions & 5 deletions js/FBLikeView.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,12 @@
*/
'use strict';

import React, {
PropTypes,
} from 'react';
import PropTypes from 'prop-types';
import React from 'react';
import {
requireNativeComponent,
StyleSheet,
View,
ViewPropTypes,
} from 'react-native';

import type { ObjectIdAndType } from './models/FBObjectIdAndType';
Expand Down Expand Up @@ -92,8 +91,10 @@ class LikeView extends React.Component {
}
}

/* $FlowFixMe(>=0.43.0) - Remove this comment to see errors found when Flow
* v0.43.0 was deployed */
LikeView.propTypes = {
...View.propTypes,
...ViewPropTypes,
objectIdAndType: PropTypes.object.isRequired,
likeViewStyle: PropTypes.oneOf(['standard', 'button', 'box_count']),
auxiliaryViewPosition: PropTypes.oneOf(['top', 'bottom', 'inline']),
Expand Down
13 changes: 7 additions & 6 deletions js/FBLoginButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,12 @@
*/
'use strict';

import React, {
PropTypes,
} from 'react';
import PropTypes from 'prop-types';
import React from 'react';
import {
requireNativeComponent,
StyleSheet,
View,
ViewPropTypes,
} from 'react-native';

import type {
Expand Down Expand Up @@ -123,8 +122,10 @@ class LoginButton extends React.Component {
}
}

/* $FlowFixMe(>=0.43.0) - Remove this comment to see errors found when Flow
* v0.43.0 was deployed */
LoginButton.propTypes = {
...View.propTypes,
...ViewPropTypes,
readPermissions: PropTypes.arrayOf(PropTypes.string),
publishPermissions: PropTypes.arrayOf(PropTypes.string),
onLoginFinished: PropTypes.func,
Expand All @@ -138,7 +139,7 @@ LoginButton.propTypes = {
const styles = StyleSheet.create({
defaultButtonStyle: {
height: 30,
width: 180,
width: 190,
},
});

Expand Down
11 changes: 6 additions & 5 deletions js/FBSendButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,12 @@
*/
'use strict';

import React, {
PropTypes,
} from 'react';
import PropTypes from 'prop-types';
import React from 'react';
import {
requireNativeComponent,
StyleSheet,
View,
ViewPropTypes,
} from 'react-native';

import type { ShareContent } from './models/FBShareContent';
Expand Down Expand Up @@ -58,8 +57,10 @@ class SendButton extends React.Component {
}
}

/* $FlowFixMe(>=0.43.0) - Remove this comment to see errors found when Flow
* v0.43.0 was deployed */
SendButton.propTypes = {
...View.propTypes,
...ViewPropTypes,
shareContent: PropTypes.object,
};

Expand Down
11 changes: 6 additions & 5 deletions js/FBShareButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,12 @@

'use strict';

import React, {
PropTypes,
} from 'react';
import PropTypes from 'prop-types';
import React from 'react';
import {
requireNativeComponent,
StyleSheet,
View,
ViewPropTypes,
} from 'react-native';

import type { ShareContent } from './models/FBShareContent';
Expand Down Expand Up @@ -59,8 +58,10 @@ class ShareButton extends React.Component {
}
}

/* $FlowFixMe(>=0.43.0) - Remove this comment to see errors found when Flow
* v0.43.0 was deployed */
ShareButton.propTypes = {
...View.propTypes,
...ViewPropTypes,
shareContent: PropTypes.object,
};

Expand Down
12 changes: 12 additions & 0 deletions js/models/FBAppInviteContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,16 @@ export type AppInviteContent = {
* An app link target that will be used as a target when the user accepts the invite.
*/
applinkUrl: string,
/**
* Promotional code to be displayed while sending and receiving the invite.
* This is optional. This can be between 0 and 10 characters long and can contain
* alphanumeric characters only. To set a promo code, you need to set promo text.
*/
promotionCode?:string,
/**
* Promotional text to be displayed while sending and receiving the invite.
* This is optional. This can be between 0 and 80 characters long and can contain
* alphanumeric and spaces only.
*/
promotionText?:string,
};
Loading

3 comments on commit f27d028

@joncursi
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After upgrading from 0.5.1 to 0.6.1, android login is broken. I'm getting undefined is not a function. Are there breaking changes here?

@pixelpax
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joncursi I do think it's this version with breaking changes. Going from working install in 0.6.0 to getting the following in 0.6.1:

rnpm-install ERR! Something went wrong while linking. Error: Expected "/*", "//", or "{" but "<" found.
Please file an issue here: https://github.com/facebook/react-native/issues

@fabriziomoscon
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will leave it here as a reference:
facebook/react-native#10032

It seems that this changes trigger an error with react-native link

Please sign in to comment.