rn-range-slider
rn-range-slider copied to clipboard
InteractionManager.runAfterInteractions not running after using RangeSlider component
Description
InteractionManager.runAfterInteractions's callback is not called after RangeSlider component is rendered at least once.
Version
2.2.2
Steps to reproduce
- Render
RangeSlidercomponent. - Use
InteractionManager.runAfterInteractions(callback). It doesn't matter ifRangeSlideris unmounted or not. InteractionManager.runAfterInteractions's callback is not called.
Cause
The package uses PanResponder which holds an InteractionManager handle to block long-running JS events from interrupting active gestures. Basically blocks all InteractionManager.runAfterInteractions's callbacks until the interaction handle is cleared.
In this package PanResponder's instance is created using useMemo and is re-created during each ongoing gesture (because its dependencies change) which causes the interaction handle's reference to be orphaned without being cleared.
Solution
Switch from useMemo to useRef as shown in React Native docs (https://reactnative.dev/docs/panresponder#usage-pattern).
(https://github.com/githuboftigran/rn-range-slider/pull/150) Fixed this problem here