Animating Swipeable Component: React Native Gesture Handler

huangapple go评论54阅读模式
英文:

Animating Swipeable Component: React Native Gesture Handler

问题

我想为我的Swipeable组件添加动画,以便向用户清楚地显示它可以滑动。然而,我不想让动画完全打开操作项。我只想部分打开它,然后返回到起始位置。有没有办法实现这个?我可以通过编程方式控制滑动,以便我可以使用Reanimated对其进行动画处理吗?

在文档中,我找到的最接近的东西是openLeftopenRight方法,但我仍然不想完全滑动我的组件。

英文:

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:

&lt;Swipeable
  renderRightActions={() =&gt; (
  &lt;View style={{width: &#39;100%&#39;, height: &#39;100%&#39;}} /&gt;
  )}&gt;
  {children}
&lt;/Swipeable&gt;

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.

huangapple
  • 本文由 发表于 2023年6月12日 13:42:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/76453874.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定