UNPKG

857 BPlain TextView Raw
1export function getReactNativeVersionWithModules(nativeModules: any): string | null {
2 try {
3 // dodge some bullets
4 if (!nativeModules.PlatformConstants) return null
5 if (!nativeModules.PlatformConstants.reactNativeVersion) return null
6
7 // grab the raw numbers
8 const major = nativeModules.PlatformConstants.reactNativeVersion.major
9 const minor = nativeModules.PlatformConstants.reactNativeVersion.minor
10 const patch = nativeModules.PlatformConstants.reactNativeVersion.patch
11 const prerelease = nativeModules.PlatformConstants.reactNativeVersion.prerelease
12
13 // check the major or jet
14 if (typeof major !== "number") return null
15
16 // assemble!
17 const vParts = []
18 vParts.push(`${major}.${minor}.${patch}`)
19 if (prerelease) vParts.push(`-${prerelease}`)
20 return vParts.join("")
21 } catch {}
22
23 return null
24}