react-native-ui-lib
react-native-ui-lib copied to clipboard
Wheelpicker performance issues
Description
When inserting a list with >30 label-value pairs, the WheelPicker becomes almost unresponsive and slow.
Related to
- [x] Components
- [ ] Demo
- [ ] Docs
- [ ] Typings
Steps to reproduce
- Create a Wheelpicker component in your return statement.
- Insert a list with more than 30 label-value pairs.
- Open the app and try scrolling through the WheelPicker.
- Lagging should be noticeable.
Expected behaviour
The WheelPicker should be easy to use and scroll smoothly.
Actual behaviour
The WheelPicker is lagging, causing confusion and incorrect feedback.
More Info
The issue seems to reside with the component assigning an event's contentOffset.y to a SharedValue offset on every scroll.
On their own, whether assigning a constant value to the SharedValue or logging contentOffset.y on every scroll, doesn't seem to impact performance.
My conclusion is that assigning an ever-changing variable to offset leads somehow to a behaviour which internally that messes with the rendering, causing stuttering.
How to remove lag
- Go to node_modules/react-native-ui-lib/src/components/WheelPicker/index.js
- Find the constant scrollHandler in index.js
- comment out the following line:
offset.value = e.contentOffset.y;
Code snippet
const range = (min, max) => {
console.log(min, max, "minmax")
var range = new Array(max-min)
for(let i=min; i <= max; i++)
range[i-min] = i
return range.map(value => {return {label: value.toString(), value}})
}
const fieldRange = useMemo(()=>range(dialogOptions.min, dialogOptions.max), [])
.
.
.
<WheelPicker
numberOfVisibleRows={5}
initialValue={'0'}
items={fieldRange}>
</WheelPicker>
Screenshots/Video
Expected behaviour:
Actual behaviour:
Environment
- React Native version: 0.70.5
- React Native UI Lib version: ^7.18.3
Affected platforms
- [x] Android
- [ ] iOS
- [ ] Web
Hi @Excustic,
I've looked at the #3026 PR, however I cannot reproduce this in our demo app using the example. Any chance you have a reproduction scenario in our demo app or another project I can look at?
BTW, the attached gif looks like there's a Dialog (or some other component) involved, if so it should be included in the example.