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

"replace" type on Scene does not work when tabs is true #2339

Closed
Pylipala opened this issue Sep 5, 2017 · 7 comments
Closed

"replace" type on Scene does not work when tabs is true #2339

Pylipala opened this issue Sep 5, 2017 · 7 comments

Comments

@Pylipala
Copy link

Pylipala commented Sep 5, 2017

Version

Tell us which versions you are using:

  • react-native-router-flux 4.0.0-beta.21 (v3 is not supported)
  • react-native 0.48.1

Expected behaviour

If a Scene's type is "replace", it should replace current scene.
I should not be able to go back to the original scene with swipe right action.

Actual behaviour

It works when tabs is false. However, if I replace with Tab'ed view, I can go back with swipe right, which is not expected

Steps to reproduce

/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 * @flow
 */

import React, { Component } from 'react';
import {
  AppRegistry,
  StyleSheet,
  Text,
  View,
    TouchableHighlight
} from 'react-native';

import { createStore, applyMiddleware, compose } from 'redux';
import { connect, Provider } from 'react-redux';
import {Router, Scene, Actions, Reducer} from 'react-native-router-flux';

const RouterWithRedux = connect()(Router);

class Splash extends Component {
    render() {
        return <View style={{marginTop: 50}}>
          <TouchableHighlight onPress={this.onPressWelcome} activeOpacity={0.55} underlayColor="#ffffff00">
            <Text>
              Go to Welcome
            </Text>
          </TouchableHighlight>

            <TouchableHighlight style={{marginTop: 50}} onPress={this.onPressHome} activeOpacity={0.55} underlayColor="#ffffff00">
                <Text>
                    Go to Home
                </Text>
            </TouchableHighlight>
        </View>
    }

    onPressWelcome() {
      Actions.welcome();
    }

    onPressHome() {
        Actions.home();
    }
}

class Welcome extends Component {
    render() {
        return <View style={{marginTop: 50}}>
            <TouchableHighlight onPress={this.onPressBack} activeOpacity={0.55} underlayColor="#ffffff00">
                <Text>
                    Go back to Splash
                </Text>
            </TouchableHighlight>
        </View>
    }

    onPressBack() {
        Actions.splash();
    }
}

class Tab1 extends Component {
    render() {
        return <View style={{marginTop: 50}}>
            <Text>
                Tab 1
            </Text>
        </View>
    }
}

class Tab2 extends Component {
    render() {
        return <View style={{marginTop: 50}}>
            <Text>
                Tab 2
            </Text>
        </View>
    }
}

class Tab3 extends Component {
    render() {
        return <View style={{marginTop: 50}}>
            <Text>
                Tab 3
            </Text>
        </View>
    }
}

class Client extends Component {

    render() {
        return <Provider store={compose()(createStore)(()=>{})}>
          <RouterWithRedux>
            <Scene key="root" type={"replace"}>
              <Scene key="splash" component={Splash} initial={true} hideNavBar={true}/>
              <Scene key="welcome" component={Welcome} type="replace" hideNavBar={true}/>

                <Scene key="home" type="replace" showLabel={true} hideNavBar={true} tabs={true} tabBarStyle={{backgroundColor: '#f0f8fff4',}}>
                    <Scene key="tab1" component={Tab1} title="tab1" />
                    <Scene key="tab2" component={Tab2} title="tab2" />
                    <Scene key="tab3" component={Tab3} title="tab3" />
                </Scene>

            </Scene>
          </RouterWithRedux>
        </Provider>;
    }

    componentWillMount() {
    }

    componentWillUnmount() {

    }

}


const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  },
  instructions: {
    textAlign: 'center',
    color: '#333333',
    marginBottom: 5,
  },
});

AppRegistry.registerComponent('rnrf_bug01', () => Client);

It works fine for the "Go to welcome" link, but if we click "Go to home", then swipe right, we could go back to the Splash scene, which is not we are expecting.

@seratonik
Copy link

seratonik commented Sep 5, 2017

I experienced this issue as well, and type reset wasn't finding nested keys. I submitted PR #2344 which was my workaround, but I'm not sure if I'm breaking some other intended behaviour.

@Pylipala
Copy link
Author

Pylipala commented Sep 6, 2017

@seratonik I tried your PR #2344 in my example case, but it doesn't help.

@Pylipala
Copy link
Author

Pylipala commented Sep 6, 2017

After some debugging, I found it is popPrevious in State.js is not working correctly. But I have not found how to fix it.

@Pylipala
Copy link
Author

Pylipala commented Sep 8, 2017

After further debugging, I have created a PR #2356 to fix it. But I am not very sure it is OK for other function.

@SoldierCorp
Copy link

SoldierCorp commented Sep 9, 2017

I have the same issue, replace is not working,

@mcabs3
Copy link
Collaborator

mcabs3 commented Sep 11, 2017

@SoldierCorp PR #2364 should address this issue

@mcabs3 mcabs3 closed this as completed Sep 11, 2017
@ghost
Copy link

ghost commented Sep 11, 2017

Im experience the same issue, and still happening, after #2364

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

4 participants