onValueChanges is called on programmatic value changes on Android
See original GitHub issueEnvironment
System: OS: macOS 11.6 CPU: (16) x64 Intel® Core™ i9-9980HK CPU @ 2.40GHz Memory: 1.06 GB / 32.00 GB Shell: 5.8 - /bin/zsh Binaries: Node: 14.16.0 - /var/folders/21/5xmhgtlx4bj0gthrmm8tm3zc0000gq/T/yarn–1657226700390-0.0757475079991885/node Yarn: 1.22.11 - /var/folders/21/5xmhgtlx4bj0gthrmm8tm3zc0000gq/T/yarn–1657226700390-0.0757475079991885/yarn npm: 6.14.11 - ~/.nvm/versions/node/v14.16.0/bin/npm Watchman: 2021.09.13.00 - /usr/local/bin/watchman Managers: CocoaPods: 1.11.2 - /Users/eueddemkim-new/.rbenv/shims/pod SDKs: iOS SDK: Platforms: DriverKit 21.2, iOS 15.2, macOS 12.1, tvOS 15.2, watchOS 8.3 Android SDK: API Levels: 30, 31 Build Tools: 30.0.2, 31.0.0 Android NDK: Not Found IDEs: Android Studio: 2020.3 AI-203.7717.56.2031.7784292 Xcode: 13.2.1/13C100 - /usr/bin/xcodebuild Languages: Java: 1.8.0_292 - /usr/bin/javac Python: 2.7.16 - /usr/bin/python npmPackages: @react-native-community/cli: Not Found react: 16.13.1 => 16.13.1 react-native: 0.63.4 => 0.63.4 react-native-macos: Not Found npmGlobalPackages: react-native: Not Found
Description
The doc says,
onValueChanges: Callback continuously called while the user is dragging the slider.
It works as expected on iOS device and simulators, but on Android devices(tested with Pixel 3 XL, Android 11), onValueChanges
is called on every value changes, even from setState
.
I’m on latest 4.2.4 version.
"@react-native-community/slider": "^4.2.4",
Reproducible Demo
const [state, setState] = useState(0);
const onValueChange = (value: number) => {
console.log("onValueChange invoked", value);
};
.... (do state change after some time interval) ...
<Slider
minimumValue={0}
maximumValue={100}
step={1}
value={state}
onValueChange={onValueChange}
/>
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:7 (1 by maintainers)
Top GitHub Comments
I used
onSlidingComplete
instead, works fine.onSlidingComplete
doesn’t seem to get called on Android when using accessibilty controls to adjust the slider, onlyonValueChange
.So unfortunately from what I can tell, having a slider that has some programmatic control (e.g. the seek bar on a playing video) isn’t currently compatible with using accessibility controls on the slider.