我陷入了在 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/