@bugsee/react-native 0.0.0-stage → 7.0.0-beta1
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/BugseeReactNative.podspec +95 -0
- package/LICENSE +21 -0
- package/README.md +552 -2
- package/android/build.gradle +162 -0
- package/android/consumer-rules.pro +2 -0
- package/android/src/main/AndroidManifest.xml +33 -0
- package/android/src/main/java/com/bugsee/reactnative/AppearanceBridge.java +82 -0
- package/android/src/main/java/com/bugsee/reactnative/AttributeBridge.java +209 -0
- package/android/src/main/java/com/bugsee/reactnative/BreadcrumbFilterBridge.java +443 -0
- package/android/src/main/java/com/bugsee/reactnative/BridgeJson.java +168 -0
- package/android/src/main/java/com/bugsee/reactnative/BugseeModule.java +1869 -0
- package/android/src/main/java/com/bugsee/reactnative/BugseeOptionEnums.java +136 -0
- package/android/src/main/java/com/bugsee/reactnative/BugseePackage.java +42 -0
- package/android/src/main/java/com/bugsee/reactnative/BugseeReactNativeWrapper.java +200 -0
- package/android/src/main/java/com/bugsee/reactnative/BugseeStatusMapper.java +66 -0
- package/android/src/main/java/com/bugsee/reactnative/BugseeTokens.java +22 -0
- package/android/src/main/java/com/bugsee/reactnative/ConsoleEchoDedup.java +202 -0
- package/android/src/main/java/com/bugsee/reactnative/CreatedReports.java +127 -0
- package/android/src/main/java/com/bugsee/reactnative/DataRequestBridge.java +375 -0
- package/android/src/main/java/com/bugsee/reactnative/ExceptionBridge.java +88 -0
- package/android/src/main/java/com/bugsee/reactnative/ExceptionExecutors.java +33 -0
- package/android/src/main/java/com/bugsee/reactnative/LogFilterBridge.java +375 -0
- package/android/src/main/java/com/bugsee/reactnative/NetworkEvents.java +227 -0
- package/android/src/main/java/com/bugsee/reactnative/NetworkFilterBridge.java +498 -0
- package/android/src/main/java/com/bugsee/reactnative/PluginEndpoint.java +48 -0
- package/android/src/main/java/com/bugsee/reactnative/ReactNativeWebException.java +19 -0
- package/android/src/main/java/com/bugsee/reactnative/ReactNativeWrapperInitProvider.java +61 -0
- package/android/src/main/java/com/bugsee/reactnative/ReactRootOriginTracker.java +867 -0
- package/android/src/main/java/com/bugsee/reactnative/ReportArgs.java +58 -0
- package/android/src/main/java/com/bugsee/reactnative/ReportHandlerBridge.java +336 -0
- package/android/src/main/java/com/bugsee/reactnative/ReportHandlerDeadlines.java +57 -0
- package/android/src/main/java/com/bugsee/reactnative/ReportOps.java +287 -0
- package/android/src/main/java/com/bugsee/reactnative/SecureRectanglePulls.java +113 -0
- package/android/src/main/java/com/bugsee/reactnative/SecureRectangleStore.java +692 -0
- package/android/src/main/java/com/bugsee/reactnative/SpanHandles.java +143 -0
- package/android/src/main/java/com/bugsee/reactnative/WrapperChannelHolder.java +137 -0
- package/android/src/main/java/com/bugsee/reactnative/WrapperEventBus.java +110 -0
- package/android/src/main/java/com/bugsee/reactnative/WrapperRegistrar.java +54 -0
- package/app.plugin.js +4 -0
- package/ios/BGSRNConsoleCapture.h +52 -0
- package/ios/BGSRNConsoleCapture.mm +344 -0
- package/ios/BugseeModule.h +25 -0
- package/ios/BugseeModule.mm +2728 -0
- package/ios/Package.swift +71 -0
- package/ios/Support/Package.resolved +14 -0
- package/ios/Support/Package.swift +44 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNAttributes.m +52 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNCreatedReportOps.m +236 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNCreatedReports.m +184 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNDataRequestBridge.m +431 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNErrorMessage.m +40 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNEventBus.m +70 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNExceptions.m +63 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNGuardedEmit.mm +32 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNJSON.m +40 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNLaunchHold.m +147 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNMainThread.m +23 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNNetworkEvents.m +159 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNNetworkFilter.m +155 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNPluginEndpoint.m +21 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNReactRootOriginTracker.m +63 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNReactWindow.m +251 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNReportArgs.m +47 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNReportDeadlines.m +8 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNReportHandlerBridge.m +308 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNReportOps.m +345 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNSecureRectangles.m +508 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNSettleOnce.m +62 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNSpanHandles.m +136 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNStatusMapper.m +18 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNTokens.m +9 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNValues.m +5 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNWrapper.m +54 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNWrapperChannelHolder.m +59 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNAttributes.h +63 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNCreatedReportOps.h +51 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNCreatedReports.h +81 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNDataRequestBridge.h +118 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNErrorMessage.h +30 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNEventBus.h +45 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNExceptions.h +31 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNGuardedEmit.h +31 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNJSON.h +25 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNLaunchHold.h +86 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNMainThread.h +32 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNNetworkEvents.h +28 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNNetworkFilter.h +28 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNPluginEndpoint.h +17 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReactRootOriginTracker.h +48 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReactWindow.h +135 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReportArgs.h +17 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReportDeadlines.h +37 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReportHandlerBridge.h +94 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReportOps.h +86 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNSecureRectangles.h +198 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNSettleOnce.h +25 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNSpanHandles.h +49 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNStatusMapper.h +26 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNTokens.h +14 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNValues.h +18 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNWrapper.h +40 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNWrapperChannelHolder.h +74 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNAttributesTests.m +194 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNCreatedReportOpsTests.m +274 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNCreatedReportsTests.m +240 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNDataRequestBridgeTests.m +685 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNErrorMessageTests.m +102 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNEventBusTests.m +136 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNExceptionsTests.m +68 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNFakeReport.h +41 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNFakeReport.m +166 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNGuardedEmitTests.mm +85 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNJSONTests.m +281 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNLaunchHoldTests.m +230 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNMainThreadTests.m +97 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNNetworkEventsTests.m +99 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNNetworkFilterTests.m +134 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNPluginEndpointTests.m +38 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReactRootOriginTrackerTests.m +210 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReactWindowTests.m +548 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReportArgsTests.m +51 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReportDeadlinesTests.m +22 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReportHandlerBridgeTests.m +382 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReportOpsTests.m +295 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNSecureRectanglesTests.m +568 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNSettleOnceTests.m +134 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNSpanHandlesTests.m +153 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNStatusMapperTests.m +81 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNValuesTests.m +32 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNWrapperChannelHolderTests.m +205 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNWrapperTests.m +66 -0
- package/ios/react-native-spm-prefix.h +10 -0
- package/native-versions.json +10 -0
- package/package.json +62 -3
- package/plugin/build/bundle-phase.d.ts +41 -0
- package/plugin/build/bundle-phase.js +116 -0
- package/plugin/build/bundle-phase.js.map +1 -0
- package/plugin/build/dsym-script.d.ts +32 -0
- package/plugin/build/dsym-script.js +159 -0
- package/plugin/build/dsym-script.js.map +1 -0
- package/plugin/build/endpoint.d.ts +30 -0
- package/plugin/build/endpoint.js +69 -0
- package/plugin/build/endpoint.js.map +1 -0
- package/plugin/build/gradle.d.ts +65 -0
- package/plugin/build/gradle.js +1066 -0
- package/plugin/build/gradle.js.map +1 -0
- package/plugin/build/index.d.ts +85 -0
- package/plugin/build/index.js +217 -0
- package/plugin/build/index.js.map +1 -0
- package/plugin/build/manifest.d.ts +48 -0
- package/plugin/build/manifest.js +69 -0
- package/plugin/build/manifest.js.map +1 -0
- package/plugin/build/native-versions.baked.json +4 -0
- package/plugin/build/native-versions.d.ts +10 -0
- package/plugin/build/native-versions.js +27 -0
- package/plugin/build/native-versions.js.map +1 -0
- package/plugin/build/pbx-string.d.ts +8 -0
- package/plugin/build/pbx-string.js +31 -0
- package/plugin/build/pbx-string.js.map +1 -0
- package/plugin/build/podfile.d.ts +3 -0
- package/plugin/build/podfile.js +28 -0
- package/plugin/build/podfile.js.map +1 -0
- package/plugin/build/properties.d.ts +19 -0
- package/plugin/build/properties.js +41 -0
- package/plugin/build/properties.js.map +1 -0
- package/plugin/build/scheme.d.ts +20 -0
- package/plugin/build/scheme.js +107 -0
- package/plugin/build/scheme.js.map +1 -0
- package/react-native.config.js +26 -0
- package/scripts/bugsee-sourcemaps.gradle +201 -0
- package/scripts/bugsee-xcode.sh +83 -0
- package/scripts/compose-then-inject.js +113 -0
- package/scripts/hermes-sourcemaps.js +634 -0
- package/scripts/hermesc-preserve-js.cmd +6 -0
- package/scripts/hermesc-preserve-js.js +200 -0
- package/scripts/hermesc-preserve-js.sh +7 -0
- package/src/NativeBugsee.ts +622 -0
- package/src/apm/notify.ts +58 -0
- package/src/apm/span.ts +403 -0
- package/src/apm/types.ts +57 -0
- package/src/appearance/report.ts +171 -0
- package/src/architecture.ts +48 -0
- package/src/attributes/errors.ts +39 -0
- package/src/attributes/validate.ts +150 -0
- package/src/breadcrumbs/add.ts +58 -0
- package/src/breadcrumbs/data.ts +33 -0
- package/src/breadcrumbs/filter.ts +215 -0
- package/src/breadcrumbs/types.ts +64 -0
- package/src/bridge/json.ts +110 -0
- package/src/console/capture.ts +180 -0
- package/src/console/dedup.ts +175 -0
- package/src/data/validate.ts +259 -0
- package/src/errorName.ts +32 -0
- package/src/exceptions/ErrorBoundary.tsx +92 -0
- package/src/exceptions/RootErrorReporter.tsx +61 -0
- package/src/exceptions/debugIds.ts +118 -0
- package/src/exceptions/handlers.ts +236 -0
- package/src/exceptions/options.ts +85 -0
- package/src/exceptions/payload.ts +456 -0
- package/src/exceptions/report.ts +170 -0
- package/src/exceptions/sha1.ts +148 -0
- package/src/exceptions/stack.ts +355 -0
- package/src/index.ts +944 -0
- package/src/logs/filter.ts +90 -0
- package/src/logs/log.ts +36 -0
- package/src/network/add.ts +165 -0
- package/src/network/filter.ts +198 -0
- package/src/options/AndroidLaunchOptions.ts +78 -0
- package/src/options/BugseeLaunchOptions.ts +190 -0
- package/src/options/IOSLaunchOptions.ts +57 -0
- package/src/options/android-options-manifest.json +646 -0
- package/src/options/createDefaultLaunchOptions.ts +29 -0
- package/src/options/endpoint.ts +58 -0
- package/src/options/enums.ts +104 -0
- package/src/options/ios-enums.json +19 -0
- package/src/options/keys.ts +39 -0
- package/src/options/option-enums.json +34 -0
- package/src/options/option-keys.json +107 -0
- package/src/report/BugseeReport.ts +264 -0
- package/src/report/CreatedReport.ts +127 -0
- package/src/report/dispatcher.ts +95 -0
- package/src/report/errors.ts +48 -0
- package/src/report/fields.ts +40 -0
- package/src/report/types.ts +157 -0
- package/src/report/validate.ts +197 -0
- package/src/secure/BugseeSecure.tsx +202 -0
- package/src/secure/ancestry.ts +622 -0
- package/src/secure/drivers.ts +342 -0
- package/src/secure/followEvents.ts +57 -0
- package/src/secure/hold.ts +99 -0
- package/src/secure/measureLoop.ts +323 -0
- package/src/secure/nativeAnimation.ts +1005 -0
- package/src/secure/rectangles.ts +93 -0
- package/src/secure/registry.ts +237 -0
- package/src/secure/surface.ts +83 -0
- package/src/secure/tracker.ts +723 -0
- package/src/secure/transition.ts +488 -0
- package/src/secure/unit.ts +22 -0
- package/src/status.ts +16 -0
- package/src/version.ts +9 -0
- package/src/viewtree/anchor.tsx +105 -0
- package/src/viewtree/constants.ts +20 -0
- package/src/viewtree/fiber.ts +251 -0
- package/src/viewtree/requests.ts +347 -0
- package/src/viewtree/walk.ts +902 -0
- package/src/wrapper/channel.ts +33 -0
- package/src/wrapper/collect.ts +52 -0
- package/src/wrapper/events.ts +45 -0
- package/src/wrapper/identity.ts +54 -0
- package/src/wrapper/lifecycle-events.ts +89 -0
|
@@ -0,0 +1,622 @@
|
|
|
1
|
+
import { FiberTag } from '../viewtree/fiber';
|
|
2
|
+
import type { FiberLike, WindowRect } from '../viewtree/fiber';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* What lies between a `<BugseeSecure>` and its surface's root, read off the
|
|
6
|
+
* fiber tree once per mount, and what that says each tick about how much of
|
|
7
|
+
* the view is really on screen.
|
|
8
|
+
*
|
|
9
|
+
* Fabric `measureInWindow` is shadow-tree layout: it ignores every ancestor's
|
|
10
|
+
* clipping. So a region scrolled out of its ScrollView would still be
|
|
11
|
+
* published. This module finds the ancestors that clip the view, so the
|
|
12
|
+
* component can intersect its rectangle with them, and the one kind of
|
|
13
|
+
* ancestor that hides a view without touching its layout: an inactive
|
|
14
|
+
* react-native-screens screen, which stays mounted with its layout intact.
|
|
15
|
+
*
|
|
16
|
+
* Everything else that hides a view already shows in its layout, so it is
|
|
17
|
+
* left to the shadow tree: a `display: 'none'` subtree, and the content of a
|
|
18
|
+
* hidden Offscreen (`<Activity>`, Suspense), which Fabric hides by cloning
|
|
19
|
+
* its hosts with `display: 'none'` (`cloneHiddenInstance`), both measure
|
|
20
|
+
* 0x0, which publishes nothing. A frozen react-native-screens screen is
|
|
21
|
+
* hidden Offscreen content that stays drawn (`RNSScreen` nulls `display` in
|
|
22
|
+
* its view config for exactly that), and it keeps its layout, so it stays
|
|
23
|
+
* masked.
|
|
24
|
+
*
|
|
25
|
+
* Every rule leans towards masking: a view is hidden only on positive
|
|
26
|
+
* committed evidence, and an ancestor that cannot be read or measured clips
|
|
27
|
+
* nothing.
|
|
28
|
+
*
|
|
29
|
+
* Committed props come from the CURRENT fiber of each ancestor. A fiber and
|
|
30
|
+
* its alternate swap roles on every update, a stored `.return` chain can run
|
|
31
|
+
* through either, and both a work-in-progress fiber's `memoizedProps` and a
|
|
32
|
+
* Fabric host's `canonical.currentProps` are written during render, before
|
|
33
|
+
* (and whether or not) that render commits. The fiber root's `current` is
|
|
34
|
+
* the committed tree, and its `.child`/`.sibling` links are the committed
|
|
35
|
+
* links, so each tick resolves the stored path top-down from it, taking at
|
|
36
|
+
* every level whichever of the stored fiber and its alternate is a child of
|
|
37
|
+
* the current parent. A path that does not resolve is unknown: nothing is
|
|
38
|
+
* hidden and nothing clipped.
|
|
39
|
+
*/
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Host types whose own bounds clip their content, unless styled
|
|
43
|
+
* `overflow: 'visible'` (iOS: `clipsToBounds = getClipsContentToBounds()`): a
|
|
44
|
+
* ScrollView's viewport (`ScrollViewNativeComponent`, vertical on both
|
|
45
|
+
* platforms and horizontal on iOS, and
|
|
46
|
+
* `AndroidHorizontalScrollViewNativeComponent`). Their content containers
|
|
47
|
+
* scroll with the content and clip nothing.
|
|
48
|
+
*/
|
|
49
|
+
export const SCROLL_HOST_TYPES: ReadonlySet<unknown> = new Set(['RCTScrollView', 'AndroidHorizontalScrollView']);
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Host types whose shadow node is `RootNodeKind`: `measureInWindow` stops
|
|
53
|
+
* there (`LayoutableShadowNode::computeRelativeLayoutMetrics`) and natively
|
|
54
|
+
* their content is drawn outside the hosts above, so nothing above one
|
|
55
|
+
* clips or hides what is inside, and the host itself clips nothing (only
|
|
56
|
+
* {@link MODAL_SCREEN_HOST_TYPE} can hide it). React Native's `<Modal>` and
|
|
57
|
+
* `<InputAccessoryView>` (the JS names are their `paperComponentName`s),
|
|
58
|
+
* and react-native-screens' `FullWindowOverlay`, modal screen and split
|
|
59
|
+
* screen, plus its gamma form sheet host. A `HostPortal` fiber ends the walk
|
|
60
|
+
* the same way: its children are drawn in another container.
|
|
61
|
+
*/
|
|
62
|
+
export const ROOT_KIND_HOST_TYPES: ReadonlySet<unknown> = new Set([
|
|
63
|
+
'RCTModalHostView',
|
|
64
|
+
'RCTInputAccessoryView',
|
|
65
|
+
'RNSFullWindowOverlay',
|
|
66
|
+
'RNSModalScreen',
|
|
67
|
+
'RNSSplitScreen',
|
|
68
|
+
// Not RootNodeKind, but its content is presented in a sheet of its own.
|
|
69
|
+
'RNSFormSheetHost',
|
|
70
|
+
]);
|
|
71
|
+
|
|
72
|
+
/** react-native-screens' screen host (`ScreenNativeComponent`). */
|
|
73
|
+
export const SCREEN_HOST_TYPE = 'RNSScreen';
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* react-native-screens' iOS modal screen host (`ModalScreenNativeComponent`),
|
|
77
|
+
* which takes `activityState` like a screen. It is also root-kind, so it ends
|
|
78
|
+
* the walk: it can hide what is inside it, but never clips it.
|
|
79
|
+
*/
|
|
80
|
+
export const MODAL_SCREEN_HOST_TYPE = 'RNSModalScreen';
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* The react-native-screens containers whose screens `activityState` 0 really
|
|
84
|
+
* hides (detaches): a screen hides the view only when the nearest host above
|
|
85
|
+
* it is one of these. Anywhere else the prop proves nothing.
|
|
86
|
+
*/
|
|
87
|
+
export const SCREEN_CONTAINER_HOST_TYPES: ReadonlySet<unknown> = new Set([
|
|
88
|
+
'RNSScreenContainer',
|
|
89
|
+
'RNSScreenNavigationContainer',
|
|
90
|
+
'RNSScreenStack',
|
|
91
|
+
]);
|
|
92
|
+
|
|
93
|
+
/** `activityState` of an inactive react-native-screens screen. */
|
|
94
|
+
const INACTIVE_SCREEN = 0;
|
|
95
|
+
|
|
96
|
+
/** What a host's `props` holds before its first read: equal to no props object. */
|
|
97
|
+
const UNREAD: unique symbol = Symbol('unread');
|
|
98
|
+
|
|
99
|
+
/** A cycle in a malformed tree must not spin forever. */
|
|
100
|
+
const MAX_ANCESTORS = 10_000;
|
|
101
|
+
|
|
102
|
+
type MeasureInWindow = (callback: (x: number, y: number, width: number, height: number) => void) => void;
|
|
103
|
+
|
|
104
|
+
interface HostAncestor {
|
|
105
|
+
/** Where the host is in `Ancestry.path`. */
|
|
106
|
+
readonly index: number;
|
|
107
|
+
/** Where the next host above it is in `Ancestry.path` (its length when there is none). */
|
|
108
|
+
above: number;
|
|
109
|
+
readonly scrolls: boolean;
|
|
110
|
+
readonly screen: boolean;
|
|
111
|
+
/** A root-kind host: it ends the walk and clips nothing. */
|
|
112
|
+
readonly boundary: boolean;
|
|
113
|
+
/** The committed props object `clips` was last read from. */
|
|
114
|
+
props: unknown;
|
|
115
|
+
clips: boolean;
|
|
116
|
+
/** The host's public instance, looked up the first time it clips. */
|
|
117
|
+
instance: { measureInWindow: MeasureInWindow } | undefined;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export interface Ancestry {
|
|
121
|
+
/** The view's own host fiber, as stored at mount; `null` when there is none. */
|
|
122
|
+
readonly self: FiberLike | null;
|
|
123
|
+
/** Every fiber above the view, nearest first, up to and including the tree's root. */
|
|
124
|
+
readonly path: readonly FiberLike[];
|
|
125
|
+
/** The fiber root (`HostRoot.stateNode`), or `null` when the path has none. */
|
|
126
|
+
readonly root: { current?: unknown } | null;
|
|
127
|
+
/** The hosts below the nearest root-kind host, nearest first. */
|
|
128
|
+
readonly hosts: readonly HostAncestor[];
|
|
129
|
+
/** The screens among `hosts`. */
|
|
130
|
+
readonly screens: readonly HostAncestor[];
|
|
131
|
+
/**
|
|
132
|
+
* Where in `path` the `Animated` components below the nearest root-kind
|
|
133
|
+
* host are (`Animated.View` and the like, nearest first): only their props
|
|
134
|
+
* can hold a native-driven transform, which the shadow tree never sees.
|
|
135
|
+
*/
|
|
136
|
+
readonly animated: readonly number[];
|
|
137
|
+
/** Whether the last {@link isHidden} read everything; `false` clips nothing. */
|
|
138
|
+
readable: boolean;
|
|
139
|
+
/** The current fibers of `path` as the last {@link isHidden} resolved them, if it did. */
|
|
140
|
+
resolved: readonly FiberLike[] | undefined;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/** Nothing above the view can be read: it is never hidden and never clipped. */
|
|
144
|
+
export function noAncestry(): Ancestry {
|
|
145
|
+
return {
|
|
146
|
+
self: null,
|
|
147
|
+
path: [],
|
|
148
|
+
root: null,
|
|
149
|
+
hosts: [],
|
|
150
|
+
screens: [],
|
|
151
|
+
animated: [],
|
|
152
|
+
readable: false,
|
|
153
|
+
resolved: undefined,
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function displayNameOf(fiber: FiberLike): unknown {
|
|
158
|
+
const type = fiber.type as { displayName?: unknown; render?: { displayName?: unknown } } | null | undefined;
|
|
159
|
+
if (type === null || (typeof type !== 'function' && typeof type !== 'object')) {
|
|
160
|
+
return undefined;
|
|
161
|
+
}
|
|
162
|
+
return type.displayName ?? type.render?.displayName;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Whether `fiber` is a Reanimated component (`createAnimatedComponent` of
|
|
167
|
+
* react-native-reanimated names every one `AnimatedComponent(<name>)`).
|
|
168
|
+
*/
|
|
169
|
+
export function isReanimatedComponent(fiber: FiberLike): boolean {
|
|
170
|
+
const name = displayNameOf(fiber);
|
|
171
|
+
return typeof name === 'string' && name.startsWith('AnimatedComponent(');
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Whether `fiber` is an `Animated` component (`Animated.createAnimatedComponent`
|
|
176
|
+
* names every one `Animated(<name>)`), as a plain function or a `forwardRef`,
|
|
177
|
+
* or a Reanimated one.
|
|
178
|
+
*/
|
|
179
|
+
export function isAnimatedComponent(fiber: FiberLike): boolean {
|
|
180
|
+
const name = displayNameOf(fiber);
|
|
181
|
+
return (typeof name === 'string' && name.startsWith('Animated(')) || isReanimatedComponent(fiber);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* The ancestors of the host `fiber`, up to the tree's root. Only the hosts
|
|
186
|
+
* below the nearest root-kind host can clip or hide it. `fiber` itself is
|
|
187
|
+
* not included.
|
|
188
|
+
*/
|
|
189
|
+
export function ancestryOfFiber(fiber: FiberLike): Ancestry {
|
|
190
|
+
const path: FiberLike[] = [];
|
|
191
|
+
const hosts: HostAncestor[] = [];
|
|
192
|
+
const animated: number[] = [];
|
|
193
|
+
let bounded = false;
|
|
194
|
+
let current = fiber.return;
|
|
195
|
+
for (let steps = 0; current != null && steps < MAX_ANCESTORS; steps += 1) {
|
|
196
|
+
bounded ||= current.tag === FiberTag.HostPortal;
|
|
197
|
+
if (current.tag === FiberTag.HostComponent) {
|
|
198
|
+
const below = hosts[hosts.length - 1];
|
|
199
|
+
if (below !== undefined && below.above === MAX_ANCESTORS) {
|
|
200
|
+
below.above = path.length;
|
|
201
|
+
}
|
|
202
|
+
const boundary = ROOT_KIND_HOST_TYPES.has(current.type);
|
|
203
|
+
if (!bounded && (!boundary || current.type === MODAL_SCREEN_HOST_TYPE)) {
|
|
204
|
+
hosts.push({
|
|
205
|
+
index: path.length,
|
|
206
|
+
above: MAX_ANCESTORS,
|
|
207
|
+
scrolls: SCROLL_HOST_TYPES.has(current.type),
|
|
208
|
+
screen: current.type === SCREEN_HOST_TYPE || current.type === MODAL_SCREEN_HOST_TYPE,
|
|
209
|
+
boundary,
|
|
210
|
+
props: UNREAD,
|
|
211
|
+
clips: false,
|
|
212
|
+
instance: undefined,
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
bounded ||= boundary;
|
|
216
|
+
} else if (!bounded && isAnimatedComponent(current)) {
|
|
217
|
+
animated.push(path.length);
|
|
218
|
+
}
|
|
219
|
+
path.push(current);
|
|
220
|
+
current = current.return;
|
|
221
|
+
}
|
|
222
|
+
const last = hosts[hosts.length - 1];
|
|
223
|
+
if (last !== undefined && last.above === MAX_ANCESTORS) {
|
|
224
|
+
last.above = path.length;
|
|
225
|
+
}
|
|
226
|
+
const top = path[path.length - 1];
|
|
227
|
+
const root = top?.tag === FiberTag.HostRoot ? (top.stateNode as { current?: unknown } | null) : null;
|
|
228
|
+
return {
|
|
229
|
+
self: fiber,
|
|
230
|
+
path,
|
|
231
|
+
root,
|
|
232
|
+
hosts,
|
|
233
|
+
screens: hosts.filter((host) => host.screen),
|
|
234
|
+
animated,
|
|
235
|
+
readable: false,
|
|
236
|
+
resolved: undefined,
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* The ancestry of a mounted host's public instance (Fabric's carries its
|
|
242
|
+
* fiber as `__internalInstanceHandle`). {@link noAncestry} when there is no
|
|
243
|
+
* fiber or the tree cannot be read.
|
|
244
|
+
*/
|
|
245
|
+
export function ancestryOfInstance(instance: object): Ancestry {
|
|
246
|
+
try {
|
|
247
|
+
// No fiber (or not an object) has no `.return`; `null` throws on reading it.
|
|
248
|
+
const fiber = (instance as { __internalInstanceHandle?: unknown }).__internalInstanceHandle;
|
|
249
|
+
if (typeof fiber !== 'object') {
|
|
250
|
+
return noAncestry();
|
|
251
|
+
}
|
|
252
|
+
return ancestryOfFiber(fiber as FiberLike);
|
|
253
|
+
} catch {
|
|
254
|
+
return noAncestry();
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* Each current parent's children, collected in the running pass the first
|
|
260
|
+
* time any view looks among them, so views that are siblings in a long list
|
|
261
|
+
* scan that list once a pass rather than once each.
|
|
262
|
+
*/
|
|
263
|
+
let passChildren: Map<FiberLike, Set<FiberLike>> | undefined;
|
|
264
|
+
|
|
265
|
+
/** The child of `parent` (a current fiber) that is `fiber` or its alternate, if any. */
|
|
266
|
+
function currentChild(parent: FiberLike, fiber: FiberLike): FiberLike | undefined {
|
|
267
|
+
let children = passChildren?.get(parent);
|
|
268
|
+
if (children === undefined) {
|
|
269
|
+
children = new Set();
|
|
270
|
+
for (let child = parent.child; child != null; child = child.sibling) {
|
|
271
|
+
children.add(child);
|
|
272
|
+
}
|
|
273
|
+
passChildren?.set(parent, children);
|
|
274
|
+
}
|
|
275
|
+
// No child is null or undefined, so a missing alternate is never found.
|
|
276
|
+
const alternate = fiber.alternate as FiberLike;
|
|
277
|
+
return children.has(fiber) ? fiber : children.has(alternate) ? alternate : undefined;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* The current fiber of every fiber in `ancestry.path` from `downTo` up, in
|
|
282
|
+
* the same order (entries below `downTo` are left as the root), or
|
|
283
|
+
* `undefined` when the path does not resolve against the committed tree.
|
|
284
|
+
* Reads fibers only, which React never makes throw.
|
|
285
|
+
*
|
|
286
|
+
* Nothing is kept from one pass to the next: React keeps no commit count, and
|
|
287
|
+
* the root's `current` alternates between the same two fibers, so a cached
|
|
288
|
+
* level cannot be told apart from one two commits stale.
|
|
289
|
+
*/
|
|
290
|
+
function resolve(ancestry: Ancestry, downTo = 0): FiberLike[] | undefined {
|
|
291
|
+
const { path, root } = ancestry;
|
|
292
|
+
// A root exists only on a path that ends at one.
|
|
293
|
+
const top = path[path.length - 1] as FiberLike;
|
|
294
|
+
const rootCurrent = root?.current as FiberLike | null | undefined;
|
|
295
|
+
if (rootCurrent == null || (rootCurrent !== top && rootCurrent !== top.alternate)) {
|
|
296
|
+
return undefined;
|
|
297
|
+
}
|
|
298
|
+
// The root's entry stays; every other is replaced below, or the path does
|
|
299
|
+
// not resolve.
|
|
300
|
+
const resolved = path.map(() => rootCurrent);
|
|
301
|
+
for (let index = path.length - 2; index >= downTo; index -= 1) {
|
|
302
|
+
const current = currentChild(resolved[index + 1] as FiberLike, path[index] as FiberLike);
|
|
303
|
+
if (current === undefined) {
|
|
304
|
+
return undefined;
|
|
305
|
+
}
|
|
306
|
+
resolved[index] = current;
|
|
307
|
+
}
|
|
308
|
+
return resolved;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* `key` of a style as React Native flattens it: the last value set wins,
|
|
313
|
+
* through nested arrays; falsy entries are skipped.
|
|
314
|
+
*/
|
|
315
|
+
export function styleValue(style: unknown, key: string): unknown {
|
|
316
|
+
if (Array.isArray(style)) {
|
|
317
|
+
return style.reduceRight<unknown>(
|
|
318
|
+
(found, entry) => (found !== undefined ? found : styleValue(entry, key)),
|
|
319
|
+
undefined,
|
|
320
|
+
);
|
|
321
|
+
}
|
|
322
|
+
if (style !== null && typeof style === 'object') {
|
|
323
|
+
return (style as Record<string, unknown>)[key];
|
|
324
|
+
}
|
|
325
|
+
return undefined;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* An `activityState` set on a fiber between a screen host and the host
|
|
330
|
+
* above it (the `Animated.createAnimatedComponent` wrapper react-native-screens
|
|
331
|
+
* renders the host through) that is not a plain number: an Animated node,
|
|
332
|
+
* whose value native drives without React committing it.
|
|
333
|
+
*/
|
|
334
|
+
function animatedActivity(resolved: readonly FiberLike[], from: number, to: number): boolean {
|
|
335
|
+
for (let index = from; index < to; index += 1) {
|
|
336
|
+
const value = ((resolved[index] as FiberLike).memoizedProps as { activityState?: unknown } | null)
|
|
337
|
+
?.activityState;
|
|
338
|
+
if (value !== null && typeof value === 'object') {
|
|
339
|
+
return true;
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
return false;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
/** Re-reads `host`'s clip from its current fiber, if its committed props changed. */
|
|
346
|
+
function refresh(host: HostAncestor, resolved: readonly FiberLike[]): void {
|
|
347
|
+
const props = (resolved[host.index] as FiberLike).memoizedProps;
|
|
348
|
+
if (props !== host.props) {
|
|
349
|
+
const overflow = styleValue((props as { style?: unknown } | null)?.style, 'overflow');
|
|
350
|
+
host.clips = !host.boundary && (host.scrolls ? overflow !== 'visible' : overflow === 'hidden');
|
|
351
|
+
// Only once read: a read that threw is tried again next time.
|
|
352
|
+
host.props = props;
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
/**
|
|
357
|
+
* Whether `screen` hides the view in the committed tree: `activityState` 0
|
|
358
|
+
* on its current fiber, not driven by an Animated node on the wrapper above
|
|
359
|
+
* it, under a react-native-screens container that detaches inactive screens.
|
|
360
|
+
*/
|
|
361
|
+
function screenHides(screen: HostAncestor, ancestry: Ancestry, resolved: readonly FiberLike[]): boolean {
|
|
362
|
+
const activityState = ((resolved[screen.index] as FiberLike).memoizedProps as { activityState?: unknown } | null)
|
|
363
|
+
?.activityState;
|
|
364
|
+
return (
|
|
365
|
+
activityState === INACTIVE_SCREEN &&
|
|
366
|
+
SCREEN_CONTAINER_HOST_TYPES.has(ancestry.path[screen.above]?.type) &&
|
|
367
|
+
!animatedActivity(resolved, screen.index + 1, screen.above)
|
|
368
|
+
);
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
/**
|
|
372
|
+
* Whether a react-native-screens screen above the view is inactive in the
|
|
373
|
+
* committed tree (see `screenHides`). Also reads which hosts clip, for
|
|
374
|
+
* {@link clipToAncestors}. When anything cannot be read (the path does not
|
|
375
|
+
* resolve, or a props read throws) the answer is `false` and nothing is
|
|
376
|
+
* clipped either.
|
|
377
|
+
*/
|
|
378
|
+
export function isHidden(ancestry: Ancestry): boolean {
|
|
379
|
+
ancestry.readable = false;
|
|
380
|
+
const resolved = resolve(ancestry);
|
|
381
|
+
ancestry.resolved = resolved;
|
|
382
|
+
if (resolved === undefined) {
|
|
383
|
+
return false;
|
|
384
|
+
}
|
|
385
|
+
// Props are the app's: a getter on one can throw.
|
|
386
|
+
try {
|
|
387
|
+
for (const host of ancestry.hosts) {
|
|
388
|
+
refresh(host, resolved);
|
|
389
|
+
}
|
|
390
|
+
const hidden = ancestry.screens.some((screen) => screenHides(screen, ancestry, resolved));
|
|
391
|
+
ancestry.readable = true;
|
|
392
|
+
return hidden;
|
|
393
|
+
} catch {
|
|
394
|
+
return false;
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
/**
|
|
399
|
+
* The screens alone of {@link isHidden}, for a view withdrawn as hidden to
|
|
400
|
+
* check every frame: it resolves the path only down to the nearest screen,
|
|
401
|
+
* and only once a pass for every view under the same screen.
|
|
402
|
+
*/
|
|
403
|
+
export function screensHide(ancestry: Ancestry): boolean {
|
|
404
|
+
const nearest = ancestry.screens[0];
|
|
405
|
+
if (nearest === undefined) {
|
|
406
|
+
return false;
|
|
407
|
+
}
|
|
408
|
+
const key = ancestry.path[nearest.index] as FiberLike;
|
|
409
|
+
const known = passScreens?.get(key);
|
|
410
|
+
if (known !== undefined) {
|
|
411
|
+
return known;
|
|
412
|
+
}
|
|
413
|
+
const resolved = resolve(ancestry, nearest.index);
|
|
414
|
+
let hidden: boolean;
|
|
415
|
+
// An unresolved path (`undefined`) throws here as a props getter can.
|
|
416
|
+
try {
|
|
417
|
+
hidden = ancestry.screens.some((screen) => screenHides(screen, ancestry, resolved as FiberLike[]));
|
|
418
|
+
} catch {
|
|
419
|
+
hidden = false;
|
|
420
|
+
}
|
|
421
|
+
passScreens?.set(key, hidden).set(key.alternate, hidden);
|
|
422
|
+
return hidden;
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
/** {@link screensHide}'s answers in the running pass, by both fibers of the nearest screen. */
|
|
426
|
+
let passScreens: Map<FiberLike | null | undefined, boolean> | undefined;
|
|
427
|
+
|
|
428
|
+
/**
|
|
429
|
+
* How many component fibers can stand between a ScrollView's host and its
|
|
430
|
+
* content container's host: on Android a vertical ScrollView renders its
|
|
431
|
+
* content through the `View` component (`VScrollContentViewNativeComponent`).
|
|
432
|
+
*/
|
|
433
|
+
export const CONTENT_DEPTH = 4;
|
|
434
|
+
|
|
435
|
+
/**
|
|
436
|
+
* The nodes whose movement can change how `ancestry`'s clipping ancestors
|
|
437
|
+
* (as the last {@link isHidden} read them) cut the view: every clipping
|
|
438
|
+
* host itself, whose bounds are the clip (a viewport that grows uncovers
|
|
439
|
+
* more of the view), and a ScrollView's content container, which moves as
|
|
440
|
+
* it scrolls: the nearest host below it on the way to the view.
|
|
441
|
+
*/
|
|
442
|
+
export function clipWatchNodes(ancestry: Ancestry): FiberLike[] {
|
|
443
|
+
if (!ancestry.readable) {
|
|
444
|
+
return [];
|
|
445
|
+
}
|
|
446
|
+
return ancestry.hosts
|
|
447
|
+
.filter((host) => host.clips)
|
|
448
|
+
.flatMap((host) => {
|
|
449
|
+
const clipper = ancestry.path[host.index] as FiberLike;
|
|
450
|
+
const below = ancestry.path
|
|
451
|
+
.slice(Math.max(0, host.index - CONTENT_DEPTH), host.index)
|
|
452
|
+
.reverse()
|
|
453
|
+
.find((fiber) => fiber.tag === FiberTag.HostComponent);
|
|
454
|
+
return host.scrolls && below !== undefined ? [below, clipper] : [clipper];
|
|
455
|
+
});
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
/**
|
|
459
|
+
* A ScrollView host's content container: the first host down its first
|
|
460
|
+
* children, through at most {@link CONTENT_DEPTH} components; `undefined`
|
|
461
|
+
* when there is none.
|
|
462
|
+
*/
|
|
463
|
+
export function contentOf(scroller: FiberLike): FiberLike | undefined {
|
|
464
|
+
let fiber = scroller.child;
|
|
465
|
+
for (let depth = 0; fiber != null && depth < CONTENT_DEPTH; depth += 1) {
|
|
466
|
+
if (fiber.tag === FiberTag.HostComponent) {
|
|
467
|
+
return fiber;
|
|
468
|
+
}
|
|
469
|
+
fiber = fiber.child;
|
|
470
|
+
}
|
|
471
|
+
return undefined;
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
/** Public instances of watched nodes, looked up once each. */
|
|
475
|
+
const nodeInstances = new WeakMap<FiberLike, { measureInWindow: MeasureInWindow }>();
|
|
476
|
+
|
|
477
|
+
/** `fiber`'s window rectangle, as {@link measureHost} answers, measured at most once a pass. */
|
|
478
|
+
export function measureFiber(fiber: FiberLike): WindowRect | null | undefined {
|
|
479
|
+
let instance = nodeInstances.get(fiber);
|
|
480
|
+
if (instance === undefined) {
|
|
481
|
+
instance = publicInstanceOf(fiber);
|
|
482
|
+
nodeInstances.set(fiber, instance);
|
|
483
|
+
}
|
|
484
|
+
return measureInstance(instance);
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
function publicInstanceOf(fiber: FiberLike): { measureInWindow: MeasureInWindow } {
|
|
488
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports -- lazy, like surface.ts: only a renderer has it.
|
|
489
|
+
const rendererProxy = require('react-native/Libraries/ReactNative/RendererProxy') as {
|
|
490
|
+
getPublicInstanceFromInternalInstanceHandle: (fiber: unknown) => { measureInWindow: MeasureInWindow };
|
|
491
|
+
};
|
|
492
|
+
return rendererProxy.getPublicInstanceFromInternalInstanceHandle(fiber);
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
/**
|
|
496
|
+
* The clipping ancestors measured in the running {@link measurePass}, by
|
|
497
|
+
* public instance: views under one ScrollView all clip to it, and measure it
|
|
498
|
+
* once a pass. `undefined` outside a pass, which measures every time.
|
|
499
|
+
*/
|
|
500
|
+
let passMeasurements: Map<object, WindowRect | null | undefined> | undefined;
|
|
501
|
+
|
|
502
|
+
/**
|
|
503
|
+
* Runs `pass` with each clipping ancestor measured, and each ancestor's
|
|
504
|
+
* current fiber resolved, at most once. Only for a synchronous stretch of JS
|
|
505
|
+
* (the re-measure loop's tick): no commit can move anything while it runs.
|
|
506
|
+
*/
|
|
507
|
+
export function measurePass(pass: () => void): void {
|
|
508
|
+
passMeasurements = new Map();
|
|
509
|
+
passChildren = new Map();
|
|
510
|
+
passScreens = new Map();
|
|
511
|
+
passMemos = new Map();
|
|
512
|
+
try {
|
|
513
|
+
pass();
|
|
514
|
+
} finally {
|
|
515
|
+
passMeasurements = undefined;
|
|
516
|
+
passChildren = undefined;
|
|
517
|
+
passScreens = undefined;
|
|
518
|
+
passMemos = undefined;
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
/** What {@link passMemo} computed in the running pass, by key. */
|
|
523
|
+
let passMemos: Map<object, unknown> | undefined;
|
|
524
|
+
|
|
525
|
+
/**
|
|
526
|
+
* `compute()`, at most once per `key` in the running {@link measurePass}
|
|
527
|
+
* (many views under one `Animated` component read its nodes once a pass);
|
|
528
|
+
* every time outside a pass.
|
|
529
|
+
*/
|
|
530
|
+
export function passMemo<T>(key: object, compute: () => T): T {
|
|
531
|
+
if (passMemos?.has(key)) {
|
|
532
|
+
return passMemos.get(key) as T;
|
|
533
|
+
}
|
|
534
|
+
const value = compute();
|
|
535
|
+
passMemos?.set(key, value);
|
|
536
|
+
return value;
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
/**
|
|
540
|
+
* `host`'s window rectangle; `null` for an exact 0/0/0/0, which Fabric
|
|
541
|
+
* answers for a node or layout it cannot find; `undefined` unless it answers
|
|
542
|
+
* at once with finite numbers.
|
|
543
|
+
*/
|
|
544
|
+
function measureHost(host: HostAncestor, fiber: FiberLike): WindowRect | null | undefined {
|
|
545
|
+
return measureInstance((host.instance ??= publicInstanceOf(fiber)));
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
function measureInstance(instance: { measureInWindow: MeasureInWindow }): WindowRect | null | undefined {
|
|
549
|
+
if (passMeasurements?.has(instance)) {
|
|
550
|
+
return passMeasurements.get(instance);
|
|
551
|
+
}
|
|
552
|
+
let measured: WindowRect | null | undefined;
|
|
553
|
+
instance.measureInWindow((x, y, width, height) => {
|
|
554
|
+
const answer = { x, y, width, height };
|
|
555
|
+
if (finite(answer)) {
|
|
556
|
+
measured = x === 0 && y === 0 && width === 0 && height === 0 ? null : answer;
|
|
557
|
+
}
|
|
558
|
+
});
|
|
559
|
+
passMeasurements?.set(instance, measured);
|
|
560
|
+
return measured;
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
function finite({ x, y, width, height }: WindowRect): boolean {
|
|
564
|
+
return Number.isFinite(x) && Number.isFinite(y) && Number.isFinite(width) && Number.isFinite(height);
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
/**
|
|
568
|
+
* The part of `rect` inside every ancestor that clips now (as the last
|
|
569
|
+
* {@link isHidden} read them), or `null` when none of it is. Only the
|
|
570
|
+
* ancestors between `path` indices `above` and `below` cut it: a native-driven
|
|
571
|
+
* transform between two clippers moves what the lower one left, and the upper
|
|
572
|
+
* one cuts where it was moved to.
|
|
573
|
+
*
|
|
574
|
+
* Fails closed: `rect` itself, unclipped, when it is not finite, the last
|
|
575
|
+
* read was not complete, or any clipping ancestor throws, answers late or
|
|
576
|
+
* answers with a non-finite rectangle. An ancestor answering 0/0/0/0 clips
|
|
577
|
+
* nothing. Measures nothing, and returns `rect` as it is, when nothing
|
|
578
|
+
* clips.
|
|
579
|
+
*/
|
|
580
|
+
export function clipToAncestors(
|
|
581
|
+
rect: WindowRect,
|
|
582
|
+
ancestry: Ancestry,
|
|
583
|
+
above = -1,
|
|
584
|
+
below = Number.POSITIVE_INFINITY,
|
|
585
|
+
): WindowRect | null {
|
|
586
|
+
if (!finite(rect) || !ancestry.readable) {
|
|
587
|
+
return rect;
|
|
588
|
+
}
|
|
589
|
+
const clips: Array<WindowRect | null | undefined> = [];
|
|
590
|
+
try {
|
|
591
|
+
for (const host of ancestry.hosts) {
|
|
592
|
+
// `above` and `below` are Animated components' indices, never a host's.
|
|
593
|
+
// Stryker disable next-line EqualityOperator -- so `>=` and `<=` pick the same hosts
|
|
594
|
+
if (host.clips && host.index > above && host.index < below) {
|
|
595
|
+
clips.push(measureHost(host, ancestry.path[host.index] as FiberLike));
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
} catch {
|
|
599
|
+
return rect;
|
|
600
|
+
}
|
|
601
|
+
if (clips.includes(undefined)) {
|
|
602
|
+
return rect;
|
|
603
|
+
}
|
|
604
|
+
const known = clips.filter((clip): clip is WindowRect => clip !== null);
|
|
605
|
+
if (known.length === 0) {
|
|
606
|
+
return rect;
|
|
607
|
+
}
|
|
608
|
+
let left = rect.x;
|
|
609
|
+
let top = rect.y;
|
|
610
|
+
let right = rect.x + rect.width;
|
|
611
|
+
let bottom = rect.y + rect.height;
|
|
612
|
+
for (const clip of known) {
|
|
613
|
+
left = Math.max(left, clip.x);
|
|
614
|
+
top = Math.max(top, clip.y);
|
|
615
|
+
right = Math.min(right, clip.x + clip.width);
|
|
616
|
+
bottom = Math.min(bottom, clip.y + clip.height);
|
|
617
|
+
}
|
|
618
|
+
if (right <= left || bottom <= top) {
|
|
619
|
+
return null;
|
|
620
|
+
}
|
|
621
|
+
return { x: left, y: top, width: right - left, height: bottom - top };
|
|
622
|
+
}
|