javascript-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,而是希望它从下到上(在ViewA上方)打开,并具有一个紧密的“上下”过渡.如模态.

我的问题是,我想保持我的StackNavigator不变.并希望自定义此过渡.

我不要模态

感谢您的时间和帮助

解决方法:

确保将其导入到页面顶部

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: {
      ...
    }
 }
上一篇:javascript-在React.js和React Native应用程序之间重用代码


下一篇:将变量传递给循环调用的异步JavaScript函数(反应)