首页 文章

反应导航:自下而上过渡

提问于
浏览
3

我在我的react-native项目中使用react-navigation来处理我的导航和路由 .

在我的情况下,我有 ViewAViewB .

ViewA 需要填写我的 ViewB 的信息 .

用户流是 ViewA - > ViewB - > ViewA .

** VIEW A **
import React from "react";
import { Button, Text, View } from "react-native";

class ViewA extends React.Component {
  state = { selected: false };

  onSelect = data => {
    this.setState(data);
  };

  onPress = () => {
    this.props.navigate("ViewB", { onSelect: this.onSelect });
  };

  render() {
    return (
      <View>
        <Text>{this.state.selected ? "Selected" : "Not Selected"}</Text>
        <Button title="Next" onPress={this.onPress} />
      </View>
    );
  }
}

.

**VIEW B**
import React from "react";
import { Button } from "react-native";

class ViewB extends React.Component {
  goBack() {
    const { navigation } = this.props;
    navigation.goBack();
    navigation.state.params.onSelect({ selected: true });
  }

  render() {
    return <Button title="back" onPress={this.goBack} />;
  }
}

我要做的是:而不是从左到右打开我的 ViewB ,而'd like it to be opened from bottom to up ('在' the ViewA) and having a close transition ' top-bottom'之上 . 比如莫代尔 .

我的问题是,我想保持我的StackNavigator不变 . 并希望定制这种转变 .

我不想要一个莫代尔 .

感谢您的时间和帮助

1 回答

  • 3

    请务必将其导入页面顶部

    import CardStackStyleInterpolator from "react-navigation/src/views/CardStack/CardStackStyleInterpolator";
    

    这就是导航器对于简单过渡的看法 .

    StackNavigator(
     {
       Scenes...
     },
     {
       transitionConfig: () => ({
         screenInterpolator: props => {
    
           // Basically you need to create a condition for individual scenes
           if (props.scene.route.routeName === 'NameOfOneScene') {
    
             // forVertical makes the scene transition for Top to Bottom
             return CardStackStyleInterpolator.forVertical(props);
           }
    
           const last = props.scenes[props.scenes.length - 1];
    
           // This controls the transition when navigation back toa specific scene
           if (last.route.routeName === 'NameOfOneScene') {
    
             // Here, forVertical flows from Top to Bottom
             return CardStackStyleInterpolator.forVertical(props);
           }
    
           This declares the default transition for every other scene
           return CardStackStyleInterpolator.forHorizontal(props);
        },
        navigationOptions: { 
          ... 
        },
        cardStyle: {
          ...
        }
     }
    

相关问题