reactotron-react-native
Version:
A development tool to explore, inspect, and diagnose your React Native apps.
25 lines (20 loc) • 857 B
text/typescript
export function getReactNativeVersionWithModules(nativeModules: any): string | null {
try {
// dodge some bullets
if (!nativeModules.PlatformConstants) return null
if (!nativeModules.PlatformConstants.reactNativeVersion) return null
// grab the raw numbers
const major = nativeModules.PlatformConstants.reactNativeVersion.major
const minor = nativeModules.PlatformConstants.reactNativeVersion.minor
const patch = nativeModules.PlatformConstants.reactNativeVersion.patch
const prerelease = nativeModules.PlatformConstants.reactNativeVersion.prerelease
// check the major or jet
if (typeof major !== "number") return null
// assemble!
const vParts = []
vParts.push(`${major}.${minor}.${patch}`)
if (prerelease) vParts.push(`-${prerelease}`)
return vParts.join("")
} catch {}
return null
}