question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Description

1. Explain what you did

Implemented a slider to set a value.

2. What you expected to happen

Expect it to work perfectly (smoothly, value changes)

3. What actually happens

Value does change, but it’s super laggy.

Steps I took:

  • Tested out on both iOS 11 and Android 8.0, and the slider is lagging.
  • I tried out a couple other libraries for the slider
  • Switched to production mode on Expo, still lags.

react-native-elements version: ^0.16.0

Reproduction Steps and Sample Code

I used CRNA to create my app, so it’s currently running on Expo.

<Slider
minimumValue={1}
maximumValue={50}
minimumTrackTintColor={"#C6C6C4"}
maximumTrackTintColor={"#C6C6C4"}
step={1}
value={this.state.value}
// BUG: This causes the lagginess
// onValueChange={(value) => this.setState({value})}
trackStyle={styles.trackStyle}
thumbStyle={styles.thumbStyle}
/>

Solution

I have a temporary solution, that is to use onSlidingComplete instead of onValueChange. It works, but it just doesn’t update real time anymore, and I’m just wondering if there’s a better way.

Culprit

Found out that the culprit was the fact that the slider has to change its value as it moves.

I’m still currently in the process of fixing it, but I feel like this is probably my fault for not understanding react-native well enough. Appreciate any resources that anyone can point to!

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:6
  • Comments:13

github_iconTop GitHub Comments

19reactions
ujeenatorcommented, May 16, 2018

I’m reducing the number of updates with a timer

onValueChange={value => {
  clearTimeout(this.sliderTimeoutId)
  this.sliderTimeoutId = setTimeout(() => {
    this.setState({value})
  }, 20)
}}
4reactions
Norfeldtcommented, Jul 8, 2018

@xavier-villelegier debouncing workings, but I can’t get your code suggestion to work. I have to declare it in the constructor.

...
import { debounce } from lodash
...
  constructor(props){
    super(props)
    ...
    this.debounceUpdate = debounce( this.updateValue, 20 )
  }

  updateValue(value) {
    this.setState({ value })
  }

  ...
  render() {
    ...
    return (
      ...
      <Slider
        ...
        value={this.state.value}
        onValueChange={(value) => this.debounceUpdate(value)}
      />
    ...
  )}
Read more comments on GitHub >

github_iconTop Results From Across the Web

React Native slider is having lagging issue - Stack Overflow
Try this solution, you reduce the number of updates : onValueChange={value => { clearTimeout(this.sliderTimeoutId) this.
Read more >
P: Slider Lag - Adobe Support Community - 12249246
The screen doesn't start to redraw until I stop dragging the slider; there is about a 0.5 second or more delay before I...
Read more >
Has the volume slider lag issue been fixed? (SoundBlaster Z)
I recently bought an Aorus Z270-X Gaming 8 Mobo with a built-in Creative soundcard and I immediately noticed the laggy volume slider.
Read more >
Are Sliders always laggy? - UI - Unreal Engine Forums
Slilders seem to be always “laggy”. Simply create a slider, pick it with the mouse and move the nouse very slowly.
Read more >
WordPress Slider Slow to Load? Here's Why (and How to Fix It)
The first thing that could create problems with the image slider speed is your WordPress hosting. Bad hosting will make your website slow,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found