Skip to content

Commit 1944fac

Browse files
committed
placeholder hack
1 parent ccd75d5 commit 1944fac

File tree

2 files changed

+44
-14
lines changed

2 files changed

+44
-14
lines changed
Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,42 @@
1-
import { registerDevtoolsHook } from './fiber';
2-
31
// __REACT_DEVTOOLS_GLOBAL_HOOK__ must exist before React is ever executed
42
// this is the case with the React Devtools extension, but without it, we need
53

6-
// sometimes in expo this comes back as undefined
7-
// registerDevtoolsHook({
8-
// onCommitFiberRoot() {
9-
// /**/
10-
// },
11-
// });
4+
let attemptCount = 0;
5+
const MAX_ATTEMPTS = 3;
6+
7+
// temporary hack since module is sometime uninitialized in expo
8+
// fix is probably to remove circular imports
9+
function ensureDevtoolsHook() {
10+
return new Promise((resolve) => {
11+
function attempt() {
12+
try {
13+
const { registerDevtoolsHook } = require('./fiber');
14+
if (registerDevtoolsHook) {
15+
registerDevtoolsHook({
16+
onCommitFiberRoot() {
17+
/**/
18+
},
19+
});
20+
resolve(true);
21+
} else if (attemptCount < MAX_ATTEMPTS) {
22+
attemptCount++;
23+
setTimeout(attempt, 50);
24+
} else {
25+
resolve(false);
26+
}
27+
} catch (e) {
28+
if (attemptCount < MAX_ATTEMPTS) {
29+
attemptCount++;
30+
setTimeout(attempt, 50);
31+
} else {
32+
resolve(false);
33+
}
34+
}
35+
}
36+
attempt();
37+
});
38+
}
39+
40+
if (typeof globalThis.__REACT_DEVTOOLS_GLOBAL_HOOK__ === 'undefined') {
41+
ensureDevtoolsHook();
42+
}

src/core/native/scan.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,11 @@ const dimensions = Dimensions.get('window');
148148
const isVisible = (x: number, y: number) => {
149149
return x >= 0 && x <= dimensions.width && y >= 0 && y <= dimensions.height;
150150
};
151+
const font = matchFont({
152+
fontFamily: Platform.select({ ios: 'Courier', default: 'monospace' }),
153+
fontSize: 11,
154+
fontWeight: 'bold',
155+
});
151156
const getTextWidth = (text: string) => {
152157
return (text || 'unknown').length * 7;
153158
};
@@ -169,12 +174,6 @@ const ReactNativeScan = ({ id: _ }: { id: string }) => {
169174
// );
170175
const animatedOpacity = useDerivedValue(() => opacity.value);
171176

172-
const font = matchFont({
173-
fontFamily: Platform.select({ ios: 'Courier', default: 'monospace' }),
174-
fontSize: 11,
175-
fontWeight: 'bold',
176-
});
177-
178177
return (
179178
<Canvas
180179
style={{

0 commit comments

Comments
 (0)