- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想调用 headerRight 按钮点击屏幕上的函数。我在 useEffect 中将 func 作为参数传递,如下所示。
useEffect(() => {
navigation.setParams({ _confirmClick: confirmNotification })
}, [navigation])
useLayoutEffect(() => {
navigation.setOptions({
headerRight: () => (
<TouchableOpacity
onPress={() => params._confirmClick('New') }
style={[theme.marginRight15]}>
<View style={[styles.sendNotificationButton,
{
backgroundColor: notification ? theme.colors.notificationDeleteButtonColor :
theme.colors.sendbuttonColor,
borderColor: notification ? theme.colors.notificationDeleteButtonColor :
theme.colors.sendbuttonColor,
}]}>
<Ionicons name="ios-send" size={15}
style={theme.padding3}
color={theme.colors.whiteColor} />
</View>
</TouchableOpacity>
),
});
}, [navigation]);
function confirmNotification(status) {
...
}
当我点击按钮时,它说:TypeError: Cannot read property '_confirmClick' of undefined
最佳答案
您不需要在标题上设置参数。您可以直接将该方法传递给 headerRight :
function yourScreenName({ navigation }) {
useLayoutEffect(() => {
navigation.setOptions({
headerRight: () => (
<TouchableOpacity
onPress={() => confirmNotification('New')}
style={[theme.marginRight15]}>
<View style={[styles.sendNotificationButton,
{
backgroundColor: notification ? theme.colors.notificationDeleteButtonColor :
theme.colors.sendbuttonColor,
borderColor: notification ? theme.colors.notificationDeleteButtonColor :
theme.colors.sendbuttonColor,
}]}>
<Ionicons name="ios-send" size={15}
style={theme.padding3}
color={theme.colors.whiteColor} />
</View>
</TouchableOpacity>
),
});
}, [navigation, confirmNotification]); // pass method directly here
}
Here是一些文档。
关于react-native - react 导航 v5 : Pass function as parameter to be used in headerRight button,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61606346/
我创建了一个堆栈导航器: import {createStackNavigator} from '@react-navigation/stack'; const TheStack = createSt
我是 react-native 和 formik 的新手,我遇到了我试图建立的这个问题。 如何使用 Formik 在 headerRight 中触发函数?我有 updateCorporation 函数
我仍然试图理解这个 react 导航 5.0。 仅供引用,我正在使用 expo,现在从一页导航到另一页没有问题, 问题是当我为 headerRight 放置导航时。 我将 headerRight 放在
我想知道有没有一种方法可以使用 headerRight onPress 来执行诸如调用 Alert 之类的操作: 我在 MyPet.js 中有一个函数,代码如下: _alert=()=>{ ale
为什么这不起作用?: headerRight: this.props.navigation.navigate('MenuCQ')}/> 按下后,expo 就会崩溃,根本没有错误消息。 onPress
使用react-navigation,发现headerLeft没有响应?而且没有headerLeft,headerRight class Message extends React.Component
我想调用 headerRight 按钮点击屏幕上的函数。我在 useEffect 中将 func 作为参数传递,如下所示。 useEffect(() => { navigation.setPa
我是一名优秀的程序员,十分优秀!