Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slider with minimumValue > 0 doesn't move #10253

Closed
iKettles opened this issue Oct 5, 2016 · 1 comment
Closed

Slider with minimumValue > 0 doesn't move #10253

iKettles opened this issue Oct 5, 2016 · 1 comment
Labels
Resolution: Locked This issue was locked by the bot.

Comments

@iKettles
Copy link

iKettles commented Oct 5, 2016

Issue Description

Using the React Native Slider works fine with a minimum value of 0. With a minimum value above 0, the slider doesn't respect the value set and places the thumb to the beginning of the slider. This prevents the thumb from being moved.

Steps to Reproduce / Code Snippets

With a minimum value of 0, this works and allows the thumb to be moved. With a value higher than 0 the thumb will be locked to the start of the slider.

import React, { 
  Component
} from 'react'

import {
  Slider,
  View
} from 'react-native';

export default class RangeSlider extends React.Component {
  constructor (props) {
    super(props)
  }

  render () {
    return (
      <View>
        <Slider 
          maximumValue={10}
          minimumValue={1} 
          stepValue={0.1} 
          value={4}
          />
      </View>
    )
  }
}

Expected Results

The thumb should be able to move with a minimum value above 0

Additional Information

  • React Native version: 0.34.1
  • Platform(s) (iOS, Android, or both?): Android
  • Operating System (macOS, Linux, or Windows?): macOS
@reneweb
Copy link
Contributor

reneweb commented Oct 6, 2016

The problem is in ReactSlider.java when calculating the step value: https://github.com/facebook/react-native/blob/master/ReactAndroid/src/main/java/com/facebook/react/views/slider/ReactSlider.java#L94

What happens is that before the maxValue property gets set, the minValue one will get set and causes the updateAll method to be called. If at the same time the step is zero and we therefore calculate it, the minValue will be greater zero and the maxValue will be zero resulting in a negative step value.

To work around this you need to provide the step value yourself, which you are trying to, but the name is just step not stepValue.
So, this should work:

import React, { 
  Component
} from 'react'

import {
  Slider,
  View
} from 'react-native';

export default class RangeSlider extends React.Component {
  constructor (props) {
    super(props)
  }

  render () {
    return (
      <View>
        <Slider 
          maximumValue={10}
          minimumValue={1} 
          step={0.1} 
          value={4}
          />
      </View>
    )
  }
}

I will also add a pr to fix the issue when the step is indeed 0.

reneweb added a commit to reneweb/react-native that referenced this issue Oct 11, 2016
This causes the step to be re-calculated on every update of min, max and step value,
to use the most up to date values for the calculation,
except if step is explicitly set to a non-zero value by the user.

Fixes facebook#10253
reneweb added a commit to reneweb/react-native that referenced this issue Oct 11, 2016
This causes the step to be re-calculated on every update of min, max and step value,
to use the most up to date values for the calculation,
except if step is explicitly set to a non-zero value by the user.

Fixes facebook#10253
reneweb added a commit to reneweb/react-native that referenced this issue Oct 11, 2016
This causes the step to be re-calculated on every update of min, max and step value,
to use the most up to date values for the calculation,
except if step is explicitly set to a non-zero value by the user.

Fixes facebook#10253
reneweb added a commit to reneweb/react-native that referenced this issue Oct 11, 2016
This causes the step to be re-calculated on every update of min, max and step value,
to use the most up to date values for the calculation,
except if step is explicitly set to a non-zero value by the user.

Fixes facebook#10253
reneweb added a commit to reneweb/react-native that referenced this issue Oct 11, 2016
This causes the step to be re-calculated on every update of min, max and step value,
to use the most up to date values for the calculation,
except if step is explicitly set to a non-zero value by the user.

Fixes facebook#10253
DanielMSchmidt pushed a commit to DanielMSchmidt/react-native that referenced this issue Jan 4, 2017
Summary:
This causes the step to be re-calculated on every update of min, max and step value,
to use the most up to date values for the calculation,
except if step is explicitly set to a non-zero value by the user.

Fixes facebook#10253

**Test plan (required)**
1. Create example app
2. Create a view with a slider that has a `value`, `minimumValue` and `maximumValue` set, but no step value (or step value set to 0).

   For example:

   ```
   <Slider
       maximumValue={10}
       minimumValue={1}
       value={4}
       />
   ```
3. See slider working as expected
Closes facebook#10343

Differential Revision: D4142646

Pulled By: hramos

fbshipit-source-id: a0df87bbdbbd4b2a291d89f5579f73f517a33dfc
@facebook facebook locked as resolved and limited conversation to collaborators May 24, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jul 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

3 participants