Repository navigation
[Proposal] Delay Pressable press-in inside ScrollView - #60331
Conversation
janicduplessis
left a comment
There was a problem hiding this comment.
Interesting, I guess the main benifit vs using the pressDelay prop directly is that it will only happen when inside a scrollview.
Not sure how I feel about it being a feature flag as I wonder how much it will be used, but if plan is to turn it on by default after a release or 2 I think it's ok.
|
@janicduplessis Yes, the plan would be to enable it by default and remove the flag at some point. We can of course discuss about having it enabled by default, with the flag as an opt-out. Or even no flag at all. I can update the PR after feedbacks. |
| isInScrollView && | ||
| ReactNativeFeatureFlags.delayPressInInScrollView() | ||
| ? SCROLL_VIEW_PRESS_DELAY_MS | ||
| : unstable_pressDelay; |
There was a problem hiding this comment.
This is intended to be used to experiment with adding a delay for when
onPressInfires. The intended purpose of this delay is to preventPressableelements from activating (i.e.onPressInfiring) if a touch gesture is immediately canceled by an enclosing native component (e.g.ScrollView).
The fix mechanism existed in RN since 2020 😅. wdyt of keeping the feature flag default to true (opt-out instead of opt-in)? (one can also pass unstable_pressDelay 0 to opt-out)
There was a problem hiding this comment.
@intergalacticspacehighway I'd rather too! I will make the switch on monday.
Do you think a flag is necessary? Or we can just recommend setting unstable_pressDelay to 0 on all ScrollView?
We can even imagine removing the unstable_ prefix in a following PR, if it's that old (as delayPressIn)
javache
left a comment
There was a problem hiding this comment.
This is an ok workaround - the real fix would require us (like rn-gesture-handler?) to declare these gesture handler relations up front so we can run / evaluate them synchronously.
| const delayPressIn = | ||
| unstable_pressDelay == null && | ||
| isInScrollView && | ||
| ReactNativeFeatureFlags.delayPressInInScrollView() | ||
| ? SCROLL_VIEW_PRESS_DELAY_MS | ||
| : unstable_pressDelay; |
There was a problem hiding this comment.
This seems reasonable to me - I think we can also push to deprecate/remove unstable_pressDelay after this, since this doing it conditionally based on a containing scrollview is better.
There was a problem hiding this comment.
@javache I agree, we should map it as delayPressIn prop. I can open the PR once this one is merged.
| const isInScrollView = useContext(ScrollViewContext) != null; | ||
|
|
||
| const delayPressIn = | ||
| unstable_pressDelay == null && |
There was a problem hiding this comment.
Let's document that you can opt-out of this behaviour by setting unstable_pressDelay={0}
|
Can you rebase past the ReactNativeFeatureFlags conflicts? |
# Conflicts: # packages/react-native/src/private/featureflags/ReactNativeFeatureFlags.js
4f68877 to
e9baaaa
Compare
|
@javache Done ✅ |
|
@javache has imported this pull request. If you are a Meta employee, you can view this in D135928009. |
Summary:
This is a proposal. Feel free to close it if this is not the direction you want for
Pressable.PressablecallsonPressInas soon as the finger touches it. When the touch turns into a scroll, the press feedback flashes on every item the finger lands on. It creates this kind of issue (compared to RNGHTouchable).This adds a JS-only flag,
delayPressInInScrollView. When it is on, aPressableinside aScrollViewwaits 130 ms beforeonPressIn(the same delay as the highlight delay of the legacyTouchablemixin). If the scroll view takes the touch during the delay, no press callback fires. An explicitunstable_pressDelaystill wins.Changelog:
[GENERAL] [ADDED] - Add
delayPressInInScrollViewfeature flag to delayPressablepress-in inside aScrollViewTest Plan:
To try it, turn on the flag in the entry file:
Then start a scroll on a tile. The tile no longer turns red:
On an Android emulator (RN 0.88.1 with the same patch), fast and slow scrolls no longer fire
onPressIn. Taps and long holds still work. This matchesTouchablefromreact-native-gesture-handler3.4.