反应导航:自下而上过渡

时间:2017-12-28 13:43:40

标签: javascript reactjs react-native transition react-navigation

我在本机反应项目中使用react-navigation来处理我的导航和路线。

就我而言,我有一个ViewA和一个ViewB

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,而是希望从下到上打开{&#39;以上&#39; ; ViewA)并且有一个接近的过渡&#39; top-bottom&#39;。比如模态。

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

我不想要一个模态。

感谢您的时间和帮助

1 个答案:

答案 0 :(得分: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: {
      ...
    }
 }
相关问题