mirror of
https://github.com/ecency/ecency-mobile.git
synced 2024-12-28 07:55:08 +03:00
Moved foreground control to root component
This commit is contained in:
parent
0ad3fd10bd
commit
58948f6a72
@ -1,6 +1,6 @@
|
||||
import React, { Component, Fragment } from 'react';
|
||||
import {
|
||||
FlatList, View, ActivityIndicator, AppState,
|
||||
FlatList, View, ActivityIndicator,
|
||||
} from 'react-native';
|
||||
|
||||
// import Placeholder from 'rn-placeholder';
|
||||
@ -28,13 +28,11 @@ class PostsView extends Component {
|
||||
startPermlink: '',
|
||||
refreshing: false,
|
||||
isLoading: false,
|
||||
appState: AppState.currentState,
|
||||
};
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
this._loadPosts(this.state.user);
|
||||
AppState.addEventListener('change', this._handleAppStateChange);
|
||||
}
|
||||
|
||||
componentWillReceiveProps(nextProps) {
|
||||
@ -47,16 +45,6 @@ class PostsView extends Component {
|
||||
}
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
AppState.removeEventListener('change', this._handleAppStateChange);
|
||||
}
|
||||
|
||||
_handleAppStateChange = (nextAppState) => {
|
||||
if (this.state.appState.match(/inactive|background/) && nextAppState === 'active') {
|
||||
alert('App has come to the foreground!');
|
||||
}
|
||||
this.setState({ appState: nextAppState });
|
||||
};
|
||||
|
||||
_loadPosts = (user, _tag = null) => {
|
||||
const { getFor, tag } = this.props;
|
||||
|
@ -51,7 +51,7 @@ class PinCodeContainer extends Component {
|
||||
|
||||
_setPinCode = pin => new Promise((resolve, reject) => {
|
||||
const {
|
||||
currentAccount: { password, name },
|
||||
currentAccount,
|
||||
dispatch,
|
||||
accessToken,
|
||||
setWrappedComponentState,
|
||||
@ -63,8 +63,8 @@ class PinCodeContainer extends Component {
|
||||
// If the user is exist, we are just checking to pin and navigating to home screen
|
||||
const pinData = {
|
||||
pinCode: pin,
|
||||
password,
|
||||
username: name,
|
||||
password: currentAccount ? currentAccount.password : '',
|
||||
username: currentAccount ? currentAccount.name : '',
|
||||
accessToken,
|
||||
};
|
||||
verifyPinCode(pinData)
|
||||
@ -89,8 +89,8 @@ class PinCodeContainer extends Component {
|
||||
} else if (pinCode === pin) {
|
||||
const pinData = {
|
||||
pinCode: pin,
|
||||
password,
|
||||
username: name,
|
||||
password: currentAccount.password,
|
||||
username: currentAccount.name,
|
||||
};
|
||||
setUserDataWithPinCode(pinData).then(() => {
|
||||
AsyncStorage.setItem(INITIAL.IS_EXIST_USER, JSON.stringify(true), () => {
|
||||
|
@ -1,5 +1,11 @@
|
||||
import React, { Component, Fragment } from 'react';
|
||||
import { AppState } from 'react-native';
|
||||
import { connect } from 'react-redux';
|
||||
|
||||
// Actions
|
||||
import { openPinCodeModal } from '../../../redux/actions/applicationActions';
|
||||
|
||||
// Components
|
||||
import { Modal } from '../../../components';
|
||||
import { PinCode } from '../..';
|
||||
|
||||
@ -10,9 +16,28 @@ const RootContainer = () => (WrappedComponent) => {
|
||||
this.state = {
|
||||
pinCodeStates: null,
|
||||
wrappedComponentStates: null,
|
||||
appState: AppState.currentState,
|
||||
};
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
AppState.addEventListener('change', this._handleAppStateChange);
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
AppState.removeEventListener('change', this._handleAppStateChange);
|
||||
}
|
||||
|
||||
_handleAppStateChange = (nextAppState) => {
|
||||
const { appState } = this.state;
|
||||
const { dispatch } = this.props;
|
||||
|
||||
if (appState.match(/inactive|background/) && nextAppState === 'active') {
|
||||
dispatch(openPinCodeModal());
|
||||
}
|
||||
this.setState({ appState: nextAppState });
|
||||
};
|
||||
|
||||
_setPinCodeState = (data) => {
|
||||
this.setState({ pinCodeStates: { ...data } });
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user