ex-navigation icon indicating copy to clipboard operation
ex-navigation copied to clipboard

`navigator.replace` only works once

Open wli opened this issue 8 years ago • 7 comments

Expected: ThirdScreen should render Actual: SecondScreen renders

RNPlay link: https://rnplay.org/apps/HlERQA

import React from 'react';
import {
  registerComponent,
} from 'react-native-playground';
import {
  StatusBar,
  StyleSheet,
  Text,
  View,
} from 'react-native';
import {
  createRouter,
  NavigationContext,
  NavigationProvider,
  StackNavigation,
} from '@exponent/ex-navigation';
 
  
class FirstScreen extends React.Component {
  static route = {
    navigationBar: {
      title: 'First',
    }
  }
  
  async componentWillMount() {
    this.props.navigator.replace(Router.getRoute('second'));
  }
  
  render() {
    return (
      <View style={styles.container}>
        <Text>FirstScreen</Text>
      </View>
    )
  }
}

class SecondScreen extends React.Component {
  static route = {
    navigationBar: {
      title: 'Second',
    }
  }
  
  async componentWillMount() {
    this.props.navigator.replace(Router.getRoute('third'));
  }

  render() {
    return (
      <View style={styles.container}>
        <Text>SecondScreen</Text>
      </View>
    )
  }
}

class ThirdScreen extends React.Component {
  static route = {
    navigationBar: {
      title: 'Third',
    }
  }
  render() {
    return (
      <View style={styles.container}>
        <Text>ThirdScreen</Text>
      </View>
    )
  }
}

const Router = createRouter(() => ({
  first: () => FirstScreen,
  second: () => SecondScreen,
  third: () => ThirdScreen,
}));

class App extends React.Component {
  render() {
    return (
      <View style={styles.container}>
        <NavigationProvider router={Router}>
          <StackNavigation initialRoute={Router.getRoute('first')} />
        </NavigationProvider>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#fff',
  },
});

registerComponent(App);

wli avatar Nov 11 '16 01:11 wli

Related issue with push and immediatelyResetStack: https://rnplay.org/apps/6FswKA

wli avatar Nov 11 '16 23:11 wli

seems to be a race condition

/cc @brent

cyprusglobe avatar Dec 09 '16 19:12 cyprusglobe

Does anyone know how this can be solved?

femiveys avatar Jan 27 '17 16:01 femiveys

any chance to fix this?

gsaandy avatar Mar 08 '17 04:03 gsaandy

any news?

kay-es avatar Nov 27 '17 10:11 kay-es

Some news?

Danjavia avatar Dec 11 '17 02:12 Danjavia

Does replace work , i am trying to do the same .

githubmss avatar Apr 27 '18 07:04 githubmss