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

How to adjust the size of the thumb button

Open noecs opened this issue 4 years ago • 28 comments

...
<Slider
    style={styles.scheduleBar}
    minimumValue={0}
    maximumValue={120}
    minimumTrackTintColor="#FFFFFF"
    maximumTrackTintColor="#000000"
    thumbImage={'../styles/dark/dot.png'}
    step={1}
 />
...

How to adjust the size of the thumb button,I checked the issue and found no useful information. Now it works on my page, but the thumb button is too big and looks very ugly

noecs avatar Aug 16 '19 07:08 noecs

+1

harrydema avatar Aug 23 '19 16:08 harrydema

I've found it'll be whatever the size of your image natively is -- reduce the image dimensions and it'll go down in the app too (bad solution I know :( )

bobber205 avatar Oct 07 '19 18:10 bobber205

I think there should be a prop for the thumb size. This is very basic.

OmarBasem avatar Jan 21 '20 07:01 OmarBasem

+1

Eesssn avatar Feb 12 '20 05:02 Eesssn

+1

kimmy-wang avatar Mar 01 '20 06:03 kimmy-wang

I'm solving this issue using an icon as image since I have installed react-native-vector-icons.

Icon.getImageSource('circle', 15, 'white')
   .then(source => this.setState({ thumbIcon: source }));

later in Slider component

<Slider
   ...
   thumbImage={this.state.thumbIcon}
/>

The thumb shows the size and color specified on getImageSource method.

Cosmitar avatar Mar 27 '20 21:03 Cosmitar

transform: [{scaleX: 0.3}, {scaleY: 0.3}],

yesnoyes avatar May 23 '20 11:05 yesnoyes

I'm solving this issue using an icon as image since I have installed react-native-vector-icons.

Icon.getImageSource('circle', 15, 'white')
   .then(source => this.setState({ thumbIcon: source }));

later in Slider component

<Slider
   ...
   thumbImage={this.state.thumbIcon}
/>

The thumb shows the size and color specified on getImageSource method.

This didn't work for me. getImageSource() gets called indefinitely and caused my app UI to be completely blocked.

VTrngNghia avatar Jun 04 '20 02:06 VTrngNghia

I'm solving this issue using an icon as image since I have installed react-native-vector-icons.

Icon.getImageSource('circle', 15, 'white')
   .then(source => this.setState({ thumbIcon: source }));

later in Slider component

<Slider
   ...
   thumbImage={this.state.thumbIcon}
/>

The thumb shows the size and color specified on getImageSource method.

This didn't work for me. getImageSource() gets called indefinitely and caused my app UI to be completely blocked.

Maybe you're calling Icon.getImageSource into render function? try something like

import React, { useState, useEffect } from 'react';

const MyComponent = () => {
  const [icon, setIcon] = useState();

  useEffect(() => {
    Icon.getImageSource('circle', 15, 'white')
     .then(setIcon);
  }, []);

  <Slider
    ...
    thumbImage={icon}
  />
};

or use the equivalent componentDidMount in class component approach. The idea is that getImageSource's callback is affecting the state and render the component again, so move Icon.getImageSource() call outside the render loop.

Cosmitar avatar Jun 04 '20 18:06 Cosmitar

The team should need to give access to change thumb size

kgsachinthaudara avatar Jul 08 '20 15:07 kgsachinthaudara

Thumb size would be very useful to change as a property

gxs1619 avatar Aug 06 '20 17:08 gxs1619

use this https://github.com/Shing-Ho/react-native-slider

Shing-Ho avatar Sep 10 '20 02:09 Shing-Ho

+1

arthur-vargas avatar Oct 07 '20 20:10 arthur-vargas

+1 for this feature !

SamiChab avatar Nov 13 '20 14:11 SamiChab

+1

vaionescu avatar Nov 15 '20 05:11 vaionescu

+1

congtung98 avatar Nov 17 '20 10:11 congtung98

+1

antonsokolow avatar Jan 21 '21 17:01 antonsokolow

Please add this feature, it is very important. Thanks.

afilp avatar Feb 22 '21 18:02 afilp

Any plans on adding this feature?

qasim90 avatar Apr 07 '21 07:04 qasim90

Bump :)

edi avatar May 04 '21 21:05 edi

This is my solution for those who do not want to use external libraries for any reason (for example the homonymous react-native-vector-icons of Expo does not support the Icon.getImage method):

import { ... , Platform } from 'react-native'
let containerHeight = ...  // this is the height of the area inside which you will insert the slider

<View style={{flex:1, height: containerHeight}}>
      <View style={
                   {
                       height: containerHeight, 
                       transform: [{ scaleX: Platform.OS=="ios"?0.5:1 }, { scaleY: Platform.OS=="ios"?0.5:1 }]}}>
                            <Slider
                                value = {...}
                                onValueChange = {...}
                                style={
                                     {
                                          flex:1, 
                                          height: containerHeight , 
                                          width: Platform.OS=="ios"?"200%":"100%", 
                                          alignSelf:"center"
                                     }
                                }
                                thumbTintColor="..."
                                ...
                            />
       </View>
</View>

For my app it was fine that the icon was scaled by half, so I applied a scale of 0.5 and a width of 200%. In general, given a scale of x, apply a width of 100 * (1 / x) %.

GiulioFede avatar Sep 05 '21 09:09 GiulioFede

I suggest below plugin. this is perfect work for me. https://github.com/miblanchard/react-native-slider

hammerstrike331 avatar Nov 04 '21 06:11 hammerstrike331

The answer is pretty simple just provide the thumbStyle prop with a width and height, here is an example:

<Slider
        style={styles.slider}
        minimumValue={0}
        maximumValue={1}
        minimumTrackTintColor="#00296B"
        maximumTrackTintColor="#C4C4C4"
        thumbTintColor="#00296B"
        thumbStyle={{width: 15, height: 15}}
/>

Rohan-Rajesh avatar Dec 12 '21 08:12 Rohan-Rajesh

thumbImage={require('link_img')} it work for me!

nangbanmai1907 avatar Aug 15 '22 08:08 nangbanmai1907

This is my solution for those who do not want to use external libraries for any reason (for example the homonymous react-native-vector-icons of Expo does not support the Icon.getImage method):

import { ... , Platform } from 'react-native'
let containerHeight = ...  // this is the height of the area inside which you will insert the slider

<View style={{flex:1, height: containerHeight}}>
      <View style={
                   {
                       height: containerHeight, 
                       transform: [{ scaleX: Platform.OS=="ios"?0.5:1 }, { scaleY: Platform.OS=="ios"?0.5:1 }]}}>
                            <Slider
                                value = {...}
                                onValueChange = {...}
                                style={
                                     {
                                          flex:1, 
                                          height: containerHeight , 
                                          width: Platform.OS=="ios"?"200%":"100%", 
                                          alignSelf:"center"
                                     }
                                }
                                thumbTintColor="..."
                                ...
                            />
       </View>
</View>

For my app it was fine that the icon was scaled by half, so I applied a scale of 0.5 and a width of 200%. In general, given a scale of x, apply a width of 100 * (1 / x) %.

That is a good solution! Thanks! It really helped. I tried a few other slider packages and most of them suck. Based on your solution I have written a Wrapper that fixes this issue.

import Slider, { SliderProps } from '@react-native-community/slider';
import { View, Platform } from 'react-native';

type SliderWrapperProps = SliderProps & { scaleIOS: number; scaleAndroid: number; height: number };

function SliderWrapper(props: SliderWrapperProps) {
  const { scaleIOS, scaleAndroid, height } = props;
  const widthIOS = 100 * (1 / scaleIOS);
  const widthAndroid = 100 * (1 / scaleAndroid);

  return (
    <View style={{ width: '100%', height }}>
      <View
        style={{
          height,
          transform: [
            { scaleX: Platform.OS === 'ios' ? scaleIOS : scaleAndroid },
            { scaleY: Platform.OS === 'ios' ? scaleIOS : scaleAndroid },
          ],
        }}>
        <Slider
          {...props}
          style={{
            flex: 1,
            height,
            width: Platform.OS === 'ios' ? `${widthIOS}%` : `${widthAndroid}%`,
            alignSelf: 'center',
          }}
        />
      </View>
    </View>
  );
}

export default SliderWrapper;

izolotarev avatar Sep 06 '23 14:09 izolotarev

I am using a local URI image on iOS and I found out that you can pass a scale, which helped me change the size. You also can pass width and height but that doesn't seem to do anything.

thumbImage={{ uri: "[email protected]", scale: 3 }}

anasomar1 avatar Jan 15 '24 09:01 anasomar1

+1

timbtimbtimb avatar Feb 16 '24 20:02 timbtimbtimb

Rename local file image with @3x, image will scale itself.

iostalks avatar Feb 28 '24 06:02 iostalks