简体   繁体   English

react-native 自定义 slider,使用 `diffClamp`

[英]react-native custom slider, using `diffClamp`

I have made a custom slider which can be seen here.我制作了一个定制的 slider,可以在这里看到。

The problem is with the following snippet问题在于以下代码段

let transX = cond(
  eq(gestureState, State.ACTIVE),
  diffClamp(add(offsetX, dragX), 0, 200),
  set(offsetX, add(offsetX, dragX)),
);

I am able to limit the range of the slider when the gesture is Active but I am not able to set the limit when the gesture has completed.当手势处于活动状态时,我可以限制 slider 的范围,但在手势完成后我无法设置限制。

I tried adding diffClamp to the set method within the cond , but that fixes the position of the knob to the start and the whole slider behaves in a weird way.我尝试将diffClamp添加到cond中的set方法中,但这会将旋钮的 position 固定到开头,并且整个 slider 的行为方式很奇怪。

Any help would be much appreciated.任何帮助将非常感激。

I've been seeing some issues when trying to implement something similar using diffClamp , where diffClamp wouldn't assign the node in set .我在尝试使用diffClamp实现类似的东西时遇到了一些问题,其中diffClamp不会在set中分配节点。 I would suggest implementing the diffClamp using min and max .我建议使用minmax来实现diffClamp

Something like this:像这样的东西:

let transX = cond(
  eq(gestureState, State.ACTIVE),
  max(0, min(200, add(offsetX, dragX))),
  set(offsetX, max(0, min(200, add(offsetX, dragX)))),
);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM