微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

React-Native滑动删除

如何解决React-Native滑动删除

我正在使用react-native-gesture-handler来刷卡。我不知道如何实施删除操作,如果我滑动该项目,它也无法完全滑动和删除,因为我确实需要帮助。

现在只有先刷卡然后抓拍

请有人看一下我的代码,看看我如何实现完整的删除操作,对此我深表歉意!!!!!

import Swipeable from 'react-native-gesture-handler/Swipeable';
import { RectButton } from 'react-native-gesture-handler';

const Todo = (props) => {
  const customList = useSelector(state => state.todo.myCustomItems);
  const renderRightAction = (icon,color,backgroundColor,x,progress) => {
    const trans = progress.interpolate({
      inputRange: [0,1],outputRange: [x,0]
    })

    return (
      <Animated.View style={{ flex: 1,transform: [{ translateX: trans }] }}>
        <RectButton
          style={[styles.rightAction,{ backgroundColor: backgroundColor }]}
        >
          <Feather name="trash-2" size={24} color={'white'} />
        </RectButton>
      </Animated.View>
    )
  }
  const renderRightActions = progress => (
    <View style={{ width: 120,flexDirection: 'row' }}>
      {renderRightAction('delete','#ffffff','#dd2c00',64,progress)}
    </View>
  )
  const updateRef = ref => {
    const swipeableRow = ref
  }

  const renderTodo = ({ item,index }) => {
    return (
      <Swipeable
        ref={updateRef}
        friction={1.5}
        rightThreshold={30}
        renderRightActions={renderRightActions}>
        <ListItem
          title={i.value}
        />
      </Swipeable>
    );
  };

  return (
    <SafeAreaView style={styles.container}>
      <FlatList
        data={customList}
        keyExtractor={(item,index) => index}
        renderItem={renderTodo}
      />
    </SafeAreaView>
  );
};

export default Todo;

解决方法

刷卡超过阈值时删除卡片。 删除时可以调用Layout Animation API -https://reactnative.dev/docs/layoutanimation,体验更流畅

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。