@bugsee/react-native 0.0.0-stage → 7.0.0-beta2
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 +557 -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 +962 -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,323 @@
|
|
|
1
|
+
import { errorName } from '../errorName';
|
|
2
|
+
import { measureFiber, measurePass } from './ancestry';
|
|
3
|
+
import { publishTogether } from './registry';
|
|
4
|
+
import type { FiberLike, WindowRect } from '../viewtree/fiber';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* How often every mounted `<BugseeSecure>` re-measures itself.
|
|
8
|
+
*
|
|
9
|
+
* `onLayout` does not fire when an ancestor scrolls, so a region measured only
|
|
10
|
+
* on layout stays where the view was while the view itself moves on screen and
|
|
11
|
+
* is recorded. 100 ms is well under the SDK's ~350 ms pull interval.
|
|
12
|
+
*/
|
|
13
|
+
export const SECURE_REMEASURE_MS = 100;
|
|
14
|
+
|
|
15
|
+
interface Registration {
|
|
16
|
+
readonly measure: () => void;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** A registration per call, so one function added twice is two measurers. */
|
|
20
|
+
const measurers = new Set<Registration>();
|
|
21
|
+
|
|
22
|
+
/** Stops the running interval; set exactly while one is running. */
|
|
23
|
+
let stopTimer: (() => void) | undefined;
|
|
24
|
+
|
|
25
|
+
function measureAll(): void {
|
|
26
|
+
// A snapshot: a measurer may add or remove one while the tick runs.
|
|
27
|
+
for (const { measure } of [...measurers]) {
|
|
28
|
+
// One broken measurer must not leave the rest stale for this tick.
|
|
29
|
+
try {
|
|
30
|
+
measure();
|
|
31
|
+
} catch (error) {
|
|
32
|
+
console.warn('[Bugsee] a secure-region measurer threw', errorName(error));
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Parked instances' checks (clipped and still): every tick runs every one. */
|
|
38
|
+
const parked = new Set<Registration>();
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Every parked instance's check, every tick. Each measures its view alone
|
|
42
|
+
* (no ancestors, nothing published while it has not moved), so a tick costs
|
|
43
|
+
* one measurement per parked instance, as a tick-mode instance's does; no
|
|
44
|
+
* frame costs any.
|
|
45
|
+
*/
|
|
46
|
+
function checkParked(): void {
|
|
47
|
+
// A snapshot: a check may park or unpark one while the tick runs.
|
|
48
|
+
for (const { measure } of [...parked]) {
|
|
49
|
+
try {
|
|
50
|
+
measure();
|
|
51
|
+
} catch (error) {
|
|
52
|
+
console.warn('[Bugsee] a secure-region measurer threw', errorName(error));
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** One pass: a ScrollView shared by many measurers is measured once. */
|
|
58
|
+
function tick(): void {
|
|
59
|
+
measurePass(() =>
|
|
60
|
+
publishTogether(() => {
|
|
61
|
+
measureAll();
|
|
62
|
+
checkParked();
|
|
63
|
+
// A lane that failed is retried here, once a tick, not every frame.
|
|
64
|
+
}, true),
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Adds `check` to the parked instances every tick re-checks, until the
|
|
70
|
+
* returned function is called. Only while some measurer keeps the tick
|
|
71
|
+
* running.
|
|
72
|
+
*/
|
|
73
|
+
export function addParked(check: () => void): () => void {
|
|
74
|
+
const registration: Registration = { measure: check };
|
|
75
|
+
parked.add(registration);
|
|
76
|
+
return () => {
|
|
77
|
+
parked.delete(registration);
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Calls `measure` every `SECURE_REMEASURE_MS` until the returned function is
|
|
83
|
+
* called. One interval serves every measurer, and it runs only while there is
|
|
84
|
+
* at least one.
|
|
85
|
+
*/
|
|
86
|
+
export function addMeasurer(measure: () => void): () => void {
|
|
87
|
+
const registration: Registration = { measure };
|
|
88
|
+
measurers.add(registration);
|
|
89
|
+
if (stopTimer === undefined) {
|
|
90
|
+
const timer = setInterval(tick, SECURE_REMEASURE_MS);
|
|
91
|
+
stopTimer = () => clearInterval(timer);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return () => {
|
|
95
|
+
measurers.delete(registration);
|
|
96
|
+
if (measurers.size === 0) {
|
|
97
|
+
stopTimer?.();
|
|
98
|
+
stopTimer = undefined;
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** A frame, for the fallback where there is no `requestAnimationFrame`. */
|
|
104
|
+
export const FRAME_MS = 16;
|
|
105
|
+
|
|
106
|
+
/** Instances that re-measure every frame: withdrawn as hidden, or clipped. */
|
|
107
|
+
const frameMeasurers = new Set<Registration>();
|
|
108
|
+
|
|
109
|
+
/** Cancels the pending frame; set exactly while one is pending. */
|
|
110
|
+
let cancelFrame: (() => void) | undefined;
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Runs `callback` before the next frame, returning what cancels it. Looked
|
|
114
|
+
* up per call, so it follows whatever the runtime provides at the time.
|
|
115
|
+
*/
|
|
116
|
+
function requestFrame(callback: () => void): () => void {
|
|
117
|
+
const { requestAnimationFrame: request, cancelAnimationFrame: cancel } = globalThis as {
|
|
118
|
+
requestAnimationFrame?: (callback: () => void) => number;
|
|
119
|
+
cancelAnimationFrame?: (handle: number) => void;
|
|
120
|
+
};
|
|
121
|
+
if (request === undefined || cancel === undefined) {
|
|
122
|
+
const timer = setTimeout(callback, FRAME_MS);
|
|
123
|
+
return () => clearTimeout(timer);
|
|
124
|
+
}
|
|
125
|
+
const handle = request(callback);
|
|
126
|
+
return () => cancel(handle);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
interface WatchedNode {
|
|
130
|
+
/** What moved callbacks to call; a callback per subscription. */
|
|
131
|
+
readonly subscribers: Set<{ readonly moved: () => void }>;
|
|
132
|
+
/** Whether any subscriber wants its geometry; one watching its props alone does not measure it. */
|
|
133
|
+
geometry: boolean;
|
|
134
|
+
/** Where the node was at the last frame (or when first watched); unmeasured, always the same. */
|
|
135
|
+
last: string;
|
|
136
|
+
/** Its two fibers' props objects then: a commit that changes either may change how it clips. */
|
|
137
|
+
props: readonly unknown[];
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/** Nodes measured every frame (a ScrollView's content, a clipping view), by fiber. */
|
|
141
|
+
const watched = new Map<FiberLike, WatchedNode>();
|
|
142
|
+
|
|
143
|
+
function where(rect: WindowRect | null | undefined): string {
|
|
144
|
+
return rect == null ? String(rect) : `${rect.x},${rect.y},${rect.width},${rect.height}`;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function whereNow(fiber: FiberLike): string {
|
|
148
|
+
try {
|
|
149
|
+
return where(measureFiber(fiber));
|
|
150
|
+
} catch {
|
|
151
|
+
// Unknown, as a node that does not answer is.
|
|
152
|
+
return where(undefined);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* The props objects of both fibers of `fiber`'s pair. Whichever is
|
|
158
|
+
* committed, a commit that changes its props replaces one of them, so
|
|
159
|
+
* comparing both by identity catches every such commit (and, harmlessly,
|
|
160
|
+
* renders that never commit).
|
|
161
|
+
*/
|
|
162
|
+
function propsOf(fiber: FiberLike): unknown[] {
|
|
163
|
+
return [fiber.memoizedProps, fiber.alternate?.memoizedProps];
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Measures every watched node once, and wakes the subscribers of each that
|
|
168
|
+
* moved or whose props changed (an `overflow` that stops clipping moves
|
|
169
|
+
* nothing).
|
|
170
|
+
*/
|
|
171
|
+
function watchNodes(): void {
|
|
172
|
+
for (const [fiber, node] of [...watched]) {
|
|
173
|
+
const now = node.geometry ? whereNow(fiber) : node.last;
|
|
174
|
+
const props = propsOf(fiber);
|
|
175
|
+
const changed = now !== node.last || props.some((value, index) => value !== node.props[index]);
|
|
176
|
+
node.last = now;
|
|
177
|
+
node.props = props;
|
|
178
|
+
if (changed) {
|
|
179
|
+
for (const { moved } of [...node.subscribers]) {
|
|
180
|
+
moved();
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/** Watched nodes, then every frame measurer, in one measure pass; then the next frame if any are left. */
|
|
187
|
+
function frame(): void {
|
|
188
|
+
cancelFrame = undefined;
|
|
189
|
+
try {
|
|
190
|
+
measurePass(() =>
|
|
191
|
+
publishTogether(() => {
|
|
192
|
+
watchNodes();
|
|
193
|
+
watchValues();
|
|
194
|
+
for (const { measure } of [...frameMeasurers]) {
|
|
195
|
+
try {
|
|
196
|
+
measure();
|
|
197
|
+
} catch (error) {
|
|
198
|
+
console.warn('[Bugsee] a secure-region measurer threw', errorName(error));
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}),
|
|
202
|
+
);
|
|
203
|
+
} finally {
|
|
204
|
+
// In a finally: nothing thrown above (a warn included) may stop the loop.
|
|
205
|
+
if (frameMeasurers.size > 0 || watched.size > 0 || watchedValues.size > 0) {
|
|
206
|
+
cancelFrame ??= requestFrame(frame);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Measures `fiber` every frame, and calls `moved` whenever it is somewhere
|
|
213
|
+
* else than the frame before, or its props changed, until the returned
|
|
214
|
+
* function is called. Every subscriber of one fiber shares one measurement a
|
|
215
|
+
* frame, and so does every fiber of one host. With `geometry` false the
|
|
216
|
+
* subscriber wants its props alone (a `<Modal>` host hidden by a commit), and
|
|
217
|
+
* the node is measured only if another subscriber wants that.
|
|
218
|
+
*/
|
|
219
|
+
export function watchNode(fiber: FiberLike, moved: () => void, geometry = true): () => void {
|
|
220
|
+
let node = watched.get(fiber);
|
|
221
|
+
if (node === undefined) {
|
|
222
|
+
// Measured at once: a move before the next frame is a move. Unmeasured, `last` never changes.
|
|
223
|
+
// Stryker disable next-line StringLiteral -- so any constant is as good
|
|
224
|
+
node = { subscribers: new Set(), geometry, last: geometry ? whereNow(fiber) : '', props: propsOf(fiber) };
|
|
225
|
+
watched.set(fiber, node);
|
|
226
|
+
} else if (geometry && !node.geometry) {
|
|
227
|
+
node.geometry = true;
|
|
228
|
+
node.last = whereNow(fiber);
|
|
229
|
+
}
|
|
230
|
+
const subscription = { moved };
|
|
231
|
+
node.subscribers.add(subscription);
|
|
232
|
+
cancelFrame ??= requestFrame(frame);
|
|
233
|
+
const target = node;
|
|
234
|
+
return () => {
|
|
235
|
+
target.subscribers.delete(subscription);
|
|
236
|
+
if (target.subscribers.size === 0 && watched.get(fiber) === target) {
|
|
237
|
+
watched.delete(fiber);
|
|
238
|
+
}
|
|
239
|
+
stopFramesIfIdle();
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
interface WatchedValue {
|
|
244
|
+
readonly subscribers: Set<{ readonly changed: () => void }>;
|
|
245
|
+
/** The node's running animation and value at the last frame. */
|
|
246
|
+
state: readonly unknown[];
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/** `Animated` values watched for an animation starting, or becoming native, by node. */
|
|
250
|
+
const watchedValues = new Map<object, WatchedValue>();
|
|
251
|
+
|
|
252
|
+
function stateOf(node: object): unknown[] {
|
|
253
|
+
const {
|
|
254
|
+
_animation: animation,
|
|
255
|
+
_value: value,
|
|
256
|
+
__isNative: native,
|
|
257
|
+
} = node as { _animation?: unknown; _value?: unknown; __isNative?: unknown };
|
|
258
|
+
// Made native by its first animation with the native driver, which commits nothing.
|
|
259
|
+
return [animation, value, native];
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/** Wakes the subscribers of every watched value whose animation or value changed. */
|
|
263
|
+
function watchValues(): void {
|
|
264
|
+
for (const [node, entry] of [...watchedValues]) {
|
|
265
|
+
const state = stateOf(node);
|
|
266
|
+
const changed = state.some((part, index) => part !== entry.state[index]);
|
|
267
|
+
entry.state = state;
|
|
268
|
+
if (changed) {
|
|
269
|
+
for (const { changed: wake } of [...entry.subscribers]) {
|
|
270
|
+
wake();
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* Reads `node` (an `Animated.Value`) every frame, and calls `changed`
|
|
278
|
+
* whenever an animation starts or ends on it, it is made native, or its value moves, until the
|
|
279
|
+
* returned function is called: a view under a still native transform needs no
|
|
280
|
+
* measuring until then. A few property reads a frame for every subscriber.
|
|
281
|
+
*/
|
|
282
|
+
export function watchValue(node: object, changed: () => void): () => void {
|
|
283
|
+
let entry = watchedValues.get(node);
|
|
284
|
+
if (entry === undefined) {
|
|
285
|
+
entry = { subscribers: new Set(), state: stateOf(node) };
|
|
286
|
+
watchedValues.set(node, entry);
|
|
287
|
+
}
|
|
288
|
+
const subscription = { changed };
|
|
289
|
+
entry.subscribers.add(subscription);
|
|
290
|
+
cancelFrame ??= requestFrame(frame);
|
|
291
|
+
const target = entry;
|
|
292
|
+
return () => {
|
|
293
|
+
target.subscribers.delete(subscription);
|
|
294
|
+
if (target.subscribers.size === 0 && watchedValues.get(node) === target) {
|
|
295
|
+
watchedValues.delete(node);
|
|
296
|
+
}
|
|
297
|
+
stopFramesIfIdle();
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
function stopFramesIfIdle(): void {
|
|
302
|
+
if (frameMeasurers.size === 0 && watched.size === 0 && watchedValues.size === 0) {
|
|
303
|
+
cancelFrame?.();
|
|
304
|
+
cancelFrame = undefined;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* Calls `measure` before every frame until the returned function is called.
|
|
310
|
+
* One frame callback serves every frame measurer, in one measure pass, so a
|
|
311
|
+
* ScrollView they share is measured once a frame, and it runs only while
|
|
312
|
+
* there is at least one.
|
|
313
|
+
*/
|
|
314
|
+
export function addFrameMeasurer(measure: () => void): () => void {
|
|
315
|
+
const registration: Registration = { measure };
|
|
316
|
+
frameMeasurers.add(registration);
|
|
317
|
+
cancelFrame ??= requestFrame(frame);
|
|
318
|
+
|
|
319
|
+
return () => {
|
|
320
|
+
frameMeasurers.delete(registration);
|
|
321
|
+
stopFramesIfIdle();
|
|
322
|
+
};
|
|
323
|
+
}
|