forked from vergnet/application-amicale
Allow going back to last screen after login
This commit is contained in:
parent
205162605f
commit
3fe6be4238
7 changed files with 53 additions and 29 deletions
2
App.js
2
App.js
|
@ -73,7 +73,7 @@ export default class App extends React.Component<Props, State> {
|
|||
// Navigate to nested navigator and pass data to the index screen
|
||||
this.navigatorRef.current.navigate('home', {
|
||||
screen: 'index',
|
||||
params: {nextScreen: route, data: data, shouldOpen: true}
|
||||
params: {nextScreen: route, data: data}
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ import {ERROR_TYPE} from "../../managers/ConnectionManager";
|
|||
|
||||
type Props = {
|
||||
navigation: Object,
|
||||
route: Object,
|
||||
errorCode: number,
|
||||
onRefresh: Function,
|
||||
}
|
||||
|
@ -85,7 +86,11 @@ class ErrorView extends React.PureComponent<Props, State> {
|
|||
</Button>;
|
||||
}
|
||||
|
||||
goToLogin = () => this.props.navigation.navigate("login");
|
||||
goToLogin = () => this.props.navigation.navigate("login",
|
||||
{
|
||||
screen: 'index',
|
||||
params: {nextScreen: this.props.route.name}
|
||||
});
|
||||
|
||||
getLoginButton() {
|
||||
return <Button
|
||||
|
|
|
@ -19,7 +19,7 @@ type Props = {
|
|||
stickyHeader: boolean,
|
||||
createDataset: Function,
|
||||
updateData: number,
|
||||
itemHeight: number,
|
||||
itemHeight: number | null,
|
||||
}
|
||||
|
||||
type State = {
|
||||
|
@ -43,7 +43,7 @@ export default class WebSectionList extends React.PureComponent<Props, State> {
|
|||
renderSectionHeader: null,
|
||||
stickyHeader: false,
|
||||
updateData: 0,
|
||||
itemHeight: undefined,
|
||||
itemHeight: null,
|
||||
};
|
||||
|
||||
refreshInterval: IntervalID;
|
||||
|
@ -198,7 +198,7 @@ export default class WebSectionList extends React.PureComponent<Props, State> {
|
|||
errorCode={ERROR_TYPE.CONNECTION_ERROR}
|
||||
onRefresh={this.onRefresh}/>
|
||||
}
|
||||
getItemLayout={this.props.itemHeight !== undefined ? this.itemLayout : undefined}
|
||||
getItemLayout={this.props.itemHeight !== null ? this.itemLayout : undefined}
|
||||
/>
|
||||
<Snackbar
|
||||
visible={this.state.snackbarVisible}
|
||||
|
|
|
@ -169,7 +169,7 @@ function HomeStackComponent(initialRoute: string | null, defaultData: Object) {
|
|||
initialParams={data}
|
||||
/>
|
||||
<HomeStack.Screen
|
||||
name="planning-information"
|
||||
name="home-planning-information"
|
||||
component={PlanningDisplayScreen}
|
||||
options={{
|
||||
title: i18n.t('screens.planningDisplayScreen'),
|
||||
|
@ -177,7 +177,7 @@ function HomeStackComponent(initialRoute: string | null, defaultData: Object) {
|
|||
}}
|
||||
/>
|
||||
<HomeStack.Screen
|
||||
name="club-information"
|
||||
name="home-club-information"
|
||||
component={ClubDisplayScreen}
|
||||
options={({navigation}) => {
|
||||
return {
|
||||
|
|
|
@ -7,9 +7,11 @@ import ConnectionManager from "../../managers/ConnectionManager";
|
|||
import {openBrowser} from "../../utils/WebBrowser";
|
||||
import i18n from 'i18n-js';
|
||||
import ErrorDialog from "../../components/Dialog/ErrorDialog";
|
||||
import {CommonActions} from "@react-navigation/native";
|
||||
|
||||
type Props = {
|
||||
navigation: Object,
|
||||
route: Object,
|
||||
}
|
||||
|
||||
type State = {
|
||||
|
@ -44,17 +46,28 @@ class LoginScreen extends React.Component<Props, State> {
|
|||
|
||||
onEmailChange: Function;
|
||||
onPasswordChange: Function;
|
||||
|
||||
passwordInputRef: Object;
|
||||
|
||||
nextScreen: string;
|
||||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.onEmailChange = this.onInputChange.bind(this, true);
|
||||
this.onPasswordChange = this.onInputChange.bind(this, false);
|
||||
|
||||
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) =>
|
||||
this.setState({
|
||||
dialogVisible: true,
|
||||
|
@ -63,23 +76,33 @@ class LoginScreen extends React.Component<Props, State> {
|
|||
|
||||
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);
|
||||
|
||||
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});
|
||||
|
||||
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) {
|
||||
if (isEmail) {
|
||||
|
|
|
@ -39,17 +39,12 @@ type Props = {
|
|||
*/
|
||||
class HomeScreen extends React.Component<Props> {
|
||||
|
||||
getRenderItem: Function;
|
||||
createDataset: Function;
|
||||
|
||||
colors: Object;
|
||||
|
||||
isLoggedIn: boolean | null;
|
||||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.getRenderItem = this.getRenderItem.bind(this);
|
||||
this.createDataset = this.createDataset.bind(this);
|
||||
this.colors = props.theme.colors;
|
||||
|
||||
this.isLoggedIn = null;
|
||||
|
@ -85,10 +80,10 @@ class HomeScreen extends React.Component<Props> {
|
|||
|
||||
handleNavigationParams = () => {
|
||||
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);
|
||||
// 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
|
||||
* @return {*}
|
||||
*/
|
||||
createDataset(fetchedData: Object) {
|
||||
createDataset = (fetchedData: Object) => {
|
||||
// fetchedData = DATA;
|
||||
let newsData = [];
|
||||
let dashboardData = [];
|
||||
|
@ -201,7 +196,7 @@ class HomeScreen extends React.Component<Props> {
|
|||
return this.getDashboardEventItem(content);
|
||||
else if (item['id'] === 'top')
|
||||
return this.getDashboardTopItem(content);
|
||||
else if (item['id'] === 'actions')
|
||||
else
|
||||
return this.getActionsDashboardItem();
|
||||
}
|
||||
|
||||
|
@ -462,10 +457,11 @@ class HomeScreen extends React.Component<Props> {
|
|||
* @param section The current section
|
||||
* @return {*}
|
||||
*/
|
||||
getRenderItem({item, section}: Object) {
|
||||
return (section['id'] === SECTIONS_ID[0] ?
|
||||
this.getDashboardItem(item) : this.getFeedItem(item));
|
||||
}
|
||||
getRenderItem = ({item, section}: Object) => {
|
||||
return (section['id'] === SECTIONS_ID[0]
|
||||
? this.getDashboardItem(item)
|
||||
: this.getFeedItem(item));
|
||||
};
|
||||
|
||||
openScanner = () => this.props.navigation.navigate("scanner");
|
||||
|
||||
|
|
|
@ -7,8 +7,8 @@ export default class URLHandler {
|
|||
static CLUB_INFO_URL_PATH = "club";
|
||||
static EVENT_INFO_URL_PATH = "event";
|
||||
|
||||
static CLUB_INFO_ROUTE = "club-information";
|
||||
static EVENT_INFO_ROUTE = "planning-information";
|
||||
static CLUB_INFO_ROUTE = "home-club-information";
|
||||
static EVENT_INFO_ROUTE = "home-planning-information";
|
||||
|
||||
onInitialURLParsed: Function;
|
||||
onDetectURL: Function;
|
||||
|
|
Loading…
Reference in a new issue