Giter VIP home page Giter VIP logo

Comments (22)

avkvak avatar avkvak commented on September 2, 2024 31

you can just wrap it with TouchableWithoutFeedback and gets coordinates when user tap.

tapSliderHandler = (evt) => { this.refs.slider.measure((fx, fy, width, height, px, py) => { this.setState({value: (evt.nativeEvent.locationX - px) / width}); })); }

<View ref="slider"> <TouchableWithoutFeedback onPressIn={this.tapSliderHandler}> <Slider value={this.state.value}/> </TouchableWithoutFeedback> </View>

it works for me

from react-native-slider.

avkvak avatar avkvak commented on September 2, 2024 3

@fadlykayo because react-native-slider takes its value from 0 (left edge) to 1 (right edge).
therefore we need to find the percentage of the completed area.
If user tapped on 61.16px from the edge of the slider with 360px width, it means that he pressed on the 0.17 part of the slider, so we can set the state of slider value

and yes, sorry for my english)

from react-native-slider.

rogerkerse avatar rogerkerse commented on September 2, 2024 3

It would be nice if it was built in and after pressing somewhere you could immediately start moving your finger to position slider more precisely

from react-native-slider.

twerff avatar twerff commented on September 2, 2024 2

@avkvak Thank you for this tip. This works great! Next up is to figure out how the the thumb will continue to be dragged after the user pressed the slider... Any ideas?

from react-native-slider.

fadlykayo avatar fadlykayo commented on September 2, 2024 1

@avkvak thank you for the detailed explanation. hope this also could help others.

from react-native-slider.

luisfuertes avatar luisfuertes commented on September 2, 2024

+1

from react-native-slider.

hugohow avatar hugohow commented on September 2, 2024

+1

from react-native-slider.

 avatar commented on September 2, 2024

+1

from react-native-slider.

jariwalabhavesh avatar jariwalabhavesh commented on September 2, 2024

+1

from react-native-slider.

gitDengXiao avatar gitDengXiao commented on September 2, 2024

avkvak . 666

from react-native-slider.

oliviachang29 avatar oliviachang29 commented on September 2, 2024

avkvak's solution works well - hoping you could put it into a PR?

from react-native-slider.

Ashi90 avatar Ashi90 commented on September 2, 2024

@avkvak , can you please let me know how it's work,
For me it always provide '0', I got following values
evt.nativeEvent.locationX = 61.17 (changeable on touch)
px = 0(always)
with = 360 (always)

So according to formula (evt.nativeEvent.locationX - px) / width
(61.17 - 0) / 360

from react-native-slider.

avkvak avatar avkvak commented on September 2, 2024

@Ashi90 , "px" is a just slider offset from the edge of the screen.
So we calculate exactly the part of the pressed slider, except white space

from react-native-slider.

Ashi90 avatar Ashi90 commented on September 2, 2024

@avkvak ,Ok "PX" is offset value from the edge of the screen, but what about others, I'm not getting the actual position of touch in slider.

from react-native-slider.

fadlykayo avatar fadlykayo commented on September 2, 2024

@Ashi90 have the same problem. not getting the actual position where I tap. did you already find any solution for this?

@avkvak could you maybe explain more about the formula? why you divide it with width?

from react-native-slider.

llphickman avatar llphickman commented on September 2, 2024

@avkvak Thank you for this tip. This works great! Next up is to figure out how the the thumb will continue to be dragged after the user pressed the slider... Any ideas?

Any progress on this?

from react-native-slider.

saeidee avatar saeidee commented on September 2, 2024

You can do something like this!

handelSliderTap = (event) => { 
    	this.refs.sliderWrapper.measure((fx, fy, width, height, px, py) => {
    		const completedDistance = ((event.nativeEvent.locationX - px) / width) * 100
                const completedDuration = (completedDistance * this.state.duration) / 100
    		...
    	})
    }

from react-native-slider.

rtt63 avatar rtt63 commented on September 2, 2024

Sadly this workaround causes an error on android to me
screen shot 2019-02-18 at 17 15 43

upd: it can be fixed by adding any style to <View ref="slider" />

from react-native-slider.

naveenprakash74 avatar naveenprakash74 commented on September 2, 2024

have look on pull request #164 it will be helpful for you

from react-native-slider.

Sleepful avatar Sleepful commented on September 2, 2024

here is @avkvak answer but with hooks, works by tapping, but not by tapping and dragging in the same gesture

const AddSlider = ({ setState, state }) => {
  const viewRef = useRef(null);
  const tapSliderHandler = (evt) => {
    if (viewRef.current) {
      viewRef.current.measure((fx, fy, width, height, px) => {
        const location = ((evt.nativeEvent.locationX - px) / width) * 100;
        setState(location);
      });
    }
  };
  return (
      <View ref={ viewRef }>
        <TouchableWithoutFeedback onPressIn={ tapSliderHandler }>
           <Slider value={state}>...
  ...);

from react-native-slider.

RageOfJustice avatar RageOfJustice commented on September 2, 2024

have look on pull request #164 it will be helpful for you

Seems like its not working

from react-native-slider.

naveenprakash74 avatar naveenprakash74 commented on September 2, 2024

have look on pull request #164 it will be helpful for you

Seems like its not working
If you are facing then comment i will try to resolve itπŸ™‚

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.