Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

delay back and refresh the current scene can lead to infinite loop. #3110

Closed
ekoooo opened this issue Jul 3, 2018 · 1 comment
Closed

delay back and refresh the current scene can lead to infinite loop. #3110

ekoooo opened this issue Jul 3, 2018 · 1 comment

Comments

@ekoooo
Copy link

ekoooo commented Jul 3, 2018

Version

  • react-native-router-flux v4.0.0-beta.31
  • react-native v0.55.4

Expected behaviour

page1 componentWillReceiveProps called once when page2 pop to page1.

Actual behaviour

page1 componentWillReceiveProps infinite loop when page2 pop to page1.

Steps to reproduce

  1. git clone https://github.com/ekoooo/TestRouterFlux.git.
  2. run App.
  3. page1 -> page2 -> page1.
  4. infinite loop.

logs

page2 componentWillMount
page2 componentWillUnmount
page1 componentWillReceiveProps
page2 componentWillMount
page2 componentWillUnmount
page1 componentWillReceiveProps
page2 componentWillMount
page2 componentWillUnmount
page1 componentWillReceiveProps
page2 componentWillMount
page2 componentWillUnmount
page1 componentWillReceiveProps
page2 componentWillMount
page2 componentWillUnmount
page1 componentWillReceiveProps
page2 componentWillMount
page2 componentWillUnmount
...
...
...

Code

page1

import React, { Component } from 'react';
import {
    Text,
    View,
    TouchableOpacity,
} from 'react-native';
import { Actions } from 'react-native-router-flux';

export default class Page1 extends Component {
    constructor(props) {
        super(props);
     
        this.state = {

        };
    }

    componentWillReceiveProps(newProps) {
        console.log('page1 componentWillReceiveProps');
    }

    render() {
        return (
            <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
                <TouchableOpacity onPress={() => { Actions.page2() }}>
                    <Text>go page2</Text>
                </TouchableOpacity>
            </View>
        );
    }
}

page2

import React, { Component } from 'react';
import {
    Text,
    View,
    YellowBox,
    TouchableOpacity,
} from 'react-native';
import { Actions } from 'react-native-router-flux';

YellowBox.ignoreWarnings(['Warning: isMounted(...) is deprecated', 'Module RCTImageLoader']);

export default class Page1 extends Component {
    constructor(props) {
        super(props);

        this.state = {};

        this.timer = null;

        this._delayGoback = this._delayGoback.bind(this);
    }

    componentWillMount() {
        console.log('page2 componentWillMount');

        Actions.refresh({
            rightTitle: "comfirm",
            onRight: () => {

            },
        })
    }

    componentWillUnmount() {
        console.log('page2 componentWillUnmount');

        this.timer && clearTimeout(this.timer);
    }

    _delayGoback() {
        this.timer = setTimeout(() => {
            Actions.pop({
                refresh: {
                    updateList: true,
                    d: +new Date(),
                }
            });
        }, 200);
    }

    render() {
        return (
            <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
                <TouchableOpacity onPress={() => { this._delayGoback() }}>
                    <Text>pop</Text>
                </TouchableOpacity>
            </View>
        );
    }
}
@aksonov
Copy link
Owner

aksonov commented Aug 8, 2018

You need to use setTimeout to defer nav action

@aksonov aksonov closed this as completed Aug 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants