diff --git a/App.js b/App.js index 15e1405..d4e505b 100644 --- a/App.js +++ b/App.js @@ -1,12 +1,12 @@ import React from 'react'; import { Root } from "native-base"; import { Provider } from 'react-redux'; -import configureStore from './app/store/configureStore' +import configureStore, {setBundlesTimer} from './app/store/configureStore' import {autoLogin, setStore} from './app/helper/auth' import NavigationService from './NavigationService'; import { getRemoteConfig } from './app/helper/remote-config'; import { AppState } from 'react-native'; -import {setRemoteConfig, loadBundles, loadProducts} from './app/actions'; +import {setRemoteConfig} from './app/actions'; import { PersistGate } from 'redux-persist/integration/react' import analytics from "./app/helper/analytics"; import { initInstabug } from "./app/helper/instabug"; @@ -52,30 +52,8 @@ export default class App extends React.Component { analytics.setCurrentScreen('OnBoarding'); } - componentDidMount = async() => { - this._setBundlesTimer(); + componentDidMount() { AppState.addEventListener('change', this._handleAppStateChange); - // TODO: Check login here then hide splashscreen - setTimeout(async () => { - const loginStatus = await autoLogin(); - - console.log('autologin', loginStatus); - if (!loginStatus.failed) { - console.log('User logged in, hide splash screen and redirect to home.') - NavigationService.navigate(screens.Home); - console.log('Hide splash screen...'); - SplashScreen.hide(); - } else { - if (!loginStatus.missingProfile) { - console.log('User not logged in, hide splash screen and redirect to login'); - store.dispatch(actions.userLogout()); - NavigationService.navigate(screens.OnBoarding); - console.log('Hide splash screen...'); - SplashScreen.hide(); - } - SplashScreen.hide(); - } - }, 200) } componentWillUnmount() { @@ -84,49 +62,30 @@ export default class App extends React.Component { _handleAppStateChange = async (nextAppState) => { // Get remote config when app enters foreground - if (this.state.appState.match(/inactive|background/) && nextAppState === 'active') { - getRemoteConfig(_getRemoteConfigCallback); - this._setBundlesTimer(); + if (this.state.appState === 'active' && nextAppState.match(/inactive|background/)) { SplashScreen.show(); - setTimeout(async () => { - const loginStatus = await autoLogin(); - console.log('autologin', loginStatus); + } else if (this.state.appState.match(/inactive|background/) && nextAppState === 'active') { + getRemoteConfig(_getRemoteConfigCallback); + setBundlesTimer() + const loginStatus = await autoLogin(); + console.log('autologin', loginStatus); - if (!loginStatus.failed) { - NavigationService.navigate(screens.Home); + if (!loginStatus.failed) { + NavigationService.navigate(screens.Home); - } else { - if (!loginStatus.missingProfile) { - store.dispatch(actions.userLogout()); - NavigationService.navigate(screens.OnBoarding); - } + } else { + if (!loginStatus.missingProfile) { + store.dispatch(actions.userLogout()); + NavigationService.navigate(screens.OnBoarding); } + } - SplashScreen.hide(); - }, 200) + console.log('hide splash screen'); + SplashScreen.hide(); } this.setState({appState: nextAppState}); }; - _reloadBundles() { - store.dispatch(loadBundles()); - store.dispatch(loadProducts()); - } - - _setBundlesTimer() { - console.log('set bundles timer...'); - if (typeof this.interval === 'undefined' || this.interval === 0) { - this.interval = setInterval(() => this._reloadBundles() , 5000); - } - } - - _removeBundlesTimer() { - console.log('remove bundles timer...', this.interval); - if (this.interval) { - clearInterval(this.interval); - } - } - render() { return ( diff --git a/NavigationService.js b/NavigationService.js index cb98328..f8e6154 100644 --- a/NavigationService.js +++ b/NavigationService.js @@ -8,8 +8,7 @@ function setTopLevelNavigator(navigatorRef) { _navigator = navigatorRef; } -function navigate(routeName, params) { - console.log(_navigator); +function _navigate(routeName,params) { _navigator.dispatch( NavigationActions.navigate({ routeName, @@ -18,6 +17,14 @@ function navigate(routeName, params) { ); } +function navigate(routeName, params) { + if (!_navigator) { + setTimeout(() => navigate(routeName, params), 200) + } else { + _navigate(routeName, params); + } +} + // add other navigation functions that you need and export them export default { diff --git a/android/app/build.gradle b/android/app/build.gradle index 0b903d5..f51c60e 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -125,8 +125,8 @@ android { applicationId "sg.redotter.otterdelight" minSdkVersion 16 targetSdkVersion 26 - versionCode 22 - versionName "2.12.0" + versionCode 24 + versionName "2.12.1" ndk { abiFilters "armeabi-v7a", "x86" } diff --git a/app/reducers/index.js b/app/reducers/index.js index 87f9d2b..427ce12 100644 --- a/app/reducers/index.js +++ b/app/reducers/index.js @@ -217,7 +217,7 @@ const rootReducer = (state, action) => { console.log('root reducer', action, state); if (action.type === ActionTypes.USER_LOGOUT) { - state = undefined + state = {} } switch (action.type) { diff --git a/app/store/configureStore.js b/app/store/configureStore.js index 57fa77f..f59bd0b 100644 --- a/app/store/configureStore.js +++ b/app/store/configureStore.js @@ -4,6 +4,11 @@ import { persistStore, persistReducer } from 'redux-persist' import storage from 'redux-persist/lib/storage' import api from '../middleware/api' import rootReducer from '../reducers' +import {autoLogin} from "../helper/auth"; +import NavigationService from "../../NavigationService"; +import screens from "../helper/screens"; +import SplashScreen from "react-native-splash-screen"; +import {loadBundles, loadProducts} from "../actions"; const persistConfig = { key: 'root', @@ -11,10 +16,50 @@ const persistConfig = { whitelist: ['pseudonyms', 'auth', 'profile', 'products', 'subscription', 'cards', 'bundles'] }; +let interval; +let store; + const persistedReducer = persistReducer(persistConfig, rootReducer); +export const setBundlesTimer = () => { + console.log('set bundles timer...'); + if (typeof interval === 'undefined' || interval === 0) { + interval = setInterval(() => reloadBundles(), 5000); + } +} + +export const reloadBundles = () => { + store.dispatch(loadBundles()); + store.dispatch(loadProducts()); +} + export default () => { - let store = createStore(persistedReducer, applyMiddleware(thunk, api)); - let persistor = persistStore(store); + store = createStore(persistedReducer, applyMiddleware(thunk, api)); + let persistor = persistStore(store, {}, async () => { + console.log('------------------------------'); + console.log('persist done...'); + + + const loginStatus = await autoLogin(); + + console.log('autologin', loginStatus); + if (!loginStatus.failed) { + console.log('User logged in, hide splash screen and redirect to home.') + console.log('Hide splash screen...'); + SplashScreen.hide(); + NavigationService.navigate(screens.Home); + setBundlesTimer() + } else { + if (!loginStatus.missingProfile) { + console.log('User not logged in, hide splash screen and redirect to login'); + // store.dispatch(actions.userLogout()); + NavigationService.navigate(screens.OnBoarding); + console.log('Hide splash screen...'); + SplashScreen.hide(); + } + console.log('Hide Splash screen'); + SplashScreen.hide(); + } + }); return { store, persistor } } diff --git a/ios/PanaceaReactNativeClient-tvOS/Info.plist b/ios/PanaceaReactNativeClient-tvOS/Info.plist index b1738db..67f9b6a 100644 --- a/ios/PanaceaReactNativeClient-tvOS/Info.plist +++ b/ios/PanaceaReactNativeClient-tvOS/Info.plist @@ -15,11 +15,11 @@ CFBundlePackageType APPL CFBundleShortVersionString - 2.12.0 + 2.12.1 CFBundleSignature ???? CFBundleVersion - 36 + 37 LSRequiresIPhoneOS UILaunchStoryboardName diff --git a/ios/PanaceaReactNativeClient-tvOSTests/Info.plist b/ios/PanaceaReactNativeClient-tvOSTests/Info.plist index c14ad99..4750071 100644 --- a/ios/PanaceaReactNativeClient-tvOSTests/Info.plist +++ b/ios/PanaceaReactNativeClient-tvOSTests/Info.plist @@ -15,10 +15,10 @@ CFBundlePackageType BNDL CFBundleShortVersionString - 2.12.0 + 2.12.1 CFBundleSignature ???? CFBundleVersion - 36 + 37 diff --git a/ios/PanaceaReactNativeClient.xcodeproj/project.pbxproj b/ios/PanaceaReactNativeClient.xcodeproj/project.pbxproj index 4b2ed88..6eecbda 100644 --- a/ios/PanaceaReactNativeClient.xcodeproj/project.pbxproj +++ b/ios/PanaceaReactNativeClient.xcodeproj/project.pbxproj @@ -1620,7 +1620,7 @@ CODE_SIGN_ENTITLEMENTS = PanaceaReactNativeClient/PanaceaReactNativeClient.entitlements; CODE_SIGN_IDENTITY = "iPhone Developer"; CODE_SIGN_STYLE = Manual; - CURRENT_PROJECT_VERSION = 36; + CURRENT_PROJECT_VERSION = 37; DEAD_CODE_STRIPPING = NO; DEVELOPMENT_TEAM = G4VMYY2CK5; FRAMEWORK_SEARCH_PATHS = ( @@ -1660,7 +1660,7 @@ CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Manual; - CURRENT_PROJECT_VERSION = 36; + CURRENT_PROJECT_VERSION = 37; DEVELOPMENT_TEAM = G4VMYY2CK5; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", diff --git a/ios/PanaceaReactNativeClient/Info.plist b/ios/PanaceaReactNativeClient/Info.plist index b0fae11..89e3ee9 100644 --- a/ios/PanaceaReactNativeClient/Info.plist +++ b/ios/PanaceaReactNativeClient/Info.plist @@ -17,7 +17,7 @@ CFBundlePackageType APPL CFBundleShortVersionString - 2.12.0 + 2.12.1 CFBundleSignature ???? CFBundleURLTypes @@ -44,7 +44,7 @@ CFBundleVersion - 36 + 37 LSRequiresIPhoneOS NSAppTransportSecurity diff --git a/ios/PanaceaReactNativeClientTests/Info.plist b/ios/PanaceaReactNativeClientTests/Info.plist index c14ad99..4750071 100644 --- a/ios/PanaceaReactNativeClientTests/Info.plist +++ b/ios/PanaceaReactNativeClientTests/Info.plist @@ -15,10 +15,10 @@ CFBundlePackageType BNDL CFBundleShortVersionString - 2.12.0 + 2.12.1 CFBundleSignature ???? CFBundleVersion - 36 + 37 diff --git a/package.json b/package.json index 2d61f17..0676d16 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "PanaceaReactNativeClient", - "version": "2.12.0", + "version": "2.12.1", "private": true, "devDependencies": { "@babel/core": "^7.0.0",