-
Notifications
You must be signed in to change notification settings - Fork 98
Expand file tree
/
Copy pathcore.ts
More file actions
79 lines (71 loc) · 2.44 KB
/
Copy pathcore.ts
File metadata and controls
79 lines (71 loc) · 2.44 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
72
73
74
75
76
77
78
79
import type { NativeSyntheticEvent } from "react-native";
import { NativeModules } from "react-native";
export type ReactNativeVersion = {
major: number;
minor: number;
patch: number;
prerelease?: string;
getVersionString: () => string;
};
export const ReactNativeVersion: ReactNativeVersion = (() => {
// https://github.com/facebook/react-native/commit/ec5638abd0e872be62b6ea5d8df9bed6335c2191
const { ReactNativeVersion } = require("react-native");
const { major, minor, patch, prerelease } =
ReactNativeVersion ??
require("react-native/Libraries/Core/ReactNativeVersion").version;
return {
major,
minor,
patch,
prerelease,
getVersionString: () => {
const v = `${major}.${minor}.${patch}`;
return prerelease ? `${v}-${prerelease.replace("-", "\n")}` : v;
},
};
})();
export function getHermesVersion(): string | undefined {
const version =
"HermesInternal" in global &&
HermesInternal &&
"getRuntimeProperties" in HermesInternal &&
typeof HermesInternal.getRuntimeProperties === "function" &&
HermesInternal.getRuntimeProperties()["OSS Release Version"];
if (!version) {
return undefined;
}
const [core, prerelease, ...build] = version.split("-");
const parts = [core];
if (prerelease) {
parts.push("-", prerelease);
if (build.length > 0) {
parts.push("\n", build.join("-"));
}
}
return `Hermes ${parts.join("")}`;
}
export function isBridgeless() {
return "RN$Bridgeless" in global && global.RN$Bridgeless === true;
}
export function isFabricInstance<T>(
ref: NativeSyntheticEvent<T>["currentTarget"]
): boolean {
return Boolean(
// @ts-expect-error — https://github.com/facebook/react-native/blob/0.76-stable/packages/react-native/Libraries/ReactNative/ReactFabricPublicInstance/ReactFabricPublicInstanceUtils.js
ref["__nativeTag"] ||
// @ts-expect-error — https://github.com/facebook/react-native/blob/0.76-stable/packages/react-native/Libraries/ReactNative/ReactFabricPublicInstance/ReactFabricPublicInstanceUtils.js
ref["_internalInstanceHandle"]?.stateNode?.canonical
);
}
export function isRemoteDebuggingAvailable(): boolean {
return (
!getHermesVersion() &&
!isBridgeless() &&
typeof NativeModules["DevSettings"]?.setIsDebuggingRemotely === "function"
);
}
export function setRemoteDebugging(value: boolean) {
if (isRemoteDebuggingAvailable()) {
NativeModules["DevSettings"].setIsDebuggingRemotely(value);
}
}