From c4a83421a4cee79b9a8da29790bfba673962c6b4 Mon Sep 17 00:00:00 2001 From: mistikk Date: Mon, 8 Oct 2018 19:18:00 -0400 Subject: [PATCH] Fixed login screen error on android. Moved all route names to constants --- src/config/routes.js | 14 +- src/constants/routeNames.js | 14 ++ src/screens/index.js | 16 +- src/screens/login/screen/loginScreen.js | 159 ++++++++-------- .../pinCode/container/pinCodeContainer.js | 170 ++++++++---------- src/screens/pinCode/index.js | 8 +- .../splash/container/splashContainer.js | 7 +- 7 files changed, 185 insertions(+), 203 deletions(-) create mode 100644 src/constants/routeNames.js diff --git a/src/config/routes.js b/src/config/routes.js index ecd57bf8f..a92b1e883 100644 --- a/src/config/routes.js +++ b/src/config/routes.js @@ -1,15 +1,16 @@ -import { DrawerNavigator, StackNavigator, SwitchNavigator } from 'react-navigation'; +import { DrawerNavigator, SwitchNavigator } from 'react-navigation'; import { BaseNavigator } from '../navigation'; +import { default as ROUTES } from '../constants/routeNames'; // Screens -import { Splash, Login } from '../screens'; +import { Splash, Login, PinCode } from '../screens'; // Components import { SideMenu } from '../components'; const mainNavigation = DrawerNavigator( { - HomeScreen: { + [ROUTES.SCREENS.HOME]: { screen: BaseNavigator, navigationOptions: { header: () => null, @@ -22,7 +23,8 @@ const mainNavigation = DrawerNavigator( ); export default SwitchNavigator({ - Splash: { screen: Splash }, - Login: { screen: Login }, - Main: mainNavigation, + [ROUTES.SCREENS.SPLASH]: { screen: Splash }, + [ROUTES.SCREENS.LOGIN]: { screen: Login }, + [ROUTES.SCREENS.PINCODE]: { screen: PinCode }, + [ROUTES.DRAWER.MAIN]: mainNavigation, }); diff --git a/src/constants/routeNames.js b/src/constants/routeNames.js new file mode 100644 index 000000000..08ba2c339 --- /dev/null +++ b/src/constants/routeNames.js @@ -0,0 +1,14 @@ +const SCREEN_SUFFIX = 'Screen'; +const DRAWER_SUFFIX = 'Drawer'; + +export default { + SCREENS: { + SPLASH: `Splash${SCREEN_SUFFIX}`, + LOGIN: `Login${SCREEN_SUFFIX}`, + PINCODE: `PinCode${SCREEN_SUFFIX}`, + HOME: `Home${SCREEN_SUFFIX}`, + }, + DRAWER: { + MAIN: `Main${DRAWER_SUFFIX}`, + }, +}; diff --git a/src/screens/index.js b/src/screens/index.js index eca5fa996..fb06b2f71 100755 --- a/src/screens/index.js +++ b/src/screens/index.js @@ -1,25 +1,26 @@ -// import Author from './authorProfile'; import Splash from './splash'; -// import SideMenu from './sideMenuScreen'; +import Login from './login'; +import PinCode from './pinCode'; import Home from './home/home'; +// import Author from './authorProfile'; +// import SideMenu from './sideMenuScreen'; // import Hot from './home/hot'; // import Feed from './home/feed'; // import { SinglePost } from './singlePost'; // import { Profile } from './profile'; -import Login from './login'; // import Wallet from './wallet/wallet'; // import Editor from './editor/editor'; // import Discover from './discover/discover'; // import Settings from './settings/settings'; // import { Notification } from './notification'; -// import PinCode from './pinCode/pinCodeContainer'; export { - // Author, Splash, - // SideMenu, - Home, Login, + PinCode, + Home, + // Author, + // SideMenu, // Hot, // Feed, // SinglePost, @@ -29,5 +30,4 @@ export { // Editor, // Discover, // Notification, - // PinCode, }; diff --git a/src/screens/login/screen/loginScreen.js b/src/screens/login/screen/loginScreen.js index 39ee9b3d0..4f2bfe840 100644 --- a/src/screens/login/screen/loginScreen.js +++ b/src/screens/login/screen/loginScreen.js @@ -1,7 +1,5 @@ import React, { Component } from 'react'; -import { - View, BackHandler, Linking, StatusBar, -} from 'react-native'; +import { View, Linking, StatusBar } from 'react-native'; import { KeyboardAwareScrollView } from 'react-native-keyboard-aware-scroll-view'; import ScrollableTabView from '@esteemapp/react-native-scrollable-tab-view'; @@ -20,6 +18,9 @@ import { TabBar } from '../../../components/tabBar'; import { lookupAccounts } from '../../../providers/steem/dsteem'; import STEEM_CONNECT_LOGO from '../../../assets/steem_connect.png'; +// Constants +import { default as ROUTES } from '../../../constants/routeNames'; + // Styles import styles from './loginStyles'; @@ -36,17 +37,6 @@ class LoginScreen extends Component { }; } - componentDidMount() { - BackHandler.addEventListener('hardwareBackPress', () => true); - Linking.getInitialURL().then((url) => { - console.log(url); - }); - } - - componentWillUnmount() { - BackHandler.removeEventListener('hardwareBackPress'); - } - _handleOnPressLogin = () => { const { dispatch, navigation } = this.props; const { password, username } = this.state; @@ -58,12 +48,10 @@ class LoginScreen extends Component { if (result) { dispatch(addNewAccount(result)); dispatch(isLoggedIn(true)); - - // It should go PinCode! (it will) - navigation.navigate('Main'); + navigation.navigate(ROUTES.SCREENS.PINCODE); } }) - .catch((err) => { + .catch(() => { dispatch(isLoggedIn(false)); this.setState({ isLoading: false }); }); @@ -116,79 +104,74 @@ class LoginScreen extends Component { description="To get all the benefits using eSteem" onPress={() => this._handleSignUp()} /> - this.setState({ keyboardIsOpen: true })} - onKeyboardWillHide={() => this.setState({ keyboardIsOpen: false })} + ( + + )} > - ( - - )} - > - - this._handleUsernameChange(value)} - placeholder="Username" - isEditable - type="username" - isFirstImage - value={username} - /> - this._handleOnPasswordChange(value)} - placeholder="Password or WIF" - isEditable - secureTextEntry - type="password" - /> - + this._handleUsernameChange(value)} + placeholder="Username" + isEditable + type="username" + isFirstImage + value={username} + /> + this._handleOnPasswordChange(value)} + placeholder="Password or WIF" + isEditable + secureTextEntry + type="password" + /> + - - navigation.navigate('Main')} text="cancel" /> - - + iconName="ios-information-circle-outline" + /> + + navigation.navigate(ROUTES.DRAWER.MAIN)} text="cancel" /> - - - this._loginwithSc2()} - iconName="md-person" - source={STEEM_CONNECT_LOGO} - text="steem" - secondText="connect" - /> - - - + + + + + this._loginwithSc2()} + iconName="md-person" + source={STEEM_CONNECT_LOGO} + text="steem" + secondText="connect" + /> + + ); } diff --git a/src/screens/pinCode/container/pinCodeContainer.js b/src/screens/pinCode/container/pinCodeContainer.js index a8f191278..bafd9df4f 100644 --- a/src/screens/pinCode/container/pinCodeContainer.js +++ b/src/screens/pinCode/container/pinCodeContainer.js @@ -1,23 +1,21 @@ -import React from "react"; -import { AsyncStorage } from "react-native"; -import { connect } from "react-redux"; -import { Navigation } from "react-native-navigation"; +import React from 'react'; +import { AsyncStorage } from 'react-native'; +import { connect } from 'react-redux'; -import { - setUserDataWithPinCode, - verifyPinCode, -} from "../../../providers/steem/auth"; +import { setUserDataWithPinCode, verifyPinCode } from '../../../providers/steem/auth'; -import { default as INITIAL } from "../../../constants/initial"; +// Constants +import { default as INITIAL } from '../../../constants/initial'; +import { default as ROUTES } from '../../../constants/routeNames'; -import { PinCodeScreen } from "../"; +import { PinCodeScreen } from '..'; class PinCodeContainer extends React.Component { constructor(props) { super(props); this.state = { isExistUser: null, - informationText: "", + informationText: '', pinCode: null, }; } @@ -28,99 +26,81 @@ class PinCodeContainer extends React.Component { const { isExistUser } = this.state; if (isExistUser) { this.setState({ - informationText: "Enter pin to unlock", + informationText: 'Enter pin to unlock', }); } else { this.setState({ - informationText: "Set new pin", + informationText: 'Set new pin', }); } }); } - _getDataFromStorage = () => - new Promise(resolve => { - AsyncStorage.getItem(INITIAL.IS_EXIST_USER, (err, result) => { - this.setState( - { - isExistUser: JSON.parse(result), - }, - resolve - ); - }); + _getDataFromStorage = () => new Promise((resolve) => { + AsyncStorage.getItem(INITIAL.IS_EXIST_USER, (err, result) => { + this.setState( + { + isExistUser: JSON.parse(result), + }, + resolve, + ); }); + }); - _setPinCode = pin => - new Promise((resolve, reject) => { - const { - currentAccount: { password, name }, - componentId, - } = this.props; - const { isExistUser, pinCode } = this.state; - if (isExistUser) { - // If the user is exist, we are just checking to pin and navigating to home screen - const pinData = { - pinCode: pin, - password, - username: name, - }; - verifyPinCode(pinData) - .then(() => { - Navigation.setStackRoot(componentId, { - component: { - name: "navigation.eSteem.Home", - }, - }); - resolve(); - }) - .catch(err => { - alert(err); - reject(err); - }); - } else { - // If the user is logging in for the first time, the user should set to pin - if (!pinCode) { - this.setState({ - informationText: "Write again", - pinCode: pin, - }); + _setPinCode = pin => new Promise((resolve, reject) => { + const { + currentAccount: { password, name }, + navigation, + } = this.props; + const { isExistUser, pinCode } = this.state; + if (isExistUser) { + // If the user is exist, we are just checking to pin and navigating to home screen + const pinData = { + pinCode: pin, + password, + username: name, + }; + verifyPinCode(pinData) + .then(() => { + navigation.navigate(ROUTES.DRAWER.MAIN); resolve(); - } else { - if (pinCode === pin) { - const pinData = { - pinCode: pin, - password, - username: name, - }; - setUserDataWithPinCode(pinData).then(() => { - AsyncStorage.setItem( - INITIAL.IS_EXIST_USER, - JSON.stringify(true), - () => { - Navigation.setStackRoot(componentId, { - component: { - name: "navigation.eSteem.Home", - }, - }); - resolve(); - } - ); - }); - } else { - this.setState({ - informationText: "wrongggg!!!", - }); - setTimeout(() => { - this.setState({ - informationText: "setup screen", - pinCode: null, - }); - resolve(); - }, 1000); - } - } - } - }); + }) + .catch((err) => { + alert(err); + reject(err); + }); + } else if (!pinCode) { + // If the user is logging in for the first time, the user should set to pin + this.setState({ + informationText: 'Write again', + pinCode: pin, + }); + resolve(); + } else if (pinCode === pin) { + const pinData = { + pinCode: pin, + password, + username: name, + }; + setUserDataWithPinCode(pinData).then(() => { + AsyncStorage.setItem(INITIAL.IS_EXIST_USER, JSON.stringify(true), () => { + navigation.navigate(ROUTES.DRAWER.MAIN); + resolve(); + }); + }); + } else { + this.setState({ + informationText: 'wrongggg!!!', + }); + setTimeout(() => { + this.setState({ + informationText: 'setup screen', + pinCode: null, + }); + resolve(); + }, 1000); + } + }); render() { const { currentAccount } = this.props; @@ -130,7 +110,7 @@ class PinCodeContainer extends React.Component { informationText={informationText} setPinCode={this._setPinCode} showForgotButton={isExistUser} - username={currentAccount ? currentAccount.name : "unknow"} + username={currentAccount ? currentAccount.name : 'unknow'} /> ); } @@ -138,7 +118,7 @@ class PinCodeContainer extends React.Component { const mapStateToProps = state => ({ currentAccount: state.account.data.accounts.find( - item => item.id === state.account.data.currentAccountId + item => item.id === state.account.data.currentAccountId, ), }); diff --git a/src/screens/pinCode/index.js b/src/screens/pinCode/index.js index 6f05acf27..c4284613f 100644 --- a/src/screens/pinCode/index.js +++ b/src/screens/pinCode/index.js @@ -1,5 +1,5 @@ -import PinCodeScreen from "./screen/pinCodeScreen"; -import PinCode from "./container/pinCodeContainer"; +import PinCodeScreen from './screen/pinCodeScreen'; +import PinCodeContainer from './container/pinCodeContainer'; -export { PinCodeScreen, PinCode }; -export default PinCode; +export { PinCodeScreen, PinCodeContainer }; +export default PinCodeContainer; diff --git a/src/screens/splash/container/splashContainer.js b/src/screens/splash/container/splashContainer.js index ccbcc29a3..ec89167f0 100644 --- a/src/screens/splash/container/splashContainer.js +++ b/src/screens/splash/container/splashContainer.js @@ -2,6 +2,9 @@ import React, { Component } from 'react'; import { getUserData, getAuthStatus } from '../../../realm/realm'; +// Constants +import { default as ROUTES } from '../../../constants/routeNames'; + import SplashScreen from '../screen/splashScreen'; class SplashContainer extends Component { @@ -14,9 +17,9 @@ class SplashContainer extends Component { // }); getAuthStatus().then((res) => { if (res) { - navigation.navigate('Main'); + navigation.navigate(ROUTES.DRAWER.MAIN); } else { - navigation.navigate('Main'); + navigation.navigate(ROUTES.SCREENS.LOGIN); } }); }