首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >React-Native Swipe删除

React-Native Swipe删除
EN

Stack Overflow用户
提问于 2020-09-16 02:50:45
回答 1查看 2.4K关注 0票数 1

我正在使用react-native-gesture-handler实现刷卡。我不知道如何实现删除,如果我滑动它,它不是完全滑动和删除,因为我真的需要帮助。

现在,它只是滑动,然后抓取

有没有人能看看我的代码,看看我如何实现一个完整的滑动删除。我真的很感激!

代码语言:javascript
复制
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;
EN

回答 1

Stack Overflow用户

发布于 2021-07-17 13:39:41

刷卡超过阈值后删除。删除时,您可以调用布局动画接口-https://reactnative.dev/docs/layoutanimation,以获得更流畅的体验

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63908155

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档