-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
179 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
{ | ||
"presets": [ | ||
"react-native" | ||
"react-native", | ||
"flow" | ||
], | ||
"plugins": [ | ||
"transform-decorators-legacy" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,104 @@ | ||
// @flow | ||
|
||
import React from 'react' | ||
import { AppRegistry, Text, View } from 'react-native' | ||
import { LoginManager } from 'react-native-fbsdk' | ||
import { observable } from 'mobx' | ||
import { observer } from 'mobx-react/native' | ||
import React from 'react'; | ||
import { AppRegistry, Text, View } from 'react-native'; | ||
import { LoginManager, GraphRequest, GraphRequestManager } from 'react-native-fbsdk'; | ||
import { observable } from 'mobx'; | ||
import { observer } from 'mobx-react/native'; | ||
|
||
// class AuthState { | ||
// @observable isAuthed = false; | ||
// } | ||
import {Actions, Scene, Router, ActionConst} from 'react-native-router-flux'; | ||
|
||
// const authState = observable({ | ||
// isAuthed: false, | ||
// }) | ||
|
||
// const authState = new AuthState(); | ||
const scenes = Actions.create( | ||
<Scene key="root"> | ||
<Scene key="loading" component={Loading} initial={true} type={ActionConst.REPLACE}/> | ||
<Scene key="auth" component={Auth} title="ログイン" type={ActionConst.REPLACE}/> | ||
<Scene key="home" component={Home} title="Home" type={ActionConst.REPLACE} /> | ||
</Scene> | ||
); | ||
|
||
const authState = observable({ | ||
isAuthed: false, | ||
}) | ||
}); | ||
|
||
function responseInfoCallback(error, result) { | ||
if (error) { | ||
console.log({ error }); | ||
authState.isAuthed = false; | ||
alert('Error fetching data: ' + error.toString()); | ||
Actions.auth(); | ||
} else { | ||
console.log({ result }); | ||
authState.isAuthed = true; | ||
Actions.home(); | ||
} | ||
} | ||
|
||
|
||
(function initialize() { | ||
const infoRequest = new GraphRequest('/me', null, responseInfoCallback); | ||
new GraphRequestManager().addRequest(infoRequest).start(); | ||
})() | ||
|
||
function facebookAuthAction() { | ||
LoginManager.logInWithReadPermissions(['public_profile']).then((result) => { | ||
LoginManager.logInWithReadPermissions(['public_profile']).then(result => { | ||
if (result.isCancelled) { | ||
console.log('Login was cancelled') | ||
authState.isAuthed = false | ||
console.log('Login was cancelled'); | ||
authState.isAuthed = false; | ||
Actions.auth(); | ||
} else { | ||
console.log('Login was successful with permissions', result) | ||
authState.isAuthed = true | ||
console.log('Login was successful with permissions', result); | ||
authState.isAuthed = true; | ||
Actions.home(); | ||
} | ||
}, (error) => { | ||
console.log(`Login failed with error: ${error}`) | ||
authState.isAuthed = false | ||
}) | ||
}, error => { | ||
console.log(`Login failed with error: ${error}`); | ||
authState.isAuthed = false; | ||
Actions.auth(); | ||
}); | ||
} | ||
|
||
export default function App() { | ||
console.log('authState.isAuthed', authState.isAuthed) | ||
function Auth() { | ||
return ( | ||
<View> | ||
<View style={{ | ||
flex: 1, | ||
justifyContent: 'center', | ||
alignItems: 'center' | ||
}}> | ||
<Text onPress={facebookAuthAction}>Facebookでログイン</Text> | ||
<Text>isAuthed: {authState.isAuthed.toString()}</Text> | ||
</View> | ||
) | ||
); | ||
} | ||
|
||
// const AppState = observer(App); | ||
function Loading() { | ||
return ( | ||
<View style={{ | ||
flex: 1, | ||
justifyContent: 'center', | ||
alignItems: 'center' | ||
}}> | ||
<Text>読み込み中</Text> | ||
</View> | ||
); | ||
} | ||
|
||
function Home() { | ||
return ( | ||
<View style={{ | ||
flex: 1, | ||
justifyContent: 'center', | ||
alignItems: 'center' | ||
}}> | ||
<Text>ホーム画面</Text> | ||
</View> | ||
); | ||
} | ||
|
||
function App() { | ||
return ( | ||
<Router scenes={scenes} style={{ | ||
backgroundColor: '#00ff77' | ||
}} /> | ||
) | ||
} | ||
|
||
AppRegistry.registerComponent('reme', () => observer(App)) | ||
AppRegistry.registerComponent('reme', () => observer(App)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters