Merge pull request #17885 from ifiokjr/react-native-fbsdk

Provide Initial Types for React Native FBSDK
This commit is contained in:
Wesley Wigham
2017-07-19 08:17:43 -07:00
committed by GitHub
4 changed files with 1202 additions and 0 deletions
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,107 @@
import * as React from 'react';
import * as FBSDK from 'react-native-fbsdk';
import { View } from 'react-native';
const {
LoginButton,
AccessToken,
LoginManager,
ShareDialog,
AppEventsLogger,
GraphRequest,
GraphRequestManager,
} = FBSDK;
export class Login extends React.Component {
render() {
return (
<View>
<LoginButton
publishPermissions={["publish_actions"]}
onLoginFinished={
(error, result) => {
if (error) {
alert("login has error: " + result.error);
} else if (result.isCancelled) {
alert("login is cancelled.");
} else {
AccessToken.getCurrentAccessToken().then(
(data) => {
if (data) {
alert(data.accessToken.toString());
}
}
);
}
}
}
onLogoutFinished={() => alert("logout.")}
/>
</View>
);
}
}
// Attempt a login using the Facebook login dialog asking for default permissions.
LoginManager.logInWithReadPermissions(['public_profile']).then(
(result) => {
if (result.isCancelled) {
alert('Login cancelled');
} else {
alert(`Login success with permissions: ${result.grantedPermissions}`);
}
},
(error) => {
alert(`Login fail with error: ${error}`);
}
);
// Build up a shareable link.
const shareLinkContent: FBSDK.ShareLinkContent = {
contentType: 'link',
contentUrl: "https://facebook.com",
contentDescription: 'Wow, check out this great site!',
};
// Share the link using the share dialog.
export const shareLinkWithShareDialog = (): void => {
ShareDialog.canShow(shareLinkContent).then(
(canShow) => {
if (canShow) {
return ShareDialog.show(shareLinkContent);
}
}
).then(
(result) => {
if (result.isCancelled) {
alert('Share cancelled');
} else {
alert(`Share success with postId: ${result.postId}`);
}
},
(error: Error) => {
alert(`Share fail with error: ${error}`);
}
);
};
const obj = { param: 'value' };
AppEventsLogger.logPurchase(15, 'USD', obj);
const responseInfoCallback: FBSDK.GraphRequestCallback = (error, result) => {
if (error) {
alert(`Error fetching data: ${error}`);
} else {
alert(`Success fetching data: ${result}`);
}
};
// Create a graph request asking for user information with a callback to handle the response.
const infoRequest = new GraphRequest(
'/me',
null,
responseInfoCallback,
);
// Start the graph request.
new GraphRequestManager().addRequest(infoRequest).start();
+24
View File
@@ -0,0 +1,24 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6",
"dom"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true,
"jsx": "react-native"
},
"files": [
"index.d.ts",
"react-native-fbsdk-tests.tsx"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }