react-native-slider icon indicating copy to clipboard operation
react-native-slider copied to clipboard

Support native events

Open ShaMan123 opened this issue 6 years ago • 8 comments

Describe the Feature

Native Events instead of ~js events~: onValueChange onSlidingStart onSlidingComplete

Possible Implementations

Supporting native events will unlock the abilities of Animated.event enabling tracking the Slider's value and animating stuff accordingly. This will enable customizing this view to a large extent easily and with high performance.

Avoiding breaking changes can be achieved with a flag from props or by checking typeof props.onValueChange === 'object'

.

Android JS Impl

Uses Slider for value and renders the rest on top. Native events will enhance this extremely and make dev experience easier (less code needed for customization)

Color Slider

Related Issues

ShaMan123 avatar Aug 28 '19 10:08 ShaMan123

I was trying to tackle that, but it does not work with the native driver. I was looking into the android implementation of Animated Animated and Scroll view (where onScroll can be used with native driver) but could not find anything that is implemented in the scroll view which is not implemented in slider in terms of events and actually I have no idea why it does not work. I didn't debug native code to see what values are there. Maybe someone with larger native knowledge could advise on how to implement it 😊

jayu avatar Nov 18 '19 09:11 jayu

I figured this out. The problem here is that the native event has a different name than the callback prop. You can hack this with a workaround.

enum NATIVE_EVENT_NAMES {
    onValueChange = 'topChange',
    onSlidingStart = 'topSlidingStart',
    onSlidingComplete = 'topSlidingComplete'
}


const val = new Animated.Value(0);
<AnimatedSlider
   topChange={event([{ nativeEvent: { value: val } }])}
/>

ShaMan123 avatar Mar 13 '20 08:03 ShaMan123

This is what I found also, we can fix it with some refactoring. But the problem is it does not work with native driver (at least for me, when I was playing with it)

Without a native driver, it will not be significantly more performant.

Maybe @osdnk could give it a try :D? or try to advise on what should be done in order to make a native driver work in that case

jayu avatar Mar 13 '20 12:03 jayu

I'm using it with reanimated and it works

ShaMan123 avatar Mar 13 '20 13:03 ShaMan123

As I remember I was trying with Animated, interesting. Seems like @ShaMan123 you are on a good way to open a PR :D

jayu avatar Mar 13 '20 13:03 jayu

Hello @ShaMan123! I can see you already spent some time investigating that issue - thank you 👍 Would you like to open a PR with a fix for that?

BartoszKlonowski avatar Oct 20 '21 18:10 BartoszKlonowski

This is very stale, I abandoned react native a while back (Hoping never to return). So I decline with respect. BTW, I think reanimated released a major that will make this simpler to fix.

ShaMan123 avatar Oct 20 '21 19:10 ShaMan123

I saw #164 , don't remember what I did there

ShaMan123 avatar Oct 20 '21 19:10 ShaMan123