目的是从平面列表中滑动组件,从右或左滑动以显示选项,就像我们在 Instagram 上一样。 Instagram 的 slider 报告功能仅适用于 iOS,不适用于 Android
我们已经尝试使用 react-native-navigation-drawer,因为它可以在特定 View 内创建菜单,但它与我们对项目的依赖性冲突,因此我们正在寻找其他选项。
最佳答案
你可以使用react-native-gesture-handler
来实现它
例子
import React, { Component } from "react";
import { Animated, StyleSheet, View } from "react-native";
import { RectButton } from "react-native-gesture-handler";
import Swipeable from "react-native-gesture-handler/Swipeable";
class AppleStyleSwipeableRow extends Component {
renderLeftActions = (progress, dragX) => {
const trans = dragX.interpolate({
inputRange: [0, 50, 100, 101],
outputRange: [-20, 0, 0, 1],
});
return (
<RectButton style={styles.leftAction} onPress={this.close}>
<Animated.Text
style={[
styles.actionText,
{
transform: [{ translateX: trans }],
},
]}>
Archive
</Animated.Text>
</RectButton>
);
};
render() {
return (
<Swipeable
renderLeftActions={this.renderLeftActions}>
<Text>
"hello"
</Text>
</Swipeable>
);
}
}
关于android - 如何在 react-native 中滑动平面列表中的组件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59217215/