gpt4 book ai didi

react-native - 在 React-Native navigationOptions 中处理 OnPress

转载 作者:行者123 更新时间:2023-12-03 01:16:21 24 4
gpt4 key购买 nike

我陷入了在 navigationOptions 中添加保存方法的困境,你能帮我做正确的事情吗?

static navigationOptions = ({navigation}) => ({
headerTitle: "Add New Item",
...css.header,
headerRight: <NavViewRight
onPress={() => this.rightHeaderAction()} />,
})

最佳答案

实际上并不清楚你到底想做什么。但似乎你想从静态方法调用类内部的非静态方法。

你指的是this,但是这里的this并不是指类实例。为了从类中调用某些内容,您需要将方法设为静态。

类似这样的事情:

class MyScreen extends Component {
static navigationOptions = ({
navigation
}) => ({
headerTitle: "Add New Item",
...css.header,
headerRight: < NavViewRight
onPress = {
() => MyScreen.rightHeaderAction()
}
/>,
})

static rightHeaderAction() {
// your code here
}
}

关于react-native - 在 React-Native navigationOptions 中处理 OnPress,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44179800/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com