-
Notifications
You must be signed in to change notification settings - Fork 945
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(reactotron-react-native): new arch support (#1508 by @frankcalise)
## Describe your PR - Closes #1486 - `NativeModules` aren't available in bridgeless, so we utilize the `TurboModuleRegistry` to dig up the same calls we were using (this is backwards compatible) - [ ] Maybe want to do better TSing over `eslint-disable` but I'll leave that up to @morganick's review 😅 > [!WARNING] > The `DevMenu` change is not Expo Go compatible. This will never work in Expo Go as documented in infinitered/ignite#2678. This would only impact the client devtools code, which they could remove the custom command from the Reactotron configuration (in this repo, it's just in the example app, hence the CNG change) ```bash ERROR Invariant Violation: TurboModuleRegistry.getEnforcing(...): 'DevMenu' could not be found. Verify that a module by this name is registered in the native binary.Bridgeless mode: false. TurboModule interop: false. Modules loaded: {"NativeModules":["PlatformConstants","LogBox","BlobModule","PlatformConstants","SourceCode","PlatformConstants","DeviceInfo"],"TurboModules":[],"NotFound":["DevMenu"]}, js engine: hermes ```
- Loading branch information
1 parent
1f05c7c
commit c114e09
Showing
7 changed files
with
115 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
lib/reactotron-react-native/src/helpers/getReactNativePlatformConstants.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { Platform, PlatformIOSStatic, PlatformAndroidStatic } from "react-native" | ||
|
||
interface PlatformConstants { | ||
osRelease: string | ||
model: string | ||
serverHost: string | ||
uiMode: string | ||
serial: string | ||
forceTouch: boolean | ||
interfaceIdiom: string | ||
systemName: string | ||
} | ||
|
||
export default function getReactNativePlatformConstants(): PlatformConstants { | ||
const defaults: PlatformConstants = { | ||
osRelease: "", | ||
model: "", | ||
serverHost: "", | ||
uiMode: "", | ||
serial: "", | ||
forceTouch: false, | ||
interfaceIdiom: "", | ||
systemName: "", | ||
} | ||
|
||
if (Platform.OS === "android") { | ||
const constants = Platform.constants as PlatformAndroidStatic["constants"] | ||
|
||
return { | ||
...defaults, | ||
osRelease: constants.Release, | ||
model: constants.Model, | ||
serverHost: constants.ServerHost, | ||
uiMode: constants.uiMode, | ||
serial: constants.Serial, | ||
} | ||
} else if (Platform.OS === "ios") { | ||
const constants = Platform.constants as PlatformIOSStatic["constants"] | ||
return { | ||
...defaults, | ||
forceTouch: constants.forceTouchAvailable || false, | ||
interfaceIdiom: constants.interfaceIdiom, | ||
systemName: constants.systemName, | ||
} | ||
} | ||
|
||
return defaults | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
lib/reactotron-react-native/src/helpers/getReactNativeVersion.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import { NativeModules } from "react-native" | ||
import { getReactNativeVersionWithModules } from "./getReactNativeVersionWithModules" | ||
import { Platform } from "react-native" | ||
|
||
export default function getReactNativeVersion(): string | null { | ||
return getReactNativeVersionWithModules(NativeModules) | ||
return getReactNativeVersionWithModules(Platform.constants) | ||
} |
14 changes: 7 additions & 7 deletions
14
lib/reactotron-react-native/src/helpers/getReactNativeVersionWithModules.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters