callstack / react-native-slider

React Native component exposing Slider from iOS and SeekBar from Android
MIT License
1.19k stars 267 forks source link

How to adjust the size of the thumb button #97

Open noecs opened 5 years ago

noecs commented 5 years ago
...
<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

harrydema commented 5 years ago

+1

bobber205 commented 4 years ago

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 :( )

OmarBasem commented 4 years ago

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

Eesssn commented 4 years ago

+1

kimmy-wang commented 4 years ago

+1

Cosmitar commented 4 years ago

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.

yesnoyes commented 4 years ago

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

VTrngNghia commented 4 years ago

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.

Cosmitar commented 4 years ago

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.

kgsachinthaudara commented 4 years ago

The team should need to give access to change thumb size

gxs1619 commented 4 years ago

Thumb size would be very useful to change as a property

defi-bear commented 4 years ago

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

arthur-vargas commented 3 years ago

+1

SamiChab commented 3 years ago

+1 for this feature !

vaionescu commented 3 years ago

+1

congtung98 commented 3 years ago

+1

antonsokolow commented 3 years ago

+1

afilp commented 3 years ago

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

qasim90 commented 3 years ago

Any plans on adding this feature?

edi commented 3 years ago

Bump :)

GiulioFede commented 3 years ago

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) %.

hammerstrike331 commented 2 years ago

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

nangbanmai1907 commented 2 years ago

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

izolotarev commented 1 year ago

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;
anasomar1 commented 8 months ago

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: "seeker@3x.png", scale: 3 }}

timbtimbtimb commented 7 months ago

+1

iostalks commented 7 months ago

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

lavisar commented 3 months ago

update Jun 26 2024, there still no props to custom Thumb Button size =(