Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

be able to use color gradient in minimumTrackTintColor #99

Open
ViktorAksionov opened this issue Jan 15, 2018 · 29 comments
Open

be able to use color gradient in minimumTrackTintColor #99

ViktorAksionov opened this issue Jan 15, 2018 · 29 comments

Comments

@ViktorAksionov
Copy link

ViktorAksionov commented Jan 15, 2018

Right now it possible to use only 1 color, but not a list of colors which can create a nice gradient when user drag a slider thumb

@alekspickle
Copy link

Any update on this?

@emmanuellmota
Copy link

emmanuellmota commented Jun 29, 2018

@ViktorAksionov @alexgnatrow @sidd123456

Use this fork: https://github.com/emmanuellmota/react-native-slider

Ex:

<Slider
  minimumValue={1}
  maximumValue={100}
  step={1}
  customMinimumTrack={(
    <LinearGradient
      start={{x: .74, y: .26}}
      end={{x: 0, y: .77}}
      colors={['#ff8960', '#ff62a5']}
      style={{
        width: '100%',
        height: '100%',
      }}
    />
  )}
  customMaximumTrack={(
    <LinearGradient
      start={{x: .74, y: .26}}
      end={{x: 0, y: .77}}
      colors={['#efefef', '#c1c0c9']}
      style={{
        width: '100%',
        height: '100%',
      }}
    />
  )}
  customThumb={(
    <LinearGradient
      start={{x: .74, y: .26}}
      end={{x: 0, y: .77}}
      colors={['#ff8960', '#ff62a5']}
      style={{
        width: 36,
        height: 36,
        margin: 2,
        borderRadius: 36 / 2,
        borderWidth: 4,
        borderColor: '#fff',
        elevation: 1
      }}
    />
  )}
/>

@nikasvan
Copy link

nikasvan commented Jul 2, 2018

@emmanuellmota I get this error when I implemented your fork https://cl.ly/0V2e450y3d1g

@nikasvan
Copy link

nikasvan commented Jul 2, 2018

Any suggestions?

@emmanuellmota
Copy link

@nikasvan You can share your code?

@nikasvan
Copy link

nikasvan commented Jul 5, 2018

Hey @emmanuellmota thanks for the answer. Sorry just saw the comment. here is my code
https://cl.ly/3X101S0M0T3A

@nikasvan
Copy link

nikasvan commented Jul 5, 2018

The bug goes away when I remove custom props. customMinimumTrack, customMaximumTrack and customThumb. Is there something I am doing wrong?

@nikasvan
Copy link

nikasvan commented Jul 5, 2018

Hey @emmanuellmota checked out the example that you commited 2 days ago and it seems to work, thanks :)

@lucasriondel
Copy link

@emmanuellmota could you make a pull request ?

@ViktorAksionov
Copy link
Author

ViktorAksionov commented Sep 16, 2018

As I can see you used https://github.com/react-native-community/react-native-linear-gradient for gradient.
That is required to link code and it will force author to publish as major version.

I can describe approach which I implemented in my project and which in reality gives very nice visual effect, so anyone can use the same idea.

Right now we already have minimumTrackTintColor, so on each drag of thumb we can constantly change color there.

For example if we have range [min, max] with step equal to step then you can in advance generate an array of colors with size of (max - min) / step,
like(copy/paste from my code):

...
import transition from 'some path';
...

this.gradientList = transition(
   this.props.fromGradientColor || '#FFFFFF', // from white
   this.props.toGradientColor || '#000000', // till black
   (this.props.max - this.props.min) / this.props.step,
);

and then use minimumTrackTintColor={this.gradientList[value - min]}

that is it.

@emmanuellmota
Copy link

@ViktorAksionov

Not necessarily, you can use any component, leaving it to whoever is developing, in the example above I used the react-native-linear-gradient, because the question was around the gradient, which I agree with if it is just for the gradient, your code is the correct one, however my alteration was just so you can use the custom component, an SVG for example as a thumb or track.

@lucasriondel
Copy link

@jeanregisser what's your point of view on this ?

@tuannkop
Copy link

tuannkop commented Oct 9, 2018

@nikasvan thank u so much , its working good :D

@tuannkop
Copy link

tuannkop commented Oct 12, 2018

@nikasvan its working good on ios but on android stlyle height customtrack seem not working .

@cspicuzza
Copy link

cspicuzza commented Dec 4, 2018

It would be fantastic if these custom component features for track and thumb were merged into this repo 🙏

@huydophu
Copy link

customMinimumTrack

hi man, we already implemented your suggestion but nothing happen! Is there anything we have to add or remove to make the attribute "customMinimumTrack" work?

@huydophu
Copy link

Hey @emmanuellmota checked out the example that you commited 2 days ago and it seems to work, thanks :)

@nikasvan I also implemented the code like yours but it seems not recognize the attribute "customMinimumTrack", could you please show me your work or tell me what should do more to make it work? Many thanks.

@andriko007
Copy link

@emmanuellmota I implemented the code with customThumb but nothing happened.

<Slider
                    style={{width: 185, height: 80}}
                    minimumValue={this.state.min}
                    maximumValue={this.state.max}
                    value={this.state.min}
                    onValueChange={(value)=> this.setState({ slideValue: value}) }
                    maximumTrackTintColor='transparent'
                    minimumTrackTintColor={colors.primary}
                    customThumb={<View
                      style={{
                        width: 50,
                        height: 80,
                        backgroundColor: colors.primary,
                        borderBottomRightRadius: 100,
                        borderTopRightRadius: 100,
                      }}
                    />}
                    trackStyle={styles.track}
                    step={1}
                />

@andriko007
Copy link

I need thumb like circle with text, in my code I just tried to get circle but have only standard thumb

@emmanuellmota
Copy link

@emmanuellmota I implemented the code with customThumb but nothing happened.

<Slider
                    style={{width: 185, height: 80}}
                    minimumValue={this.state.min}
                    maximumValue={this.state.max}
                    value={this.state.min}
                    onValueChange={(value)=> this.setState({ slideValue: value}) }
                    maximumTrackTintColor='transparent'
                    minimumTrackTintColor={colors.primary}
                    customThumb={<View
                      style={{
                        width: 50,
                        height: 80,
                        backgroundColor: colors.primary,
                        borderBottomRightRadius: 100,
                        borderTopRightRadius: 100,
                      }}
                    />}
                    trackStyle={styles.track}
                    step={1}
                />

I need thumb like circle with text, in my code I just tried to get circle but have only standard thumb

@andriko007, check if you are using my fork: https://github.com/emmanuellmota/react-native-slider

Take a look this example at Expo: https://snack.expo.io/@emmanuellmota/custom-slider

@andriko007
Copy link

@emmanuellmota thanks, it was my mistake. Now I have problem with animation, slider is too slow animation. Is there a way to make animation faster and smoother?
My animation example

What I expected

Here is my code:

<Slider
            style={{width: 150, height: 80}}
            minimumValue={50}
            maximumValue={100}
            value={50}
            maximumTrackTintColor='transparent'
            minimumTrackTintColor={colors.primary}
            onValueChange={(value)=> this.props.onSetQuantity({index: this.props.index, value: value}) }
            thumbStyle={{
    width: width 40,
    height: 80,
    backgroundColor: colors.primary,
    borderBottomRightRadius:100,
    borderTopRightRadius: 100
    justifyContent: 'center',
    alignItems: 'center'}}
            trackStyle={{height: 80,
    borderBottomRightRadius: 20,
    borderTopRightRadius: 20,}}
            step={1}
            animationConfig={Animated.timing({useNativeDriver: true})}
            animateTransitions={true}
          />

@emmanuellmota
Copy link

@andriko007, I've tested my example above, and is running smooth, here we have best practices to implement smooth animations in you React Native app: https://facebook.github.io/react-native/docs/performance, https://codeburst.io/butter-smooth-animations-in-react-native-93a3b86adf1

@andriko007
Copy link

@emmanuellmota So, can I implement this practices with animationConfig? I tried to change this config but nothing happened, may be I did something wrong?
animationConfig={Animated.timing({useNativeDriver: true})}

@emmanuellmota
Copy link

@andriko007, I made one change in my folk, added useNativeDriver, you can download again and check if is run smooth.

@andriko007
Copy link

@emmanuellmota Unfortunately it didn't help

@emmanuellmota
Copy link

@andriko007, my example that I mentioned above, runs well, or is it also slow?

@andriko007
Copy link

@emmanuellmota Yes, your example work well. I can't understand, why slider get slow(it seems like low fps) in my example

@emmanuellmota
Copy link

@andriko007, you can separate all components that you are using, and go adding one by one, to know which makes slow.

@bcosma
Copy link

bcosma commented Jul 3, 2019

@emmanuellmota I have an issue when enabling animateTransitions. I get an error: “Style property ‘width’ is not supported by native animated module”. Do you know what could be the problem? I am testing on the iOS simulator.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants