Allow going back to last screen after login

This commit is contained in:
Arnaud Vergnet 2020-04-09 00:43:43 +02:00
parent 205162605f
commit 3fe6be4238
7 changed files with 53 additions and 29 deletions

2
App.js
View file

@ -73,7 +73,7 @@ export default class App extends React.Component<Props, State> {
// Navigate to nested navigator and pass data to the index screen // Navigate to nested navigator and pass data to the index screen
this.navigatorRef.current.navigate('home', { this.navigatorRef.current.navigate('home', {
screen: 'index', screen: 'index',
params: {nextScreen: route, data: data, shouldOpen: true} params: {nextScreen: route, data: data}
}); });
}; };

View file

@ -9,6 +9,7 @@ import {ERROR_TYPE} from "../../managers/ConnectionManager";
type Props = { type Props = {
navigation: Object, navigation: Object,
route: Object,
errorCode: number, errorCode: number,
onRefresh: Function, onRefresh: Function,
} }
@ -85,7 +86,11 @@ class ErrorView extends React.PureComponent<Props, State> {
</Button>; </Button>;
} }
goToLogin = () => this.props.navigation.navigate("login"); goToLogin = () => this.props.navigation.navigate("login",
{
screen: 'index',
params: {nextScreen: this.props.route.name}
});
getLoginButton() { getLoginButton() {
return <Button return <Button

View file

@ -19,7 +19,7 @@ type Props = {
stickyHeader: boolean, stickyHeader: boolean,
createDataset: Function, createDataset: Function,
updateData: number, updateData: number,
itemHeight: number, itemHeight: number | null,
} }
type State = { type State = {
@ -43,7 +43,7 @@ export default class WebSectionList extends React.PureComponent<Props, State> {
renderSectionHeader: null, renderSectionHeader: null,
stickyHeader: false, stickyHeader: false,
updateData: 0, updateData: 0,
itemHeight: undefined, itemHeight: null,
}; };
refreshInterval: IntervalID; refreshInterval: IntervalID;
@ -198,7 +198,7 @@ export default class WebSectionList extends React.PureComponent<Props, State> {
errorCode={ERROR_TYPE.CONNECTION_ERROR} errorCode={ERROR_TYPE.CONNECTION_ERROR}
onRefresh={this.onRefresh}/> onRefresh={this.onRefresh}/>
} }
getItemLayout={this.props.itemHeight !== undefined ? this.itemLayout : undefined} getItemLayout={this.props.itemHeight !== null ? this.itemLayout : undefined}
/> />
<Snackbar <Snackbar
visible={this.state.snackbarVisible} visible={this.state.snackbarVisible}

View file

@ -169,7 +169,7 @@ function HomeStackComponent(initialRoute: string | null, defaultData: Object) {
initialParams={data} initialParams={data}
/> />
<HomeStack.Screen <HomeStack.Screen
name="planning-information" name="home-planning-information"
component={PlanningDisplayScreen} component={PlanningDisplayScreen}
options={{ options={{
title: i18n.t('screens.planningDisplayScreen'), title: i18n.t('screens.planningDisplayScreen'),
@ -177,7 +177,7 @@ function HomeStackComponent(initialRoute: string | null, defaultData: Object) {
}} }}
/> />
<HomeStack.Screen <HomeStack.Screen
name="club-information" name="home-club-information"
component={ClubDisplayScreen} component={ClubDisplayScreen}
options={({navigation}) => { options={({navigation}) => {
return { return {

View file

@ -7,9 +7,11 @@ import ConnectionManager from "../../managers/ConnectionManager";
import {openBrowser} from "../../utils/WebBrowser"; import {openBrowser} from "../../utils/WebBrowser";
import i18n from 'i18n-js'; import i18n from 'i18n-js';
import ErrorDialog from "../../components/Dialog/ErrorDialog"; import ErrorDialog from "../../components/Dialog/ErrorDialog";
import {CommonActions} from "@react-navigation/native";
type Props = { type Props = {
navigation: Object, navigation: Object,
route: Object,
} }
type State = { type State = {
@ -44,17 +46,28 @@ class LoginScreen extends React.Component<Props, State> {
onEmailChange: Function; onEmailChange: Function;
onPasswordChange: Function; onPasswordChange: Function;
passwordInputRef: Object; passwordInputRef: Object;
nextScreen: string;
constructor(props) { constructor(props) {
super(props); super(props);
this.onEmailChange = this.onInputChange.bind(this, true); this.onEmailChange = this.onInputChange.bind(this, true);
this.onPasswordChange = this.onInputChange.bind(this, false); this.onPasswordChange = this.onInputChange.bind(this, false);
this.colors = props.theme.colors; this.colors = props.theme.colors;
this.props.navigation.addListener('focus', this.onScreenFocus);
} }
onScreenFocus = () => {
if (this.props.route.params !== undefined && this.props.route.params.nextScreen !== undefined) {
this.nextScreen = this.props.route.params.nextScreen;
this.props.navigation.dispatch(CommonActions.setParams({nextScreen: 'profile'}));
} else
this.nextScreen = 'profile';
};
showErrorDialog = (error: number) => showErrorDialog = (error: number) =>
this.setState({ this.setState({
dialogVisible: true, dialogVisible: true,
@ -63,23 +76,33 @@ class LoginScreen extends React.Component<Props, State> {
hideErrorDialog = () => this.setState({dialogVisible: false}); hideErrorDialog = () => this.setState({dialogVisible: false});
handleSuccess = () => this.props.navigation.navigate('profile'); handleSuccess = () => this.props.navigation.navigate(this.nextScreen);
onResetPasswordClick = () => openBrowser(RESET_PASSWORD_LINK, this.colors.primary); onResetPasswordClick = () => openBrowser(RESET_PASSWORD_LINK, this.colors.primary);
validateEmail = () => this.setState({isEmailValidated: true}); validateEmail = () => this.setState({isEmailValidated: true});
isEmailValid() {return emailRegex.test(this.state.email);} isEmailValid() {
return emailRegex.test(this.state.email);
}
shouldShowEmailError() {return this.state.isEmailValidated && !this.isEmailValid();} shouldShowEmailError() {
return this.state.isEmailValidated && !this.isEmailValid();
}
validatePassword = () => this.setState({isPasswordValidated: true}); validatePassword = () => this.setState({isPasswordValidated: true});
isPasswordValid() {return this.state.password !== '';} isPasswordValid() {
return this.state.password !== '';
}
shouldShowPasswordError() {return this.state.isPasswordValidated && !this.isPasswordValid();} shouldShowPasswordError() {
return this.state.isPasswordValidated && !this.isPasswordValid();
}
shouldEnableLogin() {return this.isEmailValid() && this.isPasswordValid() && !this.state.loading;} shouldEnableLogin() {
return this.isEmailValid() && this.isPasswordValid() && !this.state.loading;
}
onInputChange(isEmail: boolean, value: string) { onInputChange(isEmail: boolean, value: string) {
if (isEmail) { if (isEmail) {

View file

@ -39,17 +39,12 @@ type Props = {
*/ */
class HomeScreen extends React.Component<Props> { class HomeScreen extends React.Component<Props> {
getRenderItem: Function;
createDataset: Function;
colors: Object; colors: Object;
isLoggedIn: boolean | null; isLoggedIn: boolean | null;
constructor(props) { constructor(props) {
super(props); super(props);
this.getRenderItem = this.getRenderItem.bind(this);
this.createDataset = this.createDataset.bind(this);
this.colors = props.theme.colors; this.colors = props.theme.colors;
this.isLoggedIn = null; this.isLoggedIn = null;
@ -85,10 +80,10 @@ class HomeScreen extends React.Component<Props> {
handleNavigationParams = () => { handleNavigationParams = () => {
if (this.props.route.params !== undefined) { if (this.props.route.params !== undefined) {
if (this.props.route.params.shouldOpen !== undefined && this.props.route.params.shouldOpen) { if (this.props.route.params.nextScreen !== undefined && this.props.route.params.nextScreen !== null) {
this.props.navigation.navigate(this.props.route.params.nextScreen, this.props.route.params.data); this.props.navigation.navigate(this.props.route.params.nextScreen, this.props.route.params.data);
// reset params to prevent infinite loop // reset params to prevent infinite loop
this.props.navigation.dispatch(CommonActions.setParams({ shouldOpen: false })); this.props.navigation.dispatch(CommonActions.setParams({ nextScreen: null }));
} }
} }
}; };
@ -122,7 +117,7 @@ class HomeScreen extends React.Component<Props> {
* @param fetchedData * @param fetchedData
* @return {*} * @return {*}
*/ */
createDataset(fetchedData: Object) { createDataset = (fetchedData: Object) => {
// fetchedData = DATA; // fetchedData = DATA;
let newsData = []; let newsData = [];
let dashboardData = []; let dashboardData = [];
@ -201,7 +196,7 @@ class HomeScreen extends React.Component<Props> {
return this.getDashboardEventItem(content); return this.getDashboardEventItem(content);
else if (item['id'] === 'top') else if (item['id'] === 'top')
return this.getDashboardTopItem(content); return this.getDashboardTopItem(content);
else if (item['id'] === 'actions') else
return this.getActionsDashboardItem(); return this.getActionsDashboardItem();
} }
@ -462,10 +457,11 @@ class HomeScreen extends React.Component<Props> {
* @param section The current section * @param section The current section
* @return {*} * @return {*}
*/ */
getRenderItem({item, section}: Object) { getRenderItem = ({item, section}: Object) => {
return (section['id'] === SECTIONS_ID[0] ? return (section['id'] === SECTIONS_ID[0]
this.getDashboardItem(item) : this.getFeedItem(item)); ? this.getDashboardItem(item)
} : this.getFeedItem(item));
};
openScanner = () => this.props.navigation.navigate("scanner"); openScanner = () => this.props.navigation.navigate("scanner");

View file

@ -7,8 +7,8 @@ export default class URLHandler {
static CLUB_INFO_URL_PATH = "club"; static CLUB_INFO_URL_PATH = "club";
static EVENT_INFO_URL_PATH = "event"; static EVENT_INFO_URL_PATH = "event";
static CLUB_INFO_ROUTE = "club-information"; static CLUB_INFO_ROUTE = "home-club-information";
static EVENT_INFO_ROUTE = "planning-information"; static EVENT_INFO_ROUTE = "home-planning-information";
onInitialURLParsed: Function; onInitialURLParsed: Function;
onDetectURL: Function; onDetectURL: Function;