Giter Club home page Giter Club logo

Comments (27)

OmarBasem avatar OmarBasem commented on May 24, 2024 59

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

from react-native-slider.

yesnoyes avatar yesnoyes commented on May 24, 2024 31

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

from react-native-slider.

Cosmitar avatar Cosmitar commented on May 24, 2024 26

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.

from react-native-slider.

Cosmitar avatar Cosmitar commented on May 24, 2024 16

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.

from react-native-slider.

afilp avatar afilp commented on May 24, 2024 14

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

from react-native-slider.

GiulioFede avatar GiulioFede commented on May 24, 2024 7

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

from react-native-slider.

edi avatar edi commented on May 24, 2024 3

Bump :)

from react-native-slider.

hammerstrike331 avatar hammerstrike331 commented on May 24, 2024 2

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

from react-native-slider.

kgsachinthaudara avatar kgsachinthaudara commented on May 24, 2024 1

The team should need to give access to change thumb size

from react-native-slider.

gxs1619 avatar gxs1619 commented on May 24, 2024 1

Thumb size would be very useful to change as a property

from react-native-slider.

nangbanmai1907 avatar nangbanmai1907 commented on May 24, 2024 1

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

from react-native-slider.

izolotarev avatar izolotarev commented on May 24, 2024 1

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;

from react-native-slider.

anasomar1 avatar anasomar1 commented on May 24, 2024 1

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 }}

from react-native-slider.

harrydema avatar harrydema commented on May 24, 2024

+1

from react-native-slider.

bobber205 avatar bobber205 commented on May 24, 2024

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

from react-native-slider.

Eesssn avatar Eesssn commented on May 24, 2024

+1

from react-native-slider.

kimmy-wang avatar kimmy-wang commented on May 24, 2024

+1

from react-native-slider.

VTrngNghia avatar VTrngNghia commented on May 24, 2024

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.

from react-native-slider.

Shing-Ho avatar Shing-Ho commented on May 24, 2024

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

from react-native-slider.

arthur-vargas avatar arthur-vargas commented on May 24, 2024

+1

from react-native-slider.

SamiChab avatar SamiChab commented on May 24, 2024

+1 for this feature !

from react-native-slider.

vaionescu avatar vaionescu commented on May 24, 2024

+1

from react-native-slider.

congtung98 avatar congtung98 commented on May 24, 2024

+1

from react-native-slider.

antonsokolow avatar antonsokolow commented on May 24, 2024

+1

from react-native-slider.

qasim90 avatar qasim90 commented on May 24, 2024

Any plans on adding this feature?

from react-native-slider.

timbtimbtimb avatar timbtimbtimb commented on May 24, 2024

+1

from react-native-slider.

iostalks avatar iostalks commented on May 24, 2024

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

from react-native-slider.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.