-
Notifications
You must be signed in to change notification settings - Fork 25k
Description
There is a problem handling quick succession of touches / clicks. This can be categorised as a performance issue.
Use case:
- user clicks multiple times and quickly on a button
- events handled in JS by some click handler function which performs a navigation event
- by the time the navigation event gets completed (some screen is pushed, for example, which hides the button) 2 more clicks was already on their way and this same screen gets pushed multiple times
This is not a react-native specific problem but it gets compounded by the fact all touch events originate in the native's main thread, dispatched through the bridge asynchronously along with some serialisation mechanism and handled in the JS context (in a different thread).
This is very much like the problem with Android's startActivity(Intent) which is async, and, if the pushed screen takes too much time to appear, can cause this "batching" of events.
I would appreciate your thoughts on this matter and how do you think it can be handled (with minimum hacks in mind).
Some example solutions:
- When receiving the event immediately ignore all other events (save something in the state) and enable it back once finished - this is hacky, difficult to maintain, causes the codebase to be a ball of mud, and not alway be possible.
- add a new prop to all buttons (TouchableHighlight, TouchableOpacity etc) that will be called
throttle. When you specifythrottle=1000the button will do something like
_.throttle(onClick, 1000, {leading:true, trailing:false})
which just sends the first event and ignores all other touch events on this specific button in a 1000 millisecond window. See lodash throttle
This is also hacky but much simpler to maintain.
Using react-native 0.25.1.
Happens on all platforms.