Skip to content

Commit

Permalink
Add RN056 example. Closes #151
Browse files Browse the repository at this point in the history
  • Loading branch information
jpgarcia committed Sep 17, 2018
1 parent e5b5048 commit 5b3536e
Show file tree
Hide file tree
Showing 55 changed files with 8,558 additions and 0 deletions.
3 changes: 3 additions & 0 deletions examples/RN056/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": ["react-native"]
}
6 changes: 6 additions & 0 deletions examples/RN056/.buckconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

[android]
target = Google Inc.:Google APIs:23

[maven_repositories]
central = https://repo1.maven.org/maven2
67 changes: 67 additions & 0 deletions examples/RN056/.flowconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
[ignore]
; We fork some components by platform
.*/*[.]android.js

; Ignore "BUCK" generated dirs
<PROJECT_ROOT>/\.buckd/

; Ignore unexpected extra "@providesModule"
.*/node_modules/.*/node_modules/fbjs/.*

; Ignore duplicate module providers
; For RN Apps installed via npm, "Libraries" folder is inside
; "node_modules/react-native" but in the source repo it is in the root
.*/Libraries/react-native/React.js

; Ignore polyfills
.*/Libraries/polyfills/.*

; Ignore metro
.*/node_modules/metro/.*

[include]

[libs]
node_modules/react-native/Libraries/react-native/react-native-interface.js
node_modules/react-native/flow/
node_modules/react-native/flow-github/

[options]
emoji=true

module.system=haste
module.system.haste.use_name_reducers=true
# get basename
module.system.haste.name_reducers='^.*/\([a-zA-Z0-9$_.-]+\.js\(\.flow\)?\)$' -> '\1'
# strip .js or .js.flow suffix
module.system.haste.name_reducers='^\(.*\)\.js\(\.flow\)?$' -> '\1'
# strip .ios suffix
module.system.haste.name_reducers='^\(.*\)\.ios$' -> '\1'
module.system.haste.name_reducers='^\(.*\)\.android$' -> '\1'
module.system.haste.name_reducers='^\(.*\)\.native$' -> '\1'
module.system.haste.paths.blacklist=.*/__tests__/.*
module.system.haste.paths.blacklist=.*/__mocks__/.*
module.system.haste.paths.blacklist=<PROJECT_ROOT>/node_modules/react-native/Libraries/Animated/src/polyfills/.*
module.system.haste.paths.whitelist=<PROJECT_ROOT>/node_modules/react-native/Libraries/.*

munge_underscores=true

module.name_mapper='^[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> 'RelativeImageStub'

module.file_ext=.js
module.file_ext=.jsx
module.file_ext=.json
module.file_ext=.native.js

suppress_type=$FlowIssue
suppress_type=$FlowFixMe
suppress_type=$FlowFixMeProps
suppress_type=$FlowFixMeState

suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(<VERSION>\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)
suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(<VERSION>\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)?:? #[0-9]+
suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy
suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError

[version]
^0.75.0
1 change: 1 addition & 0 deletions examples/RN056/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.pbxproj -text
59 changes: 59 additions & 0 deletions examples/RN056/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# OSX
#
.DS_Store

# Xcode
#
build/
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata
*.xccheckout
*.moved-aside
DerivedData
*.hmap
*.ipa
*.xcuserstate
project.xcworkspace

# Android/IntelliJ
#
build/
.idea
.gradle
local.properties
*.iml

# node.js
#
node_modules/
npm-debug.log
yarn-error.log

# BUCK
buck-out/
\.buckd/
*.keystore

# fastlane
#
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
# screenshots whenever they are needed.
# For more information about the recommended setup visit:
# https://docs.fastlane.tools/best-practices/source-control/

*/fastlane/report.xml
*/fastlane/Preview.html
*/fastlane/screenshots

# Bundle artifact
*.jsbundle

# CocoaPods
Pods/
1 change: 1 addition & 0 deletions examples/RN056/.watchmanconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
192 changes: 192 additions & 0 deletions examples/RN056/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
import React, { Component } from "react";

import { StyleSheet, Text, View, TouchableOpacity, Switch } from "react-native";

import AccountKit, {
LoginButton,
Color,
StatusBarStyle
} from "react-native-facebook-account-kit";

