mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-06 07:47:04 +00:00
Merge pull request #17885 from ifiokjr/react-native-fbsdk
Provide Initial Types for React Native FBSDK
This commit is contained in:
Vendored
+1070
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();
|
||||
@@ -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"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user