Skip to content

Commit 0537012

Browse files
author
Chris Hackmann
committed
Initial commit of v0.0.1
0 parents  commit 0537012

File tree

102 files changed

+6688
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+6688
-0
lines changed

LICENSE.txt

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
2+
3+
You are hereby granted a non-exclusive, worldwide, royalty-free license to use,
4+
copy, modify, and distribute this software in source code or binary form for use
5+
in connection with the web services and APIs provided by Facebook.
6+
7+
As with any software that integrates with the Facebook platform, your use of
8+
this software is subject to the Facebook Developer Principles and Policies
9+
[http://developers.facebook.com/policy/]. This copyright notice shall be
10+
included in all copies or substantial portions of the software.
11+
12+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
14+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
15+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
16+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
17+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# React Native FBSDK
2+
React Native FBSDK is a wrapper around the iOS Facebook SDK, allowing for Facebook integration in [React Native](https://facebook.github.io/react-native/) apps. Access to native components, from login to sharing, is provided entirely through documented JavaScript modules so you never have to call a single native function directly.
3+
4+
Functionality is provided through three separate npm packages so you never have to include more than you need:
5+
- `react-native-fbsdkcore`
6+
- `react-native-fbsdkshare`
7+
- `react-native-fbsdklogin`
8+
9+
## Running the Sample App
10+
- From the Sample folder, run `npm install`
11+
- Download and install the [Facebook SDK for iOS](https://developers.facebook.com/docs/ios).
12+
- Open NHSample.xcodeproj
13+
- Drag `FBSDKCoreKit.framework`, `FBSDKLoginKit.framework`, and `FBSDKShareKit.framework` into the Frameworks group in the XCode project navigator.
14+
- Build and run the app to try it out.
15+
16+
## Installation
17+
- Download and install the [Facebook SDK for iOS](https://developers.facebook.com/docs/ios).
18+
- Follow the [getting started guide](https://developers.facebook.com/docs/ios/getting-started/) to link your project with the Facebook SDK frameworks and set up the app delegate.
19+
- Depending on what functionality you're looking to integrate, run any combination of the following:
20+
- `npm install react-native-fbsdkcore` for graph requests, app events, etc.
21+
- `npm install react-native-fbsdkshare` for share buttons, dialogs, etc.
22+
- `npm install react-native-fbsdklogin` for login button and manager.
23+
- Open the Xcode project for your app.
24+
- Drag the folders prefixed with react-native-fbsdk from node_modules into the XCode project navigator.
25+
26+
## License
27+
See the LICENSE file.
28+
29+
## Platform Policy
30+
Developers looking to integrate with the Facebook Platform should familiarize themselves with the [Facebook Platform Policy](https://developers.facebook.com/policy/).

Sample/Feed.js

+131
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
/**
2+
* Copyright (c) 2015-present, Facebook, Inc. All rights reserved.
3+
*
4+
* You are hereby granted a non-exclusive, worldwide, royalty-free license to use,
5+
* copy, modify, and distribute this software in source code or binary form for use
6+
* in connection with the web services and APIs provided by Facebook.
7+
*
8+
* As with any software that integrates with the Facebook platform, your use of
9+
* this software is subject to the Facebook Developer Principles and Policies
10+
* [http://developers.facebook.com/policy/]. This copyright notice shall be
11+
* included in all copies or substantial portions of the software.
12+
*
13+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15+
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16+
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17+
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19+
*/
20+
21+
'use strict';
22+
23+
var React = require('react-native');
24+
var {
25+
StyleSheet,
26+
Image,
27+
Text,
28+
View,
29+
ScrollView,
30+
PixelRatio,
31+
TouchableHighlight,
32+
} = React;
33+
34+
var FBSDKCore = require('react-native-fbsdkcore');
35+
var {
36+
FBSDKGraphRequest,
37+
} = FBSDKCore;
38+
39+
var FBSDKShare = require('react-native-fbsdkshare');
40+
var {
41+
FBSDKShareDialog,
42+
FBSDKShareLinkContent,
43+
} = FBSDKShare;
44+
45+
var ImageWidth = 150;
46+
47+
class Feed extends React.Component {
48+
constructor() {
49+
super();
50+
51+
// Make a graph request to get photos from the New Horizons Facebook page.
52+
var feedRequest = new FBSDKGraphRequest(
53+
this._handleRequest.bind(this),
54+
'/495164637280739/photos',
55+
{
56+
type: { string: 'uploaded' },
57+
fields: { string: 'images' }
58+
}
59+
);
60+
feedRequest.start();
61+
62+
this.state = {
63+
photos: [],
64+
};
65+
}
66+
67+
render() {
68+
return (
69+
<ScrollView style={this.props.style}>
70+
{this.state.photos}
71+
</ScrollView>
72+
);
73+
}
74+
75+
_renderPhoto(photo) {
76+
var height = ImageWidth * (photo.height / photo.width);
77+
return (
78+
<View style={styles.imageBox}>
79+
<Image source={{uri: photo.source}} style={{
80+
width: ImageWidth * PixelRatio.get(),
81+
height: height * PixelRatio.get(),
82+
}}
83+
/>
84+
<TouchableHighlight
85+
style={[styles.shareButton, { width: ImageWidth * PixelRatio.get(), height: 25 * PixelRatio.get()}]}
86+
onPress={() => this._sharePhoto.bind(this)(photo)}>
87+
<Text style={styles.shareText}>share</Text>
88+
</TouchableHighlight>
89+
</View>
90+
);
91+
}
92+
93+
/**
94+
* Shares a photo to Facebook using the native share dialog.
95+
*/
96+
_sharePhoto(photo) {
97+
// Build up a shareable link to the photo.
98+
var linkContent = new FBSDKShareLinkContent(photo.source, 'A picture from New Horizons.', 'New Horizons', photo.source);
99+
// Share the link using the native share dialog.
100+
FBSDKShareDialog.show(linkContent, (error, result) => {
101+
if (!error) {
102+
if (result.isCancelled) {
103+
alert('So sad, you canceled. :(');
104+
} else {
105+
alert('You shared Pluto!');
106+
}
107+
}
108+
});
109+
}
110+
111+
/**
112+
* Handles the response from the graph request for New Horizons pictures.
113+
*/
114+
_handleRequest(error, result) {
115+
if (!error) {
116+
var photos = result.data;
117+
var renderedPhotos = [];
118+
for (var i = 0, il = photos.length; i < il; i++) {
119+
var photo = photos[i];
120+
if (photo.images && photo.images.length > 0) {
121+
renderedPhotos.push(this._renderPhoto(photo.images[0]));
122+
}
123+
}
124+
this.setState({ photos: renderedPhotos });
125+
}
126+
}
127+
}
128+
129+
var styles = StyleSheet.create(require('./styles.js'));
130+
131+
module.exports = Feed;

Sample/Login.js

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/**
2+
* Copyright (c) 2015-present, Facebook, Inc. All rights reserved.
3+
*
4+
* You are hereby granted a non-exclusive, worldwide, royalty-free license to use,
5+
* copy, modify, and distribute this software in source code or binary form for use
6+
* in connection with the web services and APIs provided by Facebook.
7+
*
8+
* As with any software that integrates with the Facebook platform, your use of
9+
* this software is subject to the Facebook Developer Principles and Policies
10+
* [http://developers.facebook.com/policy/]. This copyright notice shall be
11+
* included in all copies or substantial portions of the software.
12+
*
13+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15+
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16+
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17+
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19+
*/
20+
21+
'use strict';
22+
23+
var React = require('react-native');
24+
var {
25+
StyleSheet,
26+
View,
27+
} = React;
28+
29+
var FBSDKLogin = require('react-native-fbsdklogin');
30+
var {
31+
FBSDKLoginButton,
32+
} = FBSDKLogin;
33+
34+
var Login = React.createClass({
35+
render: function() {
36+
return (
37+
<View style={this.props.style}>
38+
<FBSDKLoginButton
39+
style={styles.loginButton}
40+
onLoginFinished={(error, result) => {
41+
if (error) {
42+
alert('Error logging in.');
43+
} else {
44+
if (result.isCanceled) {
45+
alert('Login cancelled.');
46+
} else {
47+
alert('Logged in.');
48+
}
49+
}
50+
}}
51+
onLogoutFinished={() => alert('Logged out.')}
52+
readPermissions={[]}
53+
publishPermissions={['publish_actions']}/>
54+
</View>
55+
);
56+
}
57+
});
58+
59+
var styles = StyleSheet.create(require('./styles.js'));
60+
61+
module.exports = Login;

0 commit comments

Comments
 (0)