Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions apps/common-app/src/new_api/tests/nestedTouchables/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export default function NestedTouchablesExample() {
const [log, setLog] = useState<string[]>([]);

const pushLog = (message: string) => {
console.log(message);
setLog((prev) =>
[...prev, `[${new Date().toLocaleTimeString()}] ${message}`].slice(-6)
);
Expand All @@ -20,11 +21,13 @@ export default function NestedTouchablesExample() {
const outerTap = useTapGesture({
runOnJS: true,
onActivate: () => pushLog('outer tap gesture'),
testID: 'outer-tap',
});

const innerTap = useTapGesture({
runOnJS: true,
onActivate: () => pushLog('inner tap gesture'),
testID: 'inner-tap',
});

return (
Expand All @@ -40,6 +43,11 @@ export default function NestedTouchablesExample() {

<Touchable
style={[styles.layer, styles.outerTouchable]}
testID="outer-touchable"
activeUnderlayOpacity={0.3}
onPressIn={() => pushLog('outer press in')}
onPressOut={() => pushLog('outer press out')}
onLongPress={() => pushLog('outer long press')}
onPress={() => pushLog('outer Touchable')}>
<Text style={styles.layerLabel}>Outer Touchable</Text>

Expand All @@ -49,6 +57,11 @@ export default function NestedTouchablesExample() {

<Touchable
style={[styles.layer, styles.innerTouchable]}
testID="inner-touchable"
activeUnderlayOpacity={0.3}
onPressIn={() => pushLog('inner press in')}
onPressOut={() => pushLog('inner press out')}
onLongPress={() => pushLog('inner long press')}
onPress={() => pushLog('inner Touchable')}>
<Text style={styles.layerLabel}>Inner Touchable</Text>
</Touchable>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,8 @@ open class GestureHandler {
return interactionController?.shouldHandlerBeCancelledBy(this, handler) ?: false
}

open fun shouldBeginWithRecordedHandlers(recorded: List<GestureHandler>): Boolean = true

fun isWithinBounds(view: View?, posX: Float, posY: Float): Boolean {
if (RNSVGHitTester.isSvgElement(view!!)) {
return RNSVGHitTester.hitTest(view, posX, posY)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -448,11 +448,16 @@ class GestureHandlerOrchestrator(
return
}

gestureHandlers.add(handler)
handler.isActive = false
handler.isAwaiting = false
handler.activationIndex = Int.MAX_VALUE
handler.prepare(view, this)

if (!handler.shouldBeginWithRecordedHandlers(gestureHandlers)) {
handler.cancel()
}
Comment thread
j-piasecki marked this conversation as resolved.

gestureHandlers.add(handler)
}

private fun isViewOverflowingParent(view: View): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ class NativeViewGestureHandler : GestureHandler() {

override fun shouldBeCancelledBy(handler: GestureHandler): Boolean = !disallowInterruption

override fun shouldBeginWithRecordedHandlers(recorded: List<GestureHandler>): Boolean =
hook.shouldBeginWithRecordedHandlers(recorded, this)

override fun onPrepare() {
when (val view = view) {
is NativeViewGestureHandlerHook -> this.hook = view
Expand Down Expand Up @@ -271,6 +274,16 @@ class NativeViewGestureHandler : GestureHandler() {
*/
fun shouldCancelRootViewGestureHandlerIfNecessary() = false

/**
* Called when the handler is being recorded by the orchestrator, before any pointer events
* are delivered. Returning `false` cancels the handler immediately.
*
* @param recorded handlers already recorded for the current touch
* @param handler the handler being recorded
*/
fun shouldBeginWithRecordedHandlers(recorded: List<GestureHandler>, handler: NativeViewGestureHandler): Boolean =
true

/**
* Passes the event down to the underlying view using the correct method.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ import com.facebook.react.uimanager.style.BorderStyle
import com.facebook.react.uimanager.style.LogicalEdge
import com.facebook.react.viewmanagers.RNGestureHandlerButtonManagerDelegate
import com.facebook.react.viewmanagers.RNGestureHandlerButtonManagerInterface
import com.swmansion.gesturehandler.core.GestureHandler
import com.swmansion.gesturehandler.core.HoverGestureHandler
import com.swmansion.gesturehandler.core.NativeViewGestureHandler
import com.swmansion.gesturehandler.react.RNGestureHandlerButtonViewManager.ButtonViewGroup

Expand Down Expand Up @@ -738,6 +740,16 @@ class RNGestureHandlerButtonViewManager :
isTouched = false
}

override fun shouldBeginWithRecordedHandlers(
recorded: List<GestureHandler>,
handler: NativeViewGestureHandler,
): Boolean = recorded.all {
it.shouldRecognizeSimultaneously(handler) ||
handler.shouldRecognizeSimultaneously(it) ||
it.view == this ||
it is HoverGestureHandler
}

private fun tryFreeingResponder() {
if (touchResponder === this) {
touchResponder = null
Expand Down
Loading