Giter Club home page Giter Club logo

Comments (5)

sa2812 avatar sa2812 commented on May 28, 2024 2

2 years too late, but thanks for the inspiration @nuttylord! The onLayout method on View is triggered when the key changes, so I updated changed the following element in CircularSlider.js to:

<View key={scrollY} style={...} onLayout={this.onLayout}>

I also added a PropType of number for scrollY, which I'm passing directly into the <CircularSlider scrollY={...} component where I'm calling it.

Finally, I'm using onScroll on the ScrollView to update the state with the current y-value, thus making sure that the centre of the circle is always updated correctly!

Using onScroll is a bit problematic if you want the exact scroll location as discussed on StackOverflow, but I'm happy with the results with onScroll

from react-native-circular-slider.

nuttylord avatar nuttylord commented on May 28, 2024 1

i noticed that in the setCircleCenter() function the py value was what wasnt being updated properly but that px was set correctly so i made py to be a function of px as shown in my below snippet.

For my use case this works, maybe you can find something similar.

A suggestion would be to find some way to call this.setCircleCenter(); after all rendering is complete, maybe onResponderGrant, but this would be a state change and cause rendering.

  onLayout = () => {
    this.setCircleCenter();
  }

  setCircleCenter() {
    this._circle.measure((x, y, w, h, px , py) => {
      const halfOfContainer = this.getContainerWidth() / 2;

      this.setState({ circleCenterX: px + halfOfContainer, circleCenterY: px - (px/2.4) + halfOfContainer }); 
    });
  }

from react-native-circular-slider.

quangtruong16994 avatar quangtruong16994 commented on May 28, 2024 1

I found solution for my case too. I put circular slider in horizontal ScrollView, so px was wrong value, just px subtracts total previous items width, and it works fine 😁

from react-native-circular-slider.

nuttylord avatar nuttylord commented on May 28, 2024

I have figured out that the issue is caused by the sliders initial containerWidth being called asynchronously at the same time as the rendering of the SVG elements. the setState() on line 134 of circularSlider.js (inside the setCircleCenter() function) needs to complete before the component is mounted.

from react-native-circular-slider.

quangtruong16994 avatar quangtruong16994 commented on May 28, 2024

do you have any solutions?

from react-native-circular-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.