@userflow-tech/react-native 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +325 -63
- package/docs/anchoring.md +58 -42
- package/docs/troubleshooting.md +63 -27
- package/expo-plugin/hostDependencyWarnings.d.ts +18 -0
- package/expo-plugin/hostDependencyWarnings.d.ts.map +1 -0
- package/expo-plugin/hostDependencyWarnings.js +91 -0
- package/expo-plugin/hostDependencyWarnings.js.map +1 -0
- package/expo-plugin/withUserflow.d.ts.map +1 -1
- package/expo-plugin/withUserflow.js +16 -0
- package/expo-plugin/withUserflow.js.map +1 -1
- package/lib/commonjs/anchors/AnchorRegistry.js +7 -0
- package/lib/commonjs/anchors/AnchorRegistry.js.map +1 -1
- package/lib/commonjs/anchors/elementConditionEvaluator.js +189 -55
- package/lib/commonjs/anchors/elementConditionEvaluator.js.map +1 -1
- package/lib/commonjs/anchors/elementTapMonitor.js +92 -0
- package/lib/commonjs/anchors/elementTapMonitor.js.map +1 -0
- package/lib/commonjs/anchors/elementTargetMatch.js +85 -0
- package/lib/commonjs/anchors/elementTargetMatch.js.map +1 -0
- package/lib/commonjs/anchors/fiber/findAnchorFiber.js +64 -39
- package/lib/commonjs/anchors/fiber/findAnchorFiber.js.map +1 -1
- package/lib/commonjs/anchors/fiber/touchTargetFiber.js +105 -0
- package/lib/commonjs/anchors/fiber/touchTargetFiber.js.map +1 -0
- package/lib/commonjs/anchors/resolveAnchorHost.js +2 -1
- package/lib/commonjs/anchors/resolveAnchorHost.js.map +1 -1
- package/lib/commonjs/anchors/resolveAutoAnchorHost.js +4 -2
- package/lib/commonjs/anchors/resolveAutoAnchorHost.js.map +1 -1
- package/lib/commonjs/anchors/resolveElementTargets.js +158 -0
- package/lib/commonjs/anchors/resolveElementTargets.js.map +1 -0
- package/lib/commonjs/anchors/targetPressMonitor.js +9 -3
- package/lib/commonjs/anchors/targetPressMonitor.js.map +1 -1
- package/lib/commonjs/anchors/useUserflowAnchor.js +1 -0
- package/lib/commonjs/anchors/useUserflowAnchor.js.map +1 -1
- package/lib/commonjs/anonymousId.js +16 -7
- package/lib/commonjs/anonymousId.js.map +1 -1
- package/lib/commonjs/index.js +5 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/installCheck.js +151 -0
- package/lib/commonjs/installCheck.js.map +1 -0
- package/lib/commonjs/pairing/deviceId.js +14 -11
- package/lib/commonjs/pairing/deviceId.js.map +1 -1
- package/lib/commonjs/runtime/TargetPressBridge.js +12 -1
- package/lib/commonjs/runtime/TargetPressBridge.js.map +1 -1
- package/lib/commonjs/runtime/UserflowProvider.js +6 -3
- package/lib/commonjs/runtime/UserflowProvider.js.map +1 -1
- package/lib/commonjs/storage/asyncStorage.js +67 -0
- package/lib/commonjs/storage/asyncStorage.js.map +1 -0
- package/lib/commonjs/surfaces/safeArea.js +68 -28
- package/lib/commonjs/surfaces/safeArea.js.map +1 -1
- package/lib/commonjs/version.js +1 -1
- package/lib/module/anchors/AnchorRegistry.js +7 -0
- package/lib/module/anchors/AnchorRegistry.js.map +1 -1
- package/lib/module/anchors/elementConditionEvaluator.js +189 -55
- package/lib/module/anchors/elementConditionEvaluator.js.map +1 -1
- package/lib/module/anchors/elementTapMonitor.js +87 -0
- package/lib/module/anchors/elementTapMonitor.js.map +1 -0
- package/lib/module/anchors/elementTargetMatch.js +78 -0
- package/lib/module/anchors/elementTargetMatch.js.map +1 -0
- package/lib/module/anchors/fiber/findAnchorFiber.js +62 -39
- package/lib/module/anchors/fiber/findAnchorFiber.js.map +1 -1
- package/lib/module/anchors/fiber/touchTargetFiber.js +100 -0
- package/lib/module/anchors/fiber/touchTargetFiber.js.map +1 -0
- package/lib/module/anchors/resolveAnchorHost.js +2 -1
- package/lib/module/anchors/resolveAnchorHost.js.map +1 -1
- package/lib/module/anchors/resolveAutoAnchorHost.js +3 -3
- package/lib/module/anchors/resolveAutoAnchorHost.js.map +1 -1
- package/lib/module/anchors/resolveElementTargets.js +152 -0
- package/lib/module/anchors/resolveElementTargets.js.map +1 -0
- package/lib/module/anchors/targetPressMonitor.js +8 -3
- package/lib/module/anchors/targetPressMonitor.js.map +1 -1
- package/lib/module/anchors/useUserflowAnchor.js +1 -0
- package/lib/module/anchors/useUserflowAnchor.js.map +1 -1
- package/lib/module/anonymousId.js +15 -5
- package/lib/module/anonymousId.js.map +1 -1
- package/lib/module/index.js +5 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/installCheck.js +139 -0
- package/lib/module/installCheck.js.map +1 -0
- package/lib/module/pairing/deviceId.js +14 -10
- package/lib/module/pairing/deviceId.js.map +1 -1
- package/lib/module/runtime/TargetPressBridge.js +12 -1
- package/lib/module/runtime/TargetPressBridge.js.map +1 -1
- package/lib/module/runtime/UserflowProvider.js +7 -4
- package/lib/module/runtime/UserflowProvider.js.map +1 -1
- package/lib/module/storage/asyncStorage.js +61 -0
- package/lib/module/storage/asyncStorage.js.map +1 -0
- package/lib/module/surfaces/safeArea.js +65 -28
- package/lib/module/surfaces/safeArea.js.map +1 -1
- package/lib/module/version.js +1 -1
- package/lib/typescript/commonjs/src/anchors/AnchorRegistry.d.ts +7 -0
- package/lib/typescript/commonjs/src/anchors/AnchorRegistry.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/anchors/elementConditionEvaluator.d.ts +12 -16
- package/lib/typescript/commonjs/src/anchors/elementConditionEvaluator.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/anchors/elementTapMonitor.d.ts +36 -0
- package/lib/typescript/commonjs/src/anchors/elementTapMonitor.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/anchors/elementTargetMatch.d.ts +20 -0
- package/lib/typescript/commonjs/src/anchors/elementTargetMatch.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/anchors/fiber/findAnchorFiber.d.ts +17 -5
- package/lib/typescript/commonjs/src/anchors/fiber/findAnchorFiber.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/anchors/fiber/touchTargetFiber.d.ts +24 -0
- package/lib/typescript/commonjs/src/anchors/fiber/touchTargetFiber.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/anchors/resolveAnchorHost.d.ts +2 -1
- package/lib/typescript/commonjs/src/anchors/resolveAnchorHost.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/anchors/resolveAutoAnchorHost.d.ts +10 -1
- package/lib/typescript/commonjs/src/anchors/resolveAutoAnchorHost.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/anchors/resolveElementTargets.d.ts +39 -0
- package/lib/typescript/commonjs/src/anchors/resolveElementTargets.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/anchors/targetPressMonitor.d.ts +2 -0
- package/lib/typescript/commonjs/src/anchors/targetPressMonitor.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/anchors/useUserflowAnchor.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/anonymousId.d.ts +2 -0
- package/lib/typescript/commonjs/src/anonymousId.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/installCheck.d.ts +33 -0
- package/lib/typescript/commonjs/src/installCheck.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/pairing/deviceId.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/runtime/TargetPressBridge.d.ts +2 -1
- package/lib/typescript/commonjs/src/runtime/TargetPressBridge.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/runtime/UserflowProvider.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/storage/asyncStorage.d.ts +15 -0
- package/lib/typescript/commonjs/src/storage/asyncStorage.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/surfaces/safeArea.d.ts +4 -2
- package/lib/typescript/commonjs/src/surfaces/safeArea.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/version.d.ts +1 -1
- package/lib/typescript/module/src/anchors/AnchorRegistry.d.ts +7 -0
- package/lib/typescript/module/src/anchors/AnchorRegistry.d.ts.map +1 -1
- package/lib/typescript/module/src/anchors/elementConditionEvaluator.d.ts +12 -16
- package/lib/typescript/module/src/anchors/elementConditionEvaluator.d.ts.map +1 -1
- package/lib/typescript/module/src/anchors/elementTapMonitor.d.ts +36 -0
- package/lib/typescript/module/src/anchors/elementTapMonitor.d.ts.map +1 -0
- package/lib/typescript/module/src/anchors/elementTargetMatch.d.ts +20 -0
- package/lib/typescript/module/src/anchors/elementTargetMatch.d.ts.map +1 -0
- package/lib/typescript/module/src/anchors/fiber/findAnchorFiber.d.ts +17 -5
- package/lib/typescript/module/src/anchors/fiber/findAnchorFiber.d.ts.map +1 -1
- package/lib/typescript/module/src/anchors/fiber/touchTargetFiber.d.ts +24 -0
- package/lib/typescript/module/src/anchors/fiber/touchTargetFiber.d.ts.map +1 -0
- package/lib/typescript/module/src/anchors/resolveAnchorHost.d.ts +2 -1
- package/lib/typescript/module/src/anchors/resolveAnchorHost.d.ts.map +1 -1
- package/lib/typescript/module/src/anchors/resolveAutoAnchorHost.d.ts +10 -1
- package/lib/typescript/module/src/anchors/resolveAutoAnchorHost.d.ts.map +1 -1
- package/lib/typescript/module/src/anchors/resolveElementTargets.d.ts +39 -0
- package/lib/typescript/module/src/anchors/resolveElementTargets.d.ts.map +1 -0
- package/lib/typescript/module/src/anchors/targetPressMonitor.d.ts +2 -0
- package/lib/typescript/module/src/anchors/targetPressMonitor.d.ts.map +1 -1
- package/lib/typescript/module/src/anchors/useUserflowAnchor.d.ts.map +1 -1
- package/lib/typescript/module/src/anonymousId.d.ts +2 -0
- package/lib/typescript/module/src/anonymousId.d.ts.map +1 -1
- package/lib/typescript/module/src/index.d.ts.map +1 -1
- package/lib/typescript/module/src/installCheck.d.ts +33 -0
- package/lib/typescript/module/src/installCheck.d.ts.map +1 -0
- package/lib/typescript/module/src/pairing/deviceId.d.ts.map +1 -1
- package/lib/typescript/module/src/runtime/TargetPressBridge.d.ts +2 -1
- package/lib/typescript/module/src/runtime/TargetPressBridge.d.ts.map +1 -1
- package/lib/typescript/module/src/runtime/UserflowProvider.d.ts.map +1 -1
- package/lib/typescript/module/src/storage/asyncStorage.d.ts +15 -0
- package/lib/typescript/module/src/storage/asyncStorage.d.ts.map +1 -0
- package/lib/typescript/module/src/surfaces/safeArea.d.ts +4 -2
- package/lib/typescript/module/src/surfaces/safeArea.d.ts.map +1 -1
- package/lib/typescript/module/src/version.d.ts +1 -1
- package/package.json +13 -1
- package/src/anchors/AnchorRegistry.ts +12 -0
- package/src/anchors/elementConditionEvaluator.ts +235 -70
- package/src/anchors/elementTapMonitor.ts +95 -0
- package/src/anchors/elementTargetMatch.ts +90 -0
- package/src/anchors/fiber/findAnchorFiber.ts +66 -35
- package/src/anchors/fiber/touchTargetFiber.ts +125 -0
- package/src/anchors/resolveAnchorHost.ts +2 -1
- package/src/anchors/resolveAutoAnchorHost.ts +3 -3
- package/src/anchors/resolveElementTargets.ts +165 -0
- package/src/anchors/targetPressMonitor.ts +12 -3
- package/src/anchors/useUserflowAnchor.ts +1 -0
- package/src/anonymousId.ts +19 -8
- package/src/index.ts +10 -0
- package/src/installCheck.ts +191 -0
- package/src/pairing/deviceId.ts +14 -11
- package/src/runtime/TargetPressBridge.tsx +17 -1
- package/src/runtime/UserflowProvider.tsx +11 -4
- package/src/storage/asyncStorage.ts +88 -0
- package/src/surfaces/safeArea.ts +80 -40
- package/src/version.ts +1 -1
- package/vendor/core/dist/constants.d.ts +2 -0
- package/vendor/core/dist/constants.d.ts.map +1 -1
- package/vendor/core/dist/constants.js +2 -0
- package/vendor/core/dist/constants.js.map +1 -1
- package/vendor/core/dist/engine/ClientConditionEngine.d.ts +20 -1
- package/vendor/core/dist/engine/ClientConditionEngine.d.ts.map +1 -1
- package/vendor/core/dist/engine/ClientConditionEngine.js +13 -10
- package/vendor/core/dist/engine/ClientConditionEngine.js.map +1 -1
- package/vendor/core/dist/engine/UserflowCore.d.ts.map +1 -1
- package/vendor/core/dist/engine/UserflowCore.js +21 -2
- package/vendor/core/dist/engine/UserflowCore.js.map +1 -1
- package/vendor/core/dist/index.d.ts +1 -1
- package/vendor/core/dist/index.d.ts.map +1 -1
- package/vendor/core/dist/index.js.map +1 -1
- package/vendor/core/dist/version.d.ts +1 -1
- package/vendor/core/dist/version.js +1 -1
- package/vendor/core/package.json +1 -1
- package/vendor/protocol/package.json +1 -1
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pass-through tap observation for ELEMENT CLICK / NOT_CLICK conditions.
|
|
3
|
+
*
|
|
4
|
+
* Many conditions can subscribe at once. Touch start/end are paired per finger
|
|
5
|
+
* and a tap is emitted only when movement stays within the same slop the
|
|
6
|
+
* tooltip target-press monitor uses. The host fiber is the one captured at
|
|
7
|
+
* touch start, before the press's setState commits a new tree.
|
|
8
|
+
*
|
|
9
|
+
* With no subscribers the monitor stores nothing, so the bridge can skip the
|
|
10
|
+
* fiber lookup entirely.
|
|
11
|
+
*/
|
|
12
|
+
import type { AnyFiber } from './fiber/fiberInternals';
|
|
13
|
+
import { type TouchIdentifier, type TouchPoint, withinTapSlop } from './targetPressMonitor';
|
|
14
|
+
|
|
15
|
+
export interface ElementTap {
|
|
16
|
+
targetFiber: AnyFiber;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export type ElementTapListener = (tap: ElementTap) => void;
|
|
20
|
+
|
|
21
|
+
interface TouchStart extends TouchPoint {
|
|
22
|
+
targetFiber: AnyFiber | null;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export class ElementTapMonitor {
|
|
26
|
+
private readonly listeners = new Set<ElementTapListener>();
|
|
27
|
+
private readonly touchStarts = new Map<TouchIdentifier, TouchStart>();
|
|
28
|
+
|
|
29
|
+
get subscriberCount(): number {
|
|
30
|
+
return this.listeners.size;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
subscribe(listener: ElementTapListener): () => void {
|
|
34
|
+
this.listeners.add(listener);
|
|
35
|
+
return () => {
|
|
36
|
+
this.listeners.delete(listener);
|
|
37
|
+
if (this.listeners.size === 0) {
|
|
38
|
+
this.touchStarts.clear();
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
handleTouchStart(
|
|
44
|
+
identifier: TouchIdentifier,
|
|
45
|
+
pageX: number,
|
|
46
|
+
pageY: number,
|
|
47
|
+
targetFiber: AnyFiber | null,
|
|
48
|
+
): void {
|
|
49
|
+
if (this.listeners.size === 0) {
|
|
50
|
+
this.touchStarts.clear();
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
this.touchStarts.set(identifier, { pageX, pageY, targetFiber });
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Emit a tap when this finger started and ended within slop on a resolved
|
|
58
|
+
* host. Never claims the responder.
|
|
59
|
+
*/
|
|
60
|
+
handleTouchEnd(identifier: TouchIdentifier, pageX: number, pageY: number): void {
|
|
61
|
+
const start = this.touchStarts.get(identifier) ?? null;
|
|
62
|
+
this.touchStarts.delete(identifier);
|
|
63
|
+
if (!start || this.listeners.size === 0 || !start.targetFiber) return;
|
|
64
|
+
if (!withinTapSlop(start, { pageX, pageY })) return;
|
|
65
|
+
|
|
66
|
+
const tap: ElementTap = { targetFiber: start.targetFiber };
|
|
67
|
+
for (const listener of this.listeners) {
|
|
68
|
+
// One condition's failure must not cost the others this tap, or abort
|
|
69
|
+
// the bridge's handling of the event's remaining touches.
|
|
70
|
+
try {
|
|
71
|
+
listener(tap);
|
|
72
|
+
} catch {
|
|
73
|
+
// The condition stays at its current value.
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** Drop in-progress gesture(s). Omit `identifier` to clear every finger. */
|
|
79
|
+
cancelTouch(identifier?: TouchIdentifier): void {
|
|
80
|
+
if (identifier == null) {
|
|
81
|
+
this.touchStarts.clear();
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
this.touchStarts.delete(identifier);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** Test helper. */
|
|
88
|
+
resetForTests(): void {
|
|
89
|
+
this.listeners.clear();
|
|
90
|
+
this.touchStarts.clear();
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** Shared singleton used by TargetPressBridge and the element-condition evaluator. */
|
|
95
|
+
export const elementTapMonitor = new ElementTapMonitor();
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compare a touch-start fiber with a host resolved later, tolerating the
|
|
3
|
+
* alternate swap a Pressable `pressed` re-render does mid-gesture.
|
|
4
|
+
*/
|
|
5
|
+
import type { ElementTap } from './elementTapMonitor';
|
|
6
|
+
import {
|
|
7
|
+
type AnyFiber,
|
|
8
|
+
MAX_ANCESTOR_WALK,
|
|
9
|
+
getAlternate,
|
|
10
|
+
getLiveHostProps,
|
|
11
|
+
getMemoizedProps,
|
|
12
|
+
getReturn,
|
|
13
|
+
} from './fiber/fiberInternals';
|
|
14
|
+
import { ANCHOR_PROP_TIERS } from './fiber/findAnchorFiber';
|
|
15
|
+
|
|
16
|
+
const anchorIdsByTap = new WeakMap<ElementTap, ReadonlySet<string>>();
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Anchor ids on the tapped fiber and its ancestors, built once per tap and
|
|
20
|
+
* shared by every click condition it is delivered to.
|
|
21
|
+
*/
|
|
22
|
+
export function anchorIdsAboveTap(tap: ElementTap): ReadonlySet<string> {
|
|
23
|
+
const cached = anchorIdsByTap.get(tap);
|
|
24
|
+
if (cached) return cached;
|
|
25
|
+
|
|
26
|
+
const ids = new Set<string>();
|
|
27
|
+
let current: AnyFiber = tap.targetFiber;
|
|
28
|
+
for (let depth = 0; current && depth < MAX_ANCESTOR_WALK; depth += 1) {
|
|
29
|
+
const props = getMemoizedProps(current);
|
|
30
|
+
if (props) {
|
|
31
|
+
for (const tier of ANCHOR_PROP_TIERS) {
|
|
32
|
+
const value = props[tier];
|
|
33
|
+
if (typeof value === 'string') ids.add(value);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
current = getReturn(current);
|
|
37
|
+
}
|
|
38
|
+
anchorIdsByTap.set(tap, ids);
|
|
39
|
+
return ids;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function sameFiber(a: AnyFiber, b: AnyFiber): boolean {
|
|
43
|
+
if (a == null || b == null) return false;
|
|
44
|
+
if (a === b) return true;
|
|
45
|
+
const aAlt = getAlternate(a);
|
|
46
|
+
const bAlt = getAlternate(b);
|
|
47
|
+
return a === bAlt || aAlt === b || (aAlt != null && aAlt === bAlt);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** True when `node` is `host` or a descendant of it. */
|
|
51
|
+
export function fiberIsUnder(node: AnyFiber, host: AnyFiber): boolean {
|
|
52
|
+
let current: AnyFiber = node;
|
|
53
|
+
for (let depth = 0; current && depth < MAX_ANCESTOR_WALK; depth += 1) {
|
|
54
|
+
if (sameFiber(current, host)) return true;
|
|
55
|
+
current = getReturn(current);
|
|
56
|
+
}
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function fiberDisabled(fiber: AnyFiber): boolean {
|
|
61
|
+
let props: Record<string, unknown> | undefined;
|
|
62
|
+
try {
|
|
63
|
+
props = getLiveHostProps(fiber);
|
|
64
|
+
} catch {
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
if (!props) return false;
|
|
68
|
+
if (props.disabled === true) return true;
|
|
69
|
+
if (props['aria-disabled'] === true) return true;
|
|
70
|
+
const state = props.accessibilityState;
|
|
71
|
+
return (
|
|
72
|
+
typeof state === 'object' &&
|
|
73
|
+
state !== null &&
|
|
74
|
+
(state as { disabled?: unknown }).disabled === true
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* True when the tapped fiber, the matched host, or a fiber between them is
|
|
80
|
+
* disabled. Browsers do not fire `click` on a disabled control.
|
|
81
|
+
*/
|
|
82
|
+
export function tapPathDisabled(tapped: AnyFiber, host: AnyFiber): boolean {
|
|
83
|
+
let current: AnyFiber = tapped;
|
|
84
|
+
for (let depth = 0; current && depth < MAX_ANCESTOR_WALK; depth += 1) {
|
|
85
|
+
if (fiberDisabled(current)) return true;
|
|
86
|
+
if (sameFiber(current, host)) return false;
|
|
87
|
+
current = getReturn(current);
|
|
88
|
+
}
|
|
89
|
+
return fiberDisabled(host);
|
|
90
|
+
}
|
|
@@ -19,35 +19,65 @@ const MAX_NODES = 60_000;
|
|
|
19
19
|
/** One production warning per process — truncation must not look like "missing". */
|
|
20
20
|
let maxNodesWarned = false;
|
|
21
21
|
|
|
22
|
-
export type AnchorPropTier = 'testID' | 'nativeID' | 'accessibilityLabel';
|
|
22
|
+
export type AnchorPropTier = 'userflowId' | 'testID' | 'nativeID' | 'accessibilityLabel';
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
/** Props an anchor id can sit on, strongest first. */
|
|
25
|
+
export const ANCHOR_PROP_TIERS: readonly AnchorPropTier[] = [
|
|
26
|
+
'userflowId',
|
|
27
|
+
'testID',
|
|
28
|
+
'nativeID',
|
|
29
|
+
'accessibilityLabel',
|
|
30
|
+
];
|
|
25
31
|
|
|
26
32
|
export type FindAnchorFiberResult =
|
|
27
33
|
| { status: 'found'; fiber: AnyFiber; tier: AnchorPropTier }
|
|
28
34
|
| { status: 'ambiguous'; tier: AnchorPropTier }
|
|
29
35
|
| { status: 'missing' };
|
|
30
36
|
|
|
37
|
+
/** Every collapsed host of the winning tier. Duplicates stay in the list. */
|
|
38
|
+
export type FindAnchorFibersResult =
|
|
39
|
+
| { status: 'found'; fibers: AnyFiber[]; tier: AnchorPropTier }
|
|
40
|
+
| { status: 'missing' };
|
|
41
|
+
|
|
31
42
|
/**
|
|
32
43
|
* Bounded DFS under `rootFiber` looking for fibers whose memoizedProps match
|
|
33
|
-
* `id` on testID, then nativeID, then accessibilityLabel.
|
|
34
|
-
* tier that has any match so a testID hit is never made
|
|
35
|
-
* unrelated accessibilityLabel.
|
|
44
|
+
* `id` on userflowId, then testID, then nativeID, then accessibilityLabel.
|
|
45
|
+
* Uses the highest tier that has any match so a testID hit is never made
|
|
46
|
+
* ambiguous by an unrelated accessibilityLabel.
|
|
36
47
|
*
|
|
37
48
|
* A composite match resolves to the host beneath it that carries the same id
|
|
38
49
|
* (e.g. a tab item that wraps its button in a View and forwards testID to the
|
|
39
50
|
* button), else to its shallowest host descendant. Multiple matches on a single
|
|
40
51
|
* root-to-leaf chain (e.g. Pressable forwarding testID to its inner View)
|
|
41
|
-
* collapse to the outermost host. Disjoint matches
|
|
52
|
+
* collapse to the outermost host. Disjoint matches stay in the list returned by
|
|
53
|
+
* {@link findAnchorFibers}; {@link findAnchorFiber} fails closed on those.
|
|
42
54
|
*
|
|
43
55
|
* The walk never follows `rootFiber.sibling` so the Userflow overlay (a sibling
|
|
44
56
|
* of {@link FiberScanRoot} in UserflowProvider) cannot self-match SDK testIDs.
|
|
45
57
|
*/
|
|
46
|
-
export function
|
|
58
|
+
export function findAnchorFibers(rootFiber: AnyFiber, id: string): FindAnchorFibersResult {
|
|
47
59
|
if (!rootFiber || !id) return { status: 'missing' };
|
|
60
|
+
const won = winningTier(rootFiber, id);
|
|
61
|
+
if (!won) return { status: 'missing' };
|
|
62
|
+
return { status: 'found', fibers: won.hosts, tier: won.tier };
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function findAnchorFiber(rootFiber: AnyFiber, id: string): FindAnchorFiberResult {
|
|
66
|
+
const many = findAnchorFibers(rootFiber, id);
|
|
67
|
+
if (many.status === 'missing') return { status: 'missing' };
|
|
68
|
+
if (many.fibers.length === 1) {
|
|
69
|
+
return { status: 'found', fiber: many.fibers[0]!, tier: many.tier };
|
|
70
|
+
}
|
|
71
|
+
return { status: 'ambiguous', tier: many.tier };
|
|
72
|
+
}
|
|
48
73
|
|
|
74
|
+
function winningTier(
|
|
75
|
+
rootFiber: AnyFiber,
|
|
76
|
+
id: string,
|
|
77
|
+
): { tier: AnchorPropTier; hosts: AnyFiber[] } | null {
|
|
49
78
|
try {
|
|
50
79
|
const byTier: Record<AnchorPropTier, AnyFiber[]> = {
|
|
80
|
+
userflowId: [],
|
|
51
81
|
testID: [],
|
|
52
82
|
nativeID: [],
|
|
53
83
|
accessibilityLabel: [],
|
|
@@ -58,6 +88,9 @@ export function findAnchorFiber(rootFiber: AnyFiber, id: string): FindAnchorFibe
|
|
|
58
88
|
(fiber) => {
|
|
59
89
|
const props = getMemoizedProps(fiber);
|
|
60
90
|
if (!props) return;
|
|
91
|
+
if (typeof props.userflowId === 'string' && props.userflowId === id) {
|
|
92
|
+
byTier.userflowId.push(fiber);
|
|
93
|
+
}
|
|
61
94
|
if (typeof props.testID === 'string' && props.testID === id) {
|
|
62
95
|
byTier.testID.push(fiber);
|
|
63
96
|
}
|
|
@@ -72,44 +105,42 @@ export function findAnchorFiber(rootFiber: AnyFiber, id: string): FindAnchorFibe
|
|
|
72
105
|
);
|
|
73
106
|
|
|
74
107
|
if (truncated || visited >= MAX_NODES) {
|
|
75
|
-
|
|
76
|
-
// eslint-disable-next-line no-console -- actionable: the anchor may exist but was not reached
|
|
77
|
-
const warn = (message: string): void => console.warn(message);
|
|
78
|
-
if (__DEV__) {
|
|
79
|
-
warn(
|
|
80
|
-
`[Userflow] Anchor scan for "${id}" stopped after ${MAX_NODES} nodes. ` +
|
|
81
|
-
`The element may exist but was not reached. Register it explicitly with ` +
|
|
82
|
-
`useUserflowAnchor("${id}") to skip the scan.`,
|
|
83
|
-
);
|
|
84
|
-
} else if (!maxNodesWarned) {
|
|
85
|
-
maxNodesWarned = true;
|
|
86
|
-
warn(
|
|
87
|
-
`[Userflow] Anchor scan stopped after ${MAX_NODES} nodes; some anchors may ` +
|
|
88
|
-
`be missed. Prefer useUserflowAnchor for deep or dense trees.`,
|
|
89
|
-
);
|
|
90
|
-
}
|
|
108
|
+
warnScanTruncated(id);
|
|
91
109
|
}
|
|
92
110
|
|
|
93
|
-
for (const tier of
|
|
111
|
+
for (const tier of ANCHOR_PROP_TIERS) {
|
|
94
112
|
const matches = byTier[tier];
|
|
95
113
|
if (matches.length === 0) continue;
|
|
96
114
|
|
|
97
115
|
const hosts = uniqueHosts(matches);
|
|
98
116
|
if (hosts.length === 0) continue;
|
|
99
|
-
|
|
100
|
-
return { status: 'found', fiber: hosts[0]!, tier };
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
const collapsed = collapseToChains(hosts);
|
|
104
|
-
if (collapsed.length === 1) {
|
|
105
|
-
return { status: 'found', fiber: collapsed[0]!, tier };
|
|
106
|
-
}
|
|
107
|
-
return { status: 'ambiguous', tier };
|
|
117
|
+
return { tier, hosts: collapseToChains(hosts) };
|
|
108
118
|
}
|
|
109
119
|
|
|
110
|
-
return
|
|
120
|
+
return null;
|
|
111
121
|
} catch {
|
|
112
|
-
return
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function warnScanTruncated(id: string): void {
|
|
127
|
+
// Truncation would otherwise look exactly like "the anchor isn't there".
|
|
128
|
+
// eslint-disable-next-line no-console -- actionable: the anchor may exist but was not reached
|
|
129
|
+
const warn = (message: string): void => console.warn(message);
|
|
130
|
+
if (__DEV__) {
|
|
131
|
+
warn(
|
|
132
|
+
`[Userflow] Anchor scan for "${id}" stopped after ${MAX_NODES} nodes. ` +
|
|
133
|
+
`The element may exist but was not reached. Register it explicitly with ` +
|
|
134
|
+
`useUserflowAnchor("${id}") to skip the scan.`,
|
|
135
|
+
);
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
if (!maxNodesWarned) {
|
|
139
|
+
maxNodesWarned = true;
|
|
140
|
+
warn(
|
|
141
|
+
`[Userflow] Anchor scan stopped after ${MAX_NODES} nodes; some anchors may ` +
|
|
142
|
+
`be missed. Prefer useUserflowAnchor for deep or dense trees.`,
|
|
143
|
+
);
|
|
113
144
|
}
|
|
114
145
|
}
|
|
115
146
|
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Host fiber under a touch, resolved synchronously from the responder event.
|
|
3
|
+
*
|
|
4
|
+
* Feature-detected and never throws. A renderer that does not expose any of
|
|
5
|
+
* these pointers degrades to "no target", so a click condition simply does not
|
|
6
|
+
* latch.
|
|
7
|
+
*
|
|
8
|
+
* Order:
|
|
9
|
+
* 1. `event._targetInst` (React's fiber for the touched component)
|
|
10
|
+
* 2. `event.target` public instance via {@link lookupHostFiber}
|
|
11
|
+
* 3. The touch's native tag (`changedTouches[].target`, else `nativeEvent.target`)
|
|
12
|
+
* via the scan-root host index
|
|
13
|
+
*/
|
|
14
|
+
import type { GestureResponderEvent } from 'react-native';
|
|
15
|
+
|
|
16
|
+
import {
|
|
17
|
+
type AnyFiber,
|
|
18
|
+
isHostFiber,
|
|
19
|
+
isReactFiber,
|
|
20
|
+
nativeTagFromHostFiber,
|
|
21
|
+
resolveCurrentFiber,
|
|
22
|
+
} from './fiberInternals';
|
|
23
|
+
import { nearestHostDescendant } from './findAnchorFiber';
|
|
24
|
+
import { createLazyHostFiberIndex, lookupHostFiber } from './indexHostFibers';
|
|
25
|
+
|
|
26
|
+
export function touchTargetFiber(
|
|
27
|
+
event: GestureResponderEvent,
|
|
28
|
+
identifier?: number | string,
|
|
29
|
+
): AnyFiber | null {
|
|
30
|
+
try {
|
|
31
|
+
const tag = nativeTagForTouch(event, identifier);
|
|
32
|
+
|
|
33
|
+
const fromInst = hostFromFiber(readTargetInst(event));
|
|
34
|
+
if (fromInst && tagMatches(fromInst, tag)) return fromInst;
|
|
35
|
+
|
|
36
|
+
const fromInstance = hostFromInstance(event.target);
|
|
37
|
+
if (fromInstance && tagMatches(fromInstance, tag)) return fromInstance;
|
|
38
|
+
|
|
39
|
+
if (tag === undefined) return null;
|
|
40
|
+
// The event-level fibers belong to another finger's view, so only the
|
|
41
|
+
// index can name this one. A miss must not fall back to theirs.
|
|
42
|
+
return createLazyHostFiberIndex()().byNativeTag.get(tag) ?? null;
|
|
43
|
+
} catch {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Fabric sends one touch event per touched view, and each lists every finger
|
|
50
|
+
* that changed. True when `identifier`'s finger is on this event's own view,
|
|
51
|
+
* so a caller can record each finger once, from its own event, instead of
|
|
52
|
+
* overwriting it from another finger's. Unreadable tags count as this event's.
|
|
53
|
+
*/
|
|
54
|
+
export function touchBelongsToEvent(
|
|
55
|
+
event: GestureResponderEvent,
|
|
56
|
+
identifier: number | string,
|
|
57
|
+
): boolean {
|
|
58
|
+
try {
|
|
59
|
+
const tag = nativeTagForTouch(event, identifier);
|
|
60
|
+
if (tag === undefined) return true;
|
|
61
|
+
const own = hostFromFiber(readTargetInst(event)) ?? hostFromInstance(event.target);
|
|
62
|
+
return own == null || tagMatches(own, tag);
|
|
63
|
+
} catch {
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function readTargetInst(event: GestureResponderEvent): unknown {
|
|
69
|
+
return (event as { _targetInst?: unknown })._targetInst;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function nativeTagForTouch(
|
|
73
|
+
event: GestureResponderEvent,
|
|
74
|
+
identifier: number | string | undefined,
|
|
75
|
+
): number | undefined {
|
|
76
|
+
const native = event.nativeEvent as {
|
|
77
|
+
target?: unknown;
|
|
78
|
+
changedTouches?: Array<{ identifier?: number | string; target?: unknown }>;
|
|
79
|
+
};
|
|
80
|
+
if (identifier != null && native.changedTouches) {
|
|
81
|
+
const touch = native.changedTouches.find((entry) => entry.identifier === identifier);
|
|
82
|
+
const touchTag = asTag(touch?.target);
|
|
83
|
+
if (touchTag !== undefined) return touchTag;
|
|
84
|
+
}
|
|
85
|
+
return asTag(native.target);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function asTag(value: unknown): number | undefined {
|
|
89
|
+
return typeof value === 'number' && Number.isFinite(value) ? value : undefined;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Accept a host whose tag we cannot read (test renderer, older Paper). Reject
|
|
94
|
+
* only when both sides have a tag and they differ — that event-level fiber
|
|
95
|
+
* belongs to a different finger.
|
|
96
|
+
*/
|
|
97
|
+
function tagMatches(fiber: AnyFiber, tag: number | undefined): boolean {
|
|
98
|
+
if (tag === undefined) return true;
|
|
99
|
+
const fiberTag = nativeTagFromHostFiber(fiber);
|
|
100
|
+
if (fiberTag === undefined) return true;
|
|
101
|
+
return fiberTag === tag;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function hostFromFiber(value: unknown): AnyFiber | null {
|
|
105
|
+
if (!isReactFiber(value)) return null;
|
|
106
|
+
try {
|
|
107
|
+
const current = resolveCurrentFiber(value);
|
|
108
|
+
if (isHostFiber(current)) return current;
|
|
109
|
+
return nearestHostDescendant(current);
|
|
110
|
+
} catch {
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function hostFromInstance(value: unknown): AnyFiber | null {
|
|
116
|
+
if (!value || typeof value !== 'object') return null;
|
|
117
|
+
try {
|
|
118
|
+
const fiber = lookupHostFiber(createLazyHostFiberIndex(), value);
|
|
119
|
+
if (!fiber) return null;
|
|
120
|
+
if (isHostFiber(fiber)) return fiber;
|
|
121
|
+
return nearestHostDescendant(fiber);
|
|
122
|
+
} catch {
|
|
123
|
+
return null;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
@@ -43,7 +43,8 @@ export function invalidateFiberAnchor(id: string): void {
|
|
|
43
43
|
*
|
|
44
44
|
* Tier 0: {@link anchorRegistry} (`useUserflowAnchor`) — higher priority, fails
|
|
45
45
|
* closed on ambiguous registry keys.
|
|
46
|
-
* Tier 1+: fiber scan for `testID`, then `nativeID`, then
|
|
46
|
+
* Tier 1+: fiber scan for `userflowId`, then `testID`, then `nativeID`, then
|
|
47
|
+
* `accessibilityLabel`.
|
|
47
48
|
*
|
|
48
49
|
* Synchronous (the walk is pure JS; only measurement is async via the returned
|
|
49
50
|
* host). Caches the resolved fiber per id and revalidates cheaply before reuse.
|
|
@@ -75,7 +75,7 @@ function fiberFromInstance(inst: AutoAnchorInstance): AnyFiber | null {
|
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
/** Authoritative id that the existing fiber / manual resolver can look up. */
|
|
78
|
-
function exactIdFromFingerprint(fp: MobileFingerprint): string | null {
|
|
78
|
+
export function exactIdFromFingerprint(fp: MobileFingerprint): string | null {
|
|
79
79
|
if (fp.userflowId) return fp.userflowId;
|
|
80
80
|
if (fp.testID) return fp.testID;
|
|
81
81
|
if (fp.nativeID && !fp.nativeID.startsWith('uf_')) return fp.nativeID;
|
|
@@ -116,7 +116,7 @@ function mapMatch(match: MatchResult): AutoAnchorResolution {
|
|
|
116
116
|
* scored and the unfiltered pool still has a hit, that hit is on a covered
|
|
117
117
|
* screen — `absent`, matching MANUAL covered-screen semantics.
|
|
118
118
|
*/
|
|
119
|
-
function
|
|
119
|
+
export function resolveScoredAutoAnchor(fp: MobileFingerprint): AutoAnchorResolution {
|
|
120
120
|
const visible = matchFingerprint(fp, { instanceFilter: createVisibleInstanceFilter() });
|
|
121
121
|
if (visible.instance) return mapMatch(visible);
|
|
122
122
|
|
|
@@ -178,5 +178,5 @@ export function resolveAutoAnchorHost(
|
|
|
178
178
|
}
|
|
179
179
|
}
|
|
180
180
|
|
|
181
|
-
return
|
|
181
|
+
return resolveScoredAutoAnchor(fp);
|
|
182
182
|
}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolve every host an ELEMENT condition should consider.
|
|
3
|
+
*
|
|
4
|
+
* Tooltips fail closed when an id matches more than one view. Conditions follow
|
|
5
|
+
* the web SDK instead: any match counts. AUTO exact ids (`userflowId`, then
|
|
6
|
+
* `testID`, then a real `nativeID`) use that same multi-host lookup, and fall
|
|
7
|
+
* through to scoring only when nothing matched.
|
|
8
|
+
*/
|
|
9
|
+
import { decodeMobileAutoData, type FlowSelectorFragment } from '@userflow-tech/protocol';
|
|
10
|
+
|
|
11
|
+
import { type AnchorHost, anchorRegistry } from './AnchorRegistry';
|
|
12
|
+
import type { ElementTap } from './elementTapMonitor';
|
|
13
|
+
import { anchorIdsAboveTap } from './elementTargetMatch';
|
|
14
|
+
import { fiberScanRoot } from './fiber/FiberScanRoot';
|
|
15
|
+
import { type AnyFiber, publicInstanceFromHostFiber } from './fiber/fiberInternals';
|
|
16
|
+
import { findAnchorFibers } from './fiber/findAnchorFiber';
|
|
17
|
+
import {
|
|
18
|
+
createLazyHostFiberIndex,
|
|
19
|
+
lookupHostFiber,
|
|
20
|
+
type HostFiberIndexSource,
|
|
21
|
+
} from './fiber/indexHostFibers';
|
|
22
|
+
import { createFiberMeasureInWindow } from './fiber/measureHostFiber';
|
|
23
|
+
import { isFiberOnVisibleScreen } from './fiber/visibleScreens';
|
|
24
|
+
import {
|
|
25
|
+
exactIdFromFingerprint,
|
|
26
|
+
resolveAutoAnchorHost,
|
|
27
|
+
resolveScoredAutoAnchor,
|
|
28
|
+
type AutoAnchorResolution,
|
|
29
|
+
} from './resolveAutoAnchorHost';
|
|
30
|
+
import { resolveManualAnchorId } from './resolveManualAnchorId';
|
|
31
|
+
|
|
32
|
+
export interface ElementTarget {
|
|
33
|
+
host: AnchorHost;
|
|
34
|
+
fiber?: AnyFiber;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export type ElementTargetResolution =
|
|
38
|
+
| { status: 'found'; targets: ElementTarget[] }
|
|
39
|
+
| { status: 'absent' }
|
|
40
|
+
| {
|
|
41
|
+
status: 'unknown';
|
|
42
|
+
/**
|
|
43
|
+
* Ambiguous scored matches stay unknown without a warning. A missing
|
|
44
|
+
* selector or an AUTO payload that cannot be decoded still warns.
|
|
45
|
+
*/
|
|
46
|
+
silent?: boolean;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export function resolveElementTargets(
|
|
50
|
+
selector: FlowSelectorFragment | null | undefined,
|
|
51
|
+
): ElementTargetResolution {
|
|
52
|
+
if (selector == null) return { status: 'unknown' };
|
|
53
|
+
|
|
54
|
+
if ((selector.type as string | null) === 'AUTO') {
|
|
55
|
+
return resolveAutoTargets(selector.autoData);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const anchorId = resolveManualAnchorId(selector.css);
|
|
59
|
+
if (anchorId == null) return { status: 'unknown' };
|
|
60
|
+
return resolveManualTargets(anchorId);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* False when no target of `selector` can contain `tap`, decided without a tree
|
|
65
|
+
* scan. A fiber-scan target carries its id itself or sits under a composite
|
|
66
|
+
* that does, so a MANUAL id that is neither registered nor on the tap's
|
|
67
|
+
* ancestor chain cannot match. AUTO selectors are not gated: only a scan tells
|
|
68
|
+
* whether the exact id or a scored match applies.
|
|
69
|
+
*/
|
|
70
|
+
export function tapMayHitSelector(
|
|
71
|
+
selector: FlowSelectorFragment | null | undefined,
|
|
72
|
+
tap: ElementTap,
|
|
73
|
+
): boolean {
|
|
74
|
+
if (selector == null) return false;
|
|
75
|
+
if ((selector.type as string | null) === 'AUTO') return true;
|
|
76
|
+
|
|
77
|
+
const anchorId = resolveManualAnchorId(selector.css);
|
|
78
|
+
if (anchorId == null) return false;
|
|
79
|
+
return anchorRegistry.get(anchorId) != null || anchorIdsAboveTap(tap).has(anchorId);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function resolveAutoTargets(autoData: string | null): ElementTargetResolution {
|
|
83
|
+
const decoded = decodeMobileAutoData(autoData);
|
|
84
|
+
const fingerprint = decoded?.fingerprint;
|
|
85
|
+
if (!decoded || !fingerprint) return { status: 'unknown' };
|
|
86
|
+
|
|
87
|
+
if (decoded.resolver === 'fiber' && decoded.fiberPath) {
|
|
88
|
+
return fromAutoResolution(resolveAutoAnchorHost(decoded));
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const exactId = exactIdFromFingerprint(fingerprint);
|
|
92
|
+
if (exactId) {
|
|
93
|
+
const manual = resolveManualTargets(exactId);
|
|
94
|
+
if (manual.status === 'found') return manual;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// The exact id already missed above, so go straight to scoring rather than
|
|
98
|
+
// letting resolveAutoAnchorHost scan for it again.
|
|
99
|
+
return fromAutoResolution(resolveScoredAutoAnchor(fingerprint));
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function fromAutoResolution(resolution: AutoAnchorResolution): ElementTargetResolution {
|
|
103
|
+
if (resolution.status === 'found') {
|
|
104
|
+
// Scored matches only try the direct ref pointer, which Paper release
|
|
105
|
+
// builds null out. Without the index fallback a tap could never match.
|
|
106
|
+
const fiber =
|
|
107
|
+
resolution.fiber ??
|
|
108
|
+
fiberForNode(createLazyHostFiberIndex(), resolution.match?.instance?.ref.current);
|
|
109
|
+
return {
|
|
110
|
+
status: 'found',
|
|
111
|
+
targets: [{ host: resolution.host, ...(fiber ? { fiber } : {}) }],
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
if (resolution.status === 'absent') return { status: 'absent' };
|
|
115
|
+
// Ambiguous and unknown both fail closed. Ambiguous is a real tie, not a
|
|
116
|
+
// broken selector, so it does not warn.
|
|
117
|
+
if (resolution.status === 'ambiguous') return { status: 'unknown', silent: true };
|
|
118
|
+
return { status: 'unknown' };
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function resolveManualTargets(id: string): ElementTargetResolution {
|
|
122
|
+
const registered = anchorRegistry.getAll(id);
|
|
123
|
+
if (registered.length > 0) {
|
|
124
|
+
const index = createLazyHostFiberIndex();
|
|
125
|
+
// Registered views on a covered navigator screen still measure non-zero,
|
|
126
|
+
// so drop them here the way the fiber scan skips covered screens. A host
|
|
127
|
+
// whose fiber cannot be found is kept.
|
|
128
|
+
const targets = registered
|
|
129
|
+
.map((host): ElementTarget => {
|
|
130
|
+
const fiber = fiberForNode(index, host.node);
|
|
131
|
+
return fiber ? { host, fiber } : { host };
|
|
132
|
+
})
|
|
133
|
+
.filter((target) => !target.fiber || isFiberOnVisibleScreen(target.fiber));
|
|
134
|
+
return targets.length > 0 ? { status: 'found', targets } : { status: 'absent' };
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const root = fiberScanRoot.getFiber();
|
|
138
|
+
if (!root) return { status: 'absent' };
|
|
139
|
+
|
|
140
|
+
const found = findAnchorFibers(root, id);
|
|
141
|
+
if (found.status === 'missing') return { status: 'absent' };
|
|
142
|
+
|
|
143
|
+
return {
|
|
144
|
+
status: 'found',
|
|
145
|
+
targets: found.fibers.map((fiber) => {
|
|
146
|
+
const node = publicInstanceFromHostFiber(fiber);
|
|
147
|
+
return {
|
|
148
|
+
host: {
|
|
149
|
+
measureInWindow: createFiberMeasureInWindow(fiber),
|
|
150
|
+
...(node ? { node } : {}),
|
|
151
|
+
},
|
|
152
|
+
fiber,
|
|
153
|
+
};
|
|
154
|
+
}),
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function fiberForNode(index: HostFiberIndexSource, node: unknown): AnyFiber | undefined {
|
|
159
|
+
if (!node) return undefined;
|
|
160
|
+
try {
|
|
161
|
+
return lookupHostFiber(index, node) ?? undefined;
|
|
162
|
+
} catch {
|
|
163
|
+
return undefined;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
@@ -31,6 +31,17 @@ export interface TouchPoint {
|
|
|
31
31
|
pageY: number;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
+
/** True when the finger moved no more than `slop` between start and end. */
|
|
35
|
+
export function withinTapSlop(
|
|
36
|
+
start: TouchPoint,
|
|
37
|
+
end: TouchPoint,
|
|
38
|
+
slop: number = TARGET_PRESS_TAP_SLOP,
|
|
39
|
+
): boolean {
|
|
40
|
+
const dx = end.pageX - start.pageX;
|
|
41
|
+
const dy = end.pageY - start.pageY;
|
|
42
|
+
return dx * dx + dy * dy <= slop * slop;
|
|
43
|
+
}
|
|
44
|
+
|
|
34
45
|
/**
|
|
35
46
|
* True when start and end both land in `rect` and movement stays within tap
|
|
36
47
|
* slop — mirrors a DOM click on the target without claiming the responder.
|
|
@@ -43,9 +54,7 @@ export function isTargetTap(
|
|
|
43
54
|
): boolean {
|
|
44
55
|
if (!pointInRect(start.pageX, start.pageY, rect)) return false;
|
|
45
56
|
if (!pointInRect(end.pageX, end.pageY, rect)) return false;
|
|
46
|
-
|
|
47
|
-
const dy = end.pageY - start.pageY;
|
|
48
|
-
return dx * dx + dy * dy <= slop * slop;
|
|
57
|
+
return withinTapSlop(start, end, slop);
|
|
49
58
|
}
|
|
50
59
|
|
|
51
60
|
/**
|