class AccountKitSample extends Component {
state = {
authToken: null,
loggedAccount: null
};

componentWillMount() {
this.configureAccountKit();

AccountKit.getCurrentAccessToken()
.then(token => {
if (token) {
AccountKit.getCurrentAccount().then(account => {
this.setState({
authToken: token,
loggedAccount: account
});
});
} else {
console.log("No user account logged");
}
})
.catch(e => console.log("Failed to get current access token", e));
}

configureAccountKit() {
AccountKit.configure({
theme: {
//backgroundColor: Color.rgba(0,120,0,0.1),
//buttonBackgroundColor: Color.rgba(0, 153, 0, 1.00),
//buttonDisabledBackgroundColor: Color.rgba(100, 153, 0, 0.5),
//buttonBorderColor: Color.rgba(0,255,0,1),
//buttonTextColor: Color.rgba(0,255,0,1),
//headerBackgroundColor: Color.rgba(0, 153, 0, 1.00),
//headerTextColor: Color.rgba(0,255,0,1),
//headerButtonTextColor: Color.rgba(0,255,0,1),
//iconColor: Color.rgba(0,255,0,1),
//inputBackgroundColor: Color.rgba(0,255,0,1),
//inputBorderColor: Color.hex('#ccc'),
//inputTextColor: Color.hex('#0f0'),
//textColor: Color.hex('#0f0'),
//titleColor: Color.hex('#0f0'),
//backgroundImage: "background.png",
//statusBarStyle: StatusBarStyle.LightContent,
},
//countryWhitelist: [ "AR", "BR", "US" ],
//countryBlacklist: [ "BR" ],
//defaultCountry: "AR"
initialEmail: "example.com",
initialPhoneCountryPrefix: "+355",
initialPhoneNumber: "123-456-7890"
});
}

onLogin(token) {
if (!token) {
console.warn("User canceled login");
this.setState({});
} else {
AccountKit.getCurrentAccount().then(account => {
this.setState({
authToken: token,
loggedAccount: account
});
});
}
}

onLoginError(e) {
console.log("Failed to login", e);
}

onEmailLoginPressed() {
AccountKit.loginWithEmail()
.then(token => {
this.onLogin(token);
})
.catch(e => this.onLoginError(e));
}

onLogoutPressed() {
AccountKit.logout()
.then(() => {
this.setState({
authToken: null,
loggedAccount: null
});
})
.catch(e => console.log("Failed to logout"));
}

renderUserLogged() {
const { id, email, phoneNumber } = this.state.loggedAccount;

return (
<View>
<TouchableOpacity
style={styles.button}
onPress={() => this.onLogoutPressed()}
>
<Text style={styles.buttonText}>Logout</Text>
</TouchableOpacity>

<Text style={styles.label}>Account Kit Id</Text>
<Text style={styles.text}>{id}</Text>
<Text style={styles.label}>Email</Text>
<Text style={styles.text}>{email}</Text>
<Text style={styles.label}>Phone Number</Text>
<Text style={styles.text}>
{phoneNumber
? `${phoneNumber.countryCode} ${phoneNumber.number}`
: ""}
</Text>
</View>
);
}

renderLogin() {
return (
<View>
<LoginButton
style={styles.button}
type="phone"
onLogin={token => this.onLogin(token)}
onError={e => this.onLogin(e)}
>
<Text style={styles.buttonText}>SMS</Text>
</LoginButton>

<TouchableOpacity
style={styles.button}
onPress={() => this.onEmailLoginPressed()}
>
<Text style={styles.buttonText}>Email</Text>
</TouchableOpacity>
</View>
);
}

render() {
return (
<View style={styles.container}>
{this.state.loggedAccount
? this.renderUserLogged()
: this.renderLogin()}
</View>
);
}
}

const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: "center",
alignItems: "center",
backgroundColor: "#F5FCFF"
},
button: {
height: 50,
width: 300,
backgroundColor: "aqua",
marginBottom: 10
},
buttonText: {
fontSize: 20,
textAlign: "center",
margin: 10
},
label: {
fontSize: 20,
textAlign: "center",
fontWeight: "bold",
marginTop: 20
},
text: {
fontSize: 20,
textAlign: "center",
margin: 10
}
});

export default AccountKitSample;
Loading

0 comments on commit 5b3536e

Please sign in to comment.