RoundedButton不会影响iOS / Android应用

时间:2019-04-28 08:58:57

标签: react-native-navigation

我正在运行React Native Navigation 2.18.2。我正在更改RoundedButton onPress回调,但是似乎我的更改在两个平台上均未生效。我想在按下按钮时按下一个新屏幕。

我正在根据开发人员提供的Playground开发项目。

OptionsScreen.js(部分):

class Options extends Component {
  static options() {
    return {
      topBar: {
        visible: true,
        testID: TOP_BAR,
        title: {
          text: "Styling Options"
        },
        rightButtons: [
          {
            id: "ROUND",
            testID: ROUND_BUTTON,
            component: {
              name: Screens.RoundButton,
              passProps: {
                title: "Two"
              }
            }
          }
        ]
      }
    };
  }
  ...
}

RoundedButton.js

const { Navigation } = require("react-native-navigation");
const Screens = require("./Screens");

class RoundedButton extends Component {
  constructor(props) {
    super(props);
    this.subscription = Navigation.events().bindComponent(this);
    this.state = {};
  }

  handleButtonPress = () => {
    Alert.alert(this.props.title, "Thanks for that :)");
    Navigation.push(this.props.componentId, {
      component: {
        name: Screens.Pushed
      }
    });
  };

  render() {
    return (
      <View style={styles.container}>
        <View style={styles.button}>
          <TouchableOpacity onPress={this.props.onClick}>
            <Text style={styles.text}>{this.props.title}</Text>
          </TouchableOpacity>
        </View>
      </View>
    );
  }
}

module.exports = RoundedButton;

通过点击按钮,警报会显示出来,但不会导航到所需页面。

0 个答案:

没有答案