英文:
Animating Swipeable Component: React Native Gesture Handler
问题
我想为我的Swipeable
组件添加动画,以便向用户清楚地显示它可以滑动。然而,我不想让动画完全打开操作项。我只想部分打开它,然后返回到起始位置。有没有办法实现这个?我可以通过编程方式控制滑动,以便我可以使用Reanimated对其进行动画处理吗?
在文档中,我找到的最接近的东西是openLeft
和openRight
方法,但我仍然不想完全滑动我的组件。
英文:
I want to add animations to my Swipeable
component in order to make it clear to the user that it can be swiped. However, I don't want the animation to fully open the action items. I only want it to open partially and then return to the starting position. Is there a way to achieve this? Can I control the swipe programmatically, so that I can animate it with Reanimated?
The closest thing I could find in the docs is the openLeft
and openRight
methods, but again, I don't want to swipe my component the entire way.
答案1
得分: 0
使用以下解决方法:
<Swipeable
renderRightActions={() => (
<View style={{ width: '100%', height: '100%' }} />
)}
>
{children}
</Swipeable>
以使 Swipeable
正常工作,然后在其下方插入一个绝对定位的背景。这样,我可以将 Swipeable
包装在一个 Animated.View
中,背景将保持静止,因为它正在进行动画处理。
当然,可能有我遗漏的理想解决方案。
英文:
Ended up using this workaround:
<Swipeable
renderRightActions={() => (
<View style={{width: '100%', height: '100%'}} />
)}>
{children}
</Swipeable>
to make the Swipeable
work, and then inserting an absolutely-positioned background below it. This way, I could wrap the Swipeable
with an Animated.View
and the background will stay stationary as it is being animated.
Of course, there might be an ideal solution I'm missing.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论