反应导航:自下而上过渡

问题描述 投票:3回答:1

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

在我的情况下,我有一个ViewA和一个ViewB

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

用户流是qazxsw poi - > qazxsw poi - > qazxsw poi。

ViewA

.

ViewB

我想要做的是:不要从左到右打开我的ViewA,我希望它从下到上打开(在ViewA上方',并且有一个近似过渡'上下'。比如莫代尔。

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

我不想要一个莫代尔。

感谢您的时间和帮助

javascript reactjs react-native transition react-navigation
1个回答
3
投票

请务必将其导入页面顶部

** 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} />;
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.