Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: platform constants is undefined on web #4257

Conversation

mnahkies
Copy link
Contributor

@mnahkies mnahkies commented Jan 6, 2024

Motivation

in #4246 a check based on react native version was introduced, however the Platform.constants property is undefined when targetting web using the react-native-web approach listed in the docs, as the platform object is simply:

{"OS":"web","isTesting":false}

adjust it to check if the OS is web and use the native driver as before if so.

whilst I'm not totally sure whether using the "native driver" is the best option on web, until #4246 this was the case, so seemed the best option to revert to.

Interim Workaround

In the meantime, rather than monkey patching react-native-paper I'm working around by monkey patching the constants like so:

// TODO: workaround for react-native-paper issue
//       https://github.com/callstack/react-native-paper/pull/4257
if (!Platform.constants) {
  Platform.constants = {
    isTesting: Platform.isTesting,
    reactNativeVersion: {major: 0, minor: 73, patch: 0},
  }
}

I'm using expo-router so have placed this in my general app initialization effect in the root layout.

Test plan

Before this change, I encounter this error:
Screenshot from 2024-01-06 23-27-54

Afterwards the error is gone, and the buttons look correct to my eyes.

in callstack#4246 a check based on react native version was introduced,
however the `Platform.constants` property is `undefined` when
targetting web using the `react-native-web` approach listed in
the docs, as the platform object is simply:
```
{"OS":"web","isTesting":false}
```

adjust it to check if the `OS` is `web` and use the native
driver as before if so.
@callstack-bot
Copy link

Hey @mnahkies, thank you for your pull request 🤗. The documentation from this branch can be viewed here.

@lukewalczak lukewalczak added the web label Jan 8, 2024
@lukewalczak lukewalczak merged commit 46bd31b into callstack:main Jan 8, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants