Skip to content

Commit

Permalink
Update scene controll for auth
Browse files Browse the repository at this point in the history
  • Loading branch information
snghrsw committed Mar 28, 2017
1 parent 614cb8b commit a05090c
Show file tree
Hide file tree
Showing 5 changed files with 179 additions and 38 deletions.
3 changes: 2 additions & 1 deletion .babelrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"presets": [
"react-native"
"react-native",
"flow"
],
"plugins": [
"transform-decorators-legacy"
Expand Down
4 changes: 2 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module.exports = {
commonjs: true,
es6: true,
},
extends: ['eslint:recommended', 'airbnb'],
extends: ['eslint:recommended', 'flowtype/recommended', 'airbnb'],
parserOptions: {
ecmaFeatures: {
ecmaVersion: 7,
Expand All @@ -13,7 +13,7 @@ module.exports = {
},
sourceType: 'module',
},
plugins: ['react'],
plugins: ['react', 'flowtype'],
rules: {
indent: ['error', 2],
'linebreak-style': ['error', 'unix'],
Expand Down
114 changes: 84 additions & 30 deletions index.android.js
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));
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,24 @@
"react": "~15.4.1",
"react-native": "0.42.3",
"react-native-fbsdk": "^0.5.0",
"react-native-router-flux": "^3.38.0",
"react-native-simple-auth": "^2.0.0",
"start": "^5.1.0"
},
"devDependencies": {
"@types/react-native": "^0.42.12",
"babel-eslint": "^7.2.1",
"babel-jest": "19.0.0",
"babel-plugin-transform-react-jsx-source": "^6.22.0",
"babel-preset-flow": "^6.23.0",
"babel-preset-react-native": "1.9.1",
"eslint": "^3.18.0",
"eslint-config-airbnb": "^14.1.0",
"eslint-plugin-flowtype": "^2.30.4",
"eslint-plugin-import": "^2.2.0",
"eslint-plugin-jsx-a11y": "^4.0.0",
"eslint-plugin-react": "^6.10.3",
"flow-remove-types": "^1.2.0",
"jest": "19.0.2",
"react-test-renderer": "~15.4.1"
},
Expand Down
90 changes: 85 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@
# yarn lockfile v1


"@types/react-native@^0.42.12":
version "0.42.12"
resolved "https://registry.yarnpkg.com/@types/react-native/-/react-native-0.42.12.tgz#1b07913e9398fd73dfa5c2544e6717fe772dd3bf"
dependencies:
"@types/react" "*"

"@types/react@*":
version "15.0.20"
resolved "https://registry.yarnpkg.com/@types/react/-/react-15.0.20.tgz#3d4a05ed04a8b1847ac6c8fa6093591d3910fba5"

abab@^1.0.3:
version "1.0.3"
resolved "https://registry.yarnpkg.com/abab/-/abab-1.0.3.tgz#b81de5f7274ec4e756d797cd834f303642724e5d"
Expand Down Expand Up @@ -254,6 +264,15 @@ babel-core@^6.0.0, babel-core@^6.21.0, babel-core@^6.24.0, babel-core@^6.7.2:
slash "^1.0.0"
source-map "^0.5.0"

babel-eslint@^7.2.1:
version "7.2.1"
resolved "https://registry.yarnpkg.com/babel-eslint/-/babel-eslint-7.2.1.tgz#079422eb73ba811e3ca0865ce87af29327f8c52f"
dependencies:
babel-code-frame "^6.22.0"
babel-traverse "^6.23.1"
babel-types "^6.23.0"
babylon "^6.16.1"

babel-generator@^6.18.0, babel-generator@^6.21.0, babel-generator@^6.24.0:
version "6.24.0"
resolved "https://registry.yarnpkg.com/babel-generator/-/babel-generator-6.24.0.tgz#eba270a8cc4ce6e09a61be43465d7c62c1f87c56"
Expand Down Expand Up @@ -716,7 +735,7 @@ babel-plugin-transform-export-extensions@^6.22.0:
babel-plugin-syntax-export-extensions "^6.8.0"
babel-runtime "^6.22.0"

babel-plugin-transform-flow-strip-types@^6.21.0, babel-plugin-transform-flow-strip-types@^6.5.0, babel-plugin-transform-flow-strip-types@^6.7.0, babel-plugin-transform-flow-strip-types@^6.8.0:
babel-plugin-transform-flow-strip-types@^6.21.0, babel-plugin-transform-flow-strip-types@^6.22.0, babel-plugin-transform-flow-strip-types@^6.5.0, babel-plugin-transform-flow-strip-types@^6.7.0, babel-plugin-transform-flow-strip-types@^6.8.0:
version "6.22.0"
resolved "https://registry.yarnpkg.com/babel-plugin-transform-flow-strip-types/-/babel-plugin-transform-flow-strip-types-6.22.0.tgz#84cb672935d43714fdc32bce84568d87441cf7cf"
dependencies:
Expand Down Expand Up @@ -861,13 +880,19 @@ babel-preset-fbjs@^2.1.0:
babel-plugin-transform-react-display-name "^6.8.0"
babel-plugin-transform-react-jsx "^6.8.0"

babel-preset-flow@^6.23.0:
version "6.23.0"
resolved "https://registry.yarnpkg.com/babel-preset-flow/-/babel-preset-flow-6.23.0.tgz#e71218887085ae9a24b5be4169affb599816c49d"
dependencies:
babel-plugin-transform-flow-strip-types "^6.22.0"

babel-preset-jest@^19.0.0:
version "19.0.0"
resolved "https://registry.yarnpkg.com/babel-preset-jest/-/babel-preset-jest-19.0.0.tgz#22d67201d02324a195811288eb38294bb3cac396"
dependencies:
babel-plugin-jest-hoist "^19.0.0"

babel-preset-react-native@1.9.1, babel-preset-react-native@^1.9.1:
babel-preset-react-native@1.9.1, babel-preset-react-native@^1.9.0, babel-preset-react-native@^1.9.1:
version "1.9.1"
resolved "https://registry.yarnpkg.com/babel-preset-react-native/-/babel-preset-react-native-1.9.1.tgz#ec8e378274410d78f550fa9f8edd70353f3bb2fe"
dependencies:
Expand Down Expand Up @@ -988,7 +1013,7 @@ babel-types@^6.18.0, babel-types@^6.19.0, babel-types@^6.21.0, babel-types@^6.22
lodash "^4.2.0"
to-fast-properties "^1.0.1"

babylon@^6.11.0, babylon@^6.13.0, babylon@^6.14.1, babylon@^6.15.0:
babylon@^6.11.0, babylon@^6.13.0, babylon@^6.14.1, babylon@^6.15.0, babylon@^6.16.1:
version "6.16.1"
resolved "https://registry.yarnpkg.com/babylon/-/babylon-6.16.1.tgz#30c5a22f481978a9e7f8cdfdf496b11d94b404d3"

Expand Down Expand Up @@ -1167,6 +1192,10 @@ circular-json@^0.3.1:
version "0.3.1"
resolved "https://registry.yarnpkg.com/circular-json/-/circular-json-0.3.1.tgz#be8b36aefccde8b3ca7aa2d6afc07a37242c0d2d"

clamp@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/clamp/-/clamp-1.0.1.tgz#66a0e64011816e37196828fdc8c8c147312c8634"

cli-cursor@^1.0.1:
version "1.0.2"
resolved "https://registry.yarnpkg.com/cli-cursor/-/cli-cursor-1.0.2.tgz#64da3f7d56a54412e59794bd62dc35295e8f2987"
Expand Down Expand Up @@ -1680,6 +1709,12 @@ eslint-module-utils@^2.0.0:
debug "2.2.0"
pkg-dir "^1.0.0"

eslint-plugin-flowtype@^2.30.4:
version "2.30.4"
resolved "https://registry.yarnpkg.com/eslint-plugin-flowtype/-/eslint-plugin-flowtype-2.30.4.tgz#771d6bb4578ab8598e9c58018fea2e1a22946249"
dependencies:
lodash "^4.15.0"

eslint-plugin-import@^2.2.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/eslint-plugin-import/-/eslint-plugin-import-2.2.0.tgz#72ba306fad305d67c4816348a4699a4229ac8b4e"
Expand Down Expand Up @@ -1901,7 +1936,7 @@ fbjs-scripts@^0.7.0:
semver "^5.1.0"
through2 "^2.0.0"

fbjs@^0.8.4, fbjs@^0.8.5:
fbjs@^0.8.1, fbjs@^0.8.4, fbjs@^0.8.5:
version "0.8.11"
resolved "https://registry.yarnpkg.com/fbjs/-/fbjs-0.8.11.tgz#340b590b8a2278a01ef7467c07a16da9b753db24"
dependencies:
Expand Down Expand Up @@ -1979,6 +2014,13 @@ flat-cache@^1.2.1:
graceful-fs "^4.1.2"
write "^0.2.1"

flow-remove-types@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/flow-remove-types/-/flow-remove-types-1.2.0.tgz#c285516eabba72177a1b10bfb58f6ffb675a8877"
dependencies:
babylon "^6.15.0"
vlq "^0.2.1"

for-in@^1.0.1:
version "1.0.2"
resolved "https://registry.yarnpkg.com/for-in/-/for-in-1.0.2.tgz#81068d295a8142ec0ac726c6e2200c30fb6d5e80"
Expand Down Expand Up @@ -3047,7 +3089,7 @@ lodash@^3.5.0:
version "3.10.1"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-3.10.1.tgz#5bf45e8e49ba4189e17d482789dfd15bd140b7b6"

