ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

javascript-React Navigation:自下而上的过渡

2019-11-10 17:35:42  阅读:333  来源: 互联网

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


我在我的本机项目中使用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: {
      ...
    }
 }

标签:react-navigation,reactjs,react-native,transition,javascript
来源: https://codeday.me/bug/20191110/2014007.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有