【发布时间】:2021-12-15 12:12:00
【问题描述】:
我是reanimated 的新手。我现在正在尝试恢复多个项目。
这些项目不会在加载组件的开头显示。 但是当我的意图按下相应的项目时,它们会显示出来。
eg when button 1 is pressed item 1 will pop up slowly, button 2 is pressed and item 2
像这样。
我的应用中有 2 个组件
ItemsList screen 和 item component
我在 itemList 屏幕中没有任何动画代码。我只是在重新调整 item 组件。
{items.map(item => (
<OtherItem
key={item._id}
item={item}
selectedItem={selectedItem}
setSelectedItem={setSelectedItem}
/>
))}
在项目组件中。我有一个sharedValue, useEffecthooks, and useState,我用它来根据用户交互进行动画处理。
项目组件
const [selected, setSelected] = useState(false);
const [count, setCount] = useState(1);
// Animation
const progress = useSharedValue(0);
const reAnimatedStyle = useAnimatedStyle(() => {
return {
opacity: progress.value,
transform: [{scale: progress.value}],
};
});
useEffect(() => {
progress.value = withTiming(1, {duration: 2000});
}, [selected]);
return (
<TouchableOpacity
onPress={() => selectItem(item)}
style={[
globalStyle.pageContainer,
]}>
{selected && (
<Animated.View
style={[
{flexDirection: 'row', alignItems: 'center'},
reAnimatedStyle,
]}>
...
</Animated.View>
)}
</TouchableOpacity>)
正如您在代码中看到的,我的意图是当用户按下button 1 时,button 1 中的隐藏详细信息将显示出来。
但事情是只有第一次有效。我认为是因为shared value。我想要的是我希望每个项目都能正常工作。那么任何人都可以提出解决方案
【问题讨论】:
-
“按钮 1”在哪里?你能提供更多代码吗?或者如果您在世博小吃中提供工作代码会更好。
-
@MRPMOHIBURRAHMAN 我正在映射
buttons。我的意思是ITEM COMPONENT本身就是按钮,每个按钮里面都有一些隐藏的文本
标签: react-native react-native-reanimated-v2