mirror of
https://github.com/ecency/ecency-mobile.git
synced 2024-12-23 13:22:02 +03:00
Fixed login screen error on android. Moved all route names to constants
This commit is contained in:
parent
1012b0880c
commit
c4a83421a4
@ -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,
|
||||
});
|
||||
|
14
src/constants/routeNames.js
Normal file
14
src/constants/routeNames.js
Normal file
@ -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}`,
|
||||
},
|
||||
};
|
@ -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,
|
||||
};
|
||||
|
@ -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()}
|
||||
/>
|
||||
<KeyboardAwareScrollView
|
||||
onKeyboardWillShow={() => this.setState({ keyboardIsOpen: true })}
|
||||
onKeyboardWillHide={() => this.setState({ keyboardIsOpen: false })}
|
||||
<ScrollableTabView
|
||||
locked={isLoading}
|
||||
style={styles.tabView}
|
||||
renderTabBar={() => (
|
||||
<TabBar
|
||||
style={styles.tabbar}
|
||||
tabUnderlineDefaultWidth={100} // default containerWidth / (numberOfTabs * 4)
|
||||
tabUnderlineScaleX={2} // default 3
|
||||
activeColor="#357ce6"
|
||||
inactiveColor="#222"
|
||||
/>
|
||||
)}
|
||||
>
|
||||
<ScrollableTabView
|
||||
locked={isLoading}
|
||||
style={styles.tabView}
|
||||
renderTabBar={() => (
|
||||
<TabBar
|
||||
style={styles.tabbar}
|
||||
tabUnderlineDefaultWidth={100} // default containerWidth / (numberOfTabs * 4)
|
||||
tabUnderlineScaleX={2} // default 3
|
||||
activeColor="#357ce6"
|
||||
inactiveColor="#222"
|
||||
/>
|
||||
)}
|
||||
>
|
||||
<View tabLabel="Sign in" style={styles.tabbarItem}>
|
||||
<FormInput
|
||||
rightIconName="md-at"
|
||||
leftIconName="md-close-circle"
|
||||
isValid={isUsernameValid}
|
||||
onChange={value => this._handleUsernameChange(value)}
|
||||
placeholder="Username"
|
||||
isEditable
|
||||
type="username"
|
||||
isFirstImage
|
||||
value={username}
|
||||
/>
|
||||
<FormInput
|
||||
rightIconName="md-lock"
|
||||
leftIconName="md-close-circle"
|
||||
isValid={isUsernameValid}
|
||||
onChange={value => this._handleOnPasswordChange(value)}
|
||||
placeholder="Password or WIF"
|
||||
isEditable
|
||||
secureTextEntry
|
||||
type="password"
|
||||
/>
|
||||
<InformationArea
|
||||
description="User credentials are kept locally on the device. Credentials are
|
||||
<View tabLabel="Sign in" style={styles.tabbarItem}>
|
||||
<FormInput
|
||||
rightIconName="md-at"
|
||||
leftIconName="md-close-circle"
|
||||
isValid={isUsernameValid}
|
||||
onChange={value => this._handleUsernameChange(value)}
|
||||
placeholder="Username"
|
||||
isEditable
|
||||
type="username"
|
||||
isFirstImage
|
||||
value={username}
|
||||
/>
|
||||
<FormInput
|
||||
rightIconName="md-lock"
|
||||
leftIconName="md-close-circle"
|
||||
isValid={isUsernameValid}
|
||||
onChange={value => this._handleOnPasswordChange(value)}
|
||||
placeholder="Password or WIF"
|
||||
isEditable
|
||||
secureTextEntry
|
||||
type="password"
|
||||
/>
|
||||
<InformationArea
|
||||
description="User credentials are kept locally on the device. Credentials are
|
||||
removed upon logout!"
|
||||
iconName="ios-information-circle-outline"
|
||||
/>
|
||||
<View style={styles.footerButtons}>
|
||||
<TextButton onPress={() => navigation.navigate('Main')} text="cancel" />
|
||||
</View>
|
||||
<MainButton
|
||||
wrapperStyle={styles.mainButtonWrapper}
|
||||
onPress={this._handleOnPressLogin}
|
||||
iconName="md-person"
|
||||
iconColor="white"
|
||||
text="LOGIN"
|
||||
isDisable={!isUsernameValid || password.length < 2 || username.length < 2}
|
||||
isLoading={isLoading}
|
||||
/>
|
||||
iconName="ios-information-circle-outline"
|
||||
/>
|
||||
<View style={styles.footerButtons}>
|
||||
<TextButton onPress={() => navigation.navigate(ROUTES.DRAWER.MAIN)} text="cancel" />
|
||||
</View>
|
||||
<View tabLabel="SteemConnect" style={styles.steemConnectTab}>
|
||||
<InformationArea
|
||||
description="If you don't want to keep your password encrypted and saved on your device, you can use Steemconnect."
|
||||
iconName="ios-information-circle-outline"
|
||||
/>
|
||||
<MainButton
|
||||
wrapperStyle={styles.mainButtonWrapper}
|
||||
onPress={() => this._loginwithSc2()}
|
||||
iconName="md-person"
|
||||
source={STEEM_CONNECT_LOGO}
|
||||
text="steem"
|
||||
secondText="connect"
|
||||
/>
|
||||
</View>
|
||||
</ScrollableTabView>
|
||||
</KeyboardAwareScrollView>
|
||||
<MainButton
|
||||
wrapperStyle={styles.mainButtonWrapper}
|
||||
onPress={this._handleOnPressLogin}
|
||||
iconName="md-person"
|
||||
iconColor="white"
|
||||
text="LOGIN"
|
||||
isDisable={!isUsernameValid || password.length < 2 || username.length < 2}
|
||||
isLoading={isLoading}
|
||||
/>
|
||||
</View>
|
||||
<View tabLabel="SteemConnect" style={styles.steemConnectTab}>
|
||||
<InformationArea
|
||||
description="If you don't want to keep your password encrypted and saved on your device, you can use Steemconnect."
|
||||
iconName="ios-information-circle-outline"
|
||||
/>
|
||||
<MainButton
|
||||
wrapperStyle={styles.mainButtonWrapper}
|
||||
onPress={() => this._loginwithSc2()}
|
||||
iconName="md-person"
|
||||
source={STEEM_CONNECT_LOGO}
|
||||
text="steem"
|
||||
secondText="connect"
|
||||
/>
|
||||
</View>
|
||||
</ScrollableTabView>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
@ -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,
|
||||
),
|
||||
});
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user