在我的react应用程序中,我使用了来自react原生手势处理程序的Swipeable。当用户向左滑动时,我会显示两个按钮。
<Swipeable
ref={updateRef}
friction={2}
leftThreshold={80}
rightThreshold={41}
renderRightActions={renderRightActions}>children </Swipeable>
const renderRightAction = (text: string, color: string, x: number, progress: any, imageUrl: string, dragX: any) => {
const pressHandler = () => {
close();
console.log(text);
};
return (
<Animated.View style={{ flex: 1, transform: [{ translateX: 0 }] }}>
<RectButton
style={[styles.rightAction, { backgroundColor: color }]}
onPress={pressHandler}>
<SvgXml xml={imageUrl} width={wp(16)} height={wp(16)} />
<Text style={styles.actionText}>{text}</Text>
</RectButton>
</Animated.View>
);
};
const renderRightActions = (progress: any, dragX: any) => (
<View style={styles.renderRightActionsContainer}>
{renderRightAction('Favoritt', Colors.lightBeige, 84, progress, Images.Favourite, dragX)}
{renderRightAction('Skjul', Colors.primaryBackground, 84, progress, Images.CloseEye, dragX)}
</View>
);
字符串
它是工作,我无法实现的是,如果用户不断滑动我希望其中一个按钮(删除)采取全宽,然后删除项目的行。
2条答案
按热度按时间wswtfjt71#
你可以使用onSwipeableOpen(()=> pressPush())。
https://docs.swmansion.com/react-native-gesture-handler/docs/api/components/swipeable#onswipeableopen
我的建议请使用键到你的Swipeable。这将防止不关闭renderRightActions的问题。
字符串
如果您遇到无法关闭的问题,请检查:Delete on swipe is not closing the Swipeable React native
8hhllhi22#
我已经解决了这个错误使用以下方法,它是工作
字符串
我的公寓列表:
型