lodash@^4.0.0, lodash@^4.14.0, lodash@^4.16.6, lodash@^4.2.0, lodash@^4.3.0, lodash@^4.6.1:
lodash@^4.0.0, lodash@^4.14.0, lodash@^4.15.0, lodash@^4.16.6, lodash@^4.2.0, lodash@^4.3.0, lodash@^4.6.1:
version "4.17.4"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae"

Expand Down Expand Up @@ -3580,6 +3622,13 @@ raw-body@~2.1.2:
iconv-lite "0.4.13"
unpipe "1.0.0"

react-addons-pure-render-mixin@^15.0.2:
version "15.4.2"
resolved "https://registry.yarnpkg.com/react-addons-pure-render-mixin/-/react-addons-pure-render-mixin-15.4.2.tgz#a8433c71c45e2368503721921dc47bdaf1fbabcd"
dependencies:
fbjs "^0.8.4"
object-assign "^4.1.0"

react-clone-referenced-element@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/react-clone-referenced-element/-/react-clone-referenced-element-1.0.1.tgz#2bba8c69404c5e4a944398600bcc4c941f860682"
Expand All @@ -3588,10 +3637,29 @@ react-deep-force-update@^1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/react-deep-force-update/-/react-deep-force-update-1.0.1.tgz#f911b5be1d2a6fe387507dd6e9a767aa2924b4c7"

react-native-experimental-navigation@0.26.x:
version "0.26.10"
resolved "https://registry.yarnpkg.com/react-native-experimental-navigation/-/react-native-experimental-navigation-0.26.10.tgz#355e37929a2bfb84088dca331f34bc575297df68"
dependencies:
babel-plugin-syntax-flow "^6.8.0"
babel-plugin-transform-flow-strip-types "^6.8.0"
babel-preset-react-native "^1.9.0"
clamp "^1.0.1"
fbjs "^0.8.1"
react-addons-pure-render-mixin "^15.0.2"

react-native-fbsdk@^0.5.0:
version "0.5.0"
resolved "https://registry.yarnpkg.com/react-native-fbsdk/-/react-native-fbsdk-0.5.0.tgz#3ccd67d189755df11d366b8de9acb91ea2300e6e"

react-native-router-flux@^3.38.0:
version "3.38.0"
resolved "https://registry.yarnpkg.com/react-native-router-flux/-/react-native-router-flux-3.38.0.tgz#f5f8ec2875b46f96f61006ff502d0d80268e6ce2"
dependencies:
react-native-experimental-navigation "0.26.x"
react-native-tabs "^1.0.9"
react-static-container "1.0.1"

react-native-simple-auth@^2.0.0:
version "2.0.1"
resolved "https://registry.yarnpkg.com/react-native-simple-auth/-/react-native-simple-auth-2.0.1.tgz#faf26f5c81257ed58e6f0ce33847ce59c694f2ea"
Expand All @@ -3602,6 +3670,10 @@ react-native-simple-auth@^2.0.0:
hmacsha1 "^1.0.0"
ramda "^0.22.1"

react-native-tabs@^1.0.9:
version "1.0.9"
resolved "https://registry.yarnpkg.com/react-native-tabs/-/react-native-tabs-1.0.9.tgz#75d3c35e8b5b6970869eab282372cb32e2a782cd"

react-native@0.42.3:
version "0.42.3"
resolved "https://registry.yarnpkg.com/react-native/-/react-native-0.42.3.tgz#450c8a03a5e3e991a08a426f22776dd8feb80b26"
Expand Down Expand Up @@ -3689,6 +3761,10 @@ react-proxy@^1.1.7:
lodash "^4.6.1"
react-deep-force-update "^1.0.0"

react-static-container@1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/react-static-container/-/react-static-container-1.0.1.tgz#694c0dd68a896b879519afb548399cc1989c9ab0"

react-test-renderer@~15.4.1:
version "15.4.2"
resolved "https://registry.yarnpkg.com/react-test-renderer/-/react-test-renderer-15.4.2.tgz#27e1dff5d26d0e830f99614c487622bc831416f3"
Expand Down Expand Up @@ -4422,6 +4498,10 @@ vinyl@^0.5.0:
clone-stats "^0.0.1"
replace-ext "0.0.1"

vlq@^0.2.1:
version "0.2.1"
resolved "https://registry.yarnpkg.com/vlq/-/vlq-0.2.1.tgz#14439d711891e682535467f8587c5630e4222a6c"

walker@~1.0.5:
version "1.0.7"
resolved "https://registry.yarnpkg.com/walker/-/walker-1.0.7.tgz#2f7f9b8fd10d677262b18a884e28d19618e028fb"
Expand Down

0 comments on commit a05090c

Please sign in to comment.