Working on splash

This commit is contained in:
mistikk 2018-10-30 17:24:27 +03:00
parent 58948f6a72
commit 0fd01239a6
6 changed files with 43 additions and 10 deletions

View File

@ -30,6 +30,6 @@ export default SwitchNavigator({
[ROUTES.SCREENS.EDITOR]: { screen: RootComponent()(Editor) }, [ROUTES.SCREENS.EDITOR]: { screen: RootComponent()(Editor) },
[ROUTES.SCREENS.PINCODE]: { screen: RootComponent()(PinCode) }, [ROUTES.SCREENS.PINCODE]: { screen: RootComponent()(PinCode) },
[ROUTES.SCREENS.PROFILE]: { screen: RootComponent()(Profile) }, [ROUTES.SCREENS.PROFILE]: { screen: RootComponent()(Profile) },
[ROUTES.SCREENS.SPLASH]: { screen: RootComponent()(Splash) }, [ROUTES.SCREENS.SPLASH]: { screen: Splash },
[ROUTES.SCREENS.STEEM_CONNECT]: { screen: RootComponent()(SteemConnect) }, [ROUTES.SCREENS.STEEM_CONNECT]: { screen: RootComponent()(SteemConnect) },
}); });

View File

@ -1,5 +1,9 @@
import { import {
LOGIN, LOGOUT, OPEN_PIN_CODE_MODAL, CLOSE_PIN_CODE_MODAL, LOGIN,
LOGOUT,
OPEN_PIN_CODE_MODAL,
CLOSE_PIN_CODE_MODAL,
ACTIVE_APPLICATION,
} from '../constants/constants'; } from '../constants/constants';
export const login = () => ({ export const login = () => ({
@ -17,3 +21,7 @@ export const openPinCodeModal = () => ({
export const closePinCodeModal = () => ({ export const closePinCodeModal = () => ({
type: CLOSE_PIN_CODE_MODAL, type: CLOSE_PIN_CODE_MODAL,
}); });
export const activeApplication = () => ({
type: ACTIVE_APPLICATION,
});

View File

@ -17,3 +17,4 @@ export const FETCH_ACCOUNT_FAIL = 'FETCH_ACCOUNT_FAIL';
export const IS_LOGGED_IN = 'IS_LOGGED_IN'; export const IS_LOGGED_IN = 'IS_LOGGED_IN';
export const OPEN_PIN_CODE_MODAL = 'OPEN_PIN_CODE_MODAL'; export const OPEN_PIN_CODE_MODAL = 'OPEN_PIN_CODE_MODAL';
export const CLOSE_PIN_CODE_MODAL = 'CLOSE_PIN_CODE_MODAL'; export const CLOSE_PIN_CODE_MODAL = 'CLOSE_PIN_CODE_MODAL';
export const ACTIVE_APPLICATION = 'ACTIVE_APPLICATION';

View File

@ -1,11 +1,16 @@
import { import {
LOGIN, LOGOUT, OPEN_PIN_CODE_MODAL, CLOSE_PIN_CODE_MODAL, LOGIN,
LOGOUT,
OPEN_PIN_CODE_MODAL,
CLOSE_PIN_CODE_MODAL,
ACTIVE_APPLICATION,
} from '../constants/constants'; } from '../constants/constants';
const initialState = { const initialState = {
isLoggedIn: false, // Has any logged in user. isLoggedIn: false, // Has any logged in user.
loading: false, // It is lock to all screen and shows loading animation. loading: false, // It is lock to all screen and shows loading animation.
isPinCodeReqiure: false, isPinCodeReqiure: false,
isActive: false,
}; };
export default function (state = initialState, action) { export default function (state = initialState, action) {
@ -30,6 +35,11 @@ export default function (state = initialState, action) {
...state, ...state,
isPinCodeReqiure: false, isPinCodeReqiure: false,
}; };
case ACTIVE_APPLICATION:
return {
...state,
isActive: true,
};
default: default:
return state; return state;
} }

View File

@ -9,6 +9,9 @@ import { openPinCodeModal } from '../../../redux/actions/applicationActions';
import { Modal } from '../../../components'; import { Modal } from '../../../components';
import { PinCode } from '../..'; import { PinCode } from '../..';
// Constants
import { default as ROUTES } from '../../../constants/routeNames';
const RootContainer = () => (WrappedComponent) => { const RootContainer = () => (WrappedComponent) => {
class RootComponent extends Component { class RootComponent extends Component {
constructor(props) { constructor(props) {
@ -20,6 +23,13 @@ const RootContainer = () => (WrappedComponent) => {
}; };
} }
componentWillMount() {
const { isActive, navigation } = this.props;
if (!isActive) {
navigation.navigate(ROUTES.SCREENS.SPLASH);
}
}
componentDidMount() { componentDidMount() {
AppState.addEventListener('change', this._handleAppStateChange); AppState.addEventListener('change', this._handleAppStateChange);
} }
@ -74,6 +84,7 @@ const RootContainer = () => (WrappedComponent) => {
} }
const mapStateToProps = state => ({ const mapStateToProps = state => ({
isPinCodeReqiure: state.application.isPinCodeReqiure, isPinCodeReqiure: state.application.isPinCodeReqiure,
isActiveApp: state.application.isActive,
}); });
return connect(mapStateToProps)(RootComponent); return connect(mapStateToProps)(RootComponent);

View File

@ -14,15 +14,18 @@ class SplashContainer extends Component {
_getUserData = () => { _getUserData = () => {
const { navigation } = this.props; const { navigation } = this.props;
getAuthStatus().then((res) => { getAuthStatus().then((res) => {
console.log('=========res=========', res);
getUserData().then((response) => { getUserData().then((response) => {
if (response) { console.log('=========response=========', response);
navigation.navigate(ROUTES.SCREENS.PINCODE); // if (response) {
// navigation.navigate(ROUTES.DRAWER.MAIN); // navigation.navigate(ROUTES.SCREENS.PINCODE);
} else { // // navigation.navigate(ROUTES.DRAWER.MAIN);
navigation.navigate(ROUTES.SCREENS.LOGIN); // } else {
} // navigation.navigate(ROUTES.SCREENS.LOGIN);
// }
}); });
}); });
}; };