-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathTestComponentOverlay.tsx
More file actions
71 lines (62 loc) · 1.95 KB
/
TestComponentOverlay.tsx
File metadata and controls
71 lines (62 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import React, { useEffect } from 'react';
import { View, StyleSheet } from 'react-native';
import { useRenderedElement } from '../ui/state.js';
import { store } from '../ui/state.js';
import { ErrorBoundary } from './ErrorBoundary.js';
/**
* Waits for the native view hierarchy to be fully updated.
* Uses double requestAnimationFrame to ensure native has processed
* all view creation commands after React's commit phase.
*/
const waitForNativeViewHierarchy = (): Promise<void> => {
return new Promise((resolve) => {
requestAnimationFrame(() => {
requestAnimationFrame(() => {
resolve();
});
});
});
};
export const TestComponentOverlay = (): React.ReactElement | null => {
const { element, key } = useRenderedElement();
useEffect(() => {
// Call onRenderCallback when element changes
const callback = store.getState().onRenderCallback;
if (callback) {
// Wait for native view hierarchy to be fully updated before calling callback.
// useEffect fires after React commits, but native processes commands async.
// Double rAF ensures native has finished processing all view creation.
waitForNativeViewHierarchy().then(() => {
callback();
store.getState().setOnRenderCallback(null);
});
}
}, [element]);
if (!element) {
return null;
}
const handleLayout = (): void => {
const callback = store.getState().onLayoutCallback;
if (callback) {
callback();
// Clear the callback after calling it
store.getState().setOnLayoutCallback(null);
}
};
return (
<View
key={key}
// Keep runtime buildable on RN 0.85+ so this branch stays focused on the Metro loading repro.
style={[StyleSheet.absoluteFill, styles.overlay]}
onLayout={handleLayout}
>
<ErrorBoundary>{element}</ErrorBoundary>
</View>
);
};
const styles = StyleSheet.create({
overlay: {
backgroundColor: '#0a1628',
zIndex: 1000,
},
});