gpt4 book ai didi

javascript - 从 header 响应 native 调用屏幕功能

转载 作者:行者123 更新时间:2023-11-30 11:10:06 25 4
gpt4 key购买 nike

我在 ScreenPassword 中有更新密码功能,但我想通过点击屏幕标题上的保存按钮来更新密码。

NavSettings.js

const routeConfigs = {
Password: {
screen: ScreenPassword,
navigationOptions: {
headerTitle: 'Password',
headerTintColor: '#000',
headerRight: (
<View style={styles.headerRight}>
<Button
style={styles.buttonHeader}
color='#000'
title="Save"
onPress={???????????} />
</View>
)
}
}
}

export default createStackNavigator(routeConfigs);

屏幕密码

export default class ScreenPassword extends Component {
updatePassword = () => {

}
render() {
return (
<ScrollView style={styles.container}>
<View style={styles.boxForm}>
<TextInput
style={styles.textInput}
placeholder="Old Password"
secureTextEntry='true'
/>
<TextInput
style={styles.textInput}
placeholder="New Password"
secureTextEntry='true'
/>
<TextInput
style={styles.textInput}
placeholder="Confirm Password"
secureTextEntry='true'
/>
</View>
</ScrollView>
)
}
}

最佳答案

您可以使用参数和静态方法 navigationOptions:

class ScreenPassword extends React.Component {

static navigationOptions = ({ navigation }) => {
return {
headerTitle: 'Password',
headerTintColor: '#000',
headerRight: (
<View style={styles.headerRight}>
<Button
style={styles.buttonHeader}
color='#000'
title="Save"
onPress={navigation.getParam('updatePassword')}
/>
</View>
),
};
};

componentDidMount() {
this.props.navigation.setParams({ updatePassword: this.updatePassword});
}

render() {
...
}

updatePassword = () => {
...
}

}

关于javascript - 从 header 响应 native 调用屏幕功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54058740/

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