| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [View Raw Code] [Original HTTPS Page] |
| id | platform |
|---|---|
| title | Platform |
| officialDoc | https://reactnative.dev/docs/platform-specific-code |
React Native provides a module that detects the platform in which the app is running. You can use the detection logic to implement platform-specific code. Use this option when only small parts of a component are platform-specific.
if Platform.os === Platform.ios {
// your code
}Platform.os can be
If you need an unsupported platform, you can use Platform.unsafe(string).
For conditional style depending on the platform, you can do the following:
let styles = StyleSheet.create({
open Style
{
"wrapper": style(~width=pct(Platform.os == Platform.ios ? 100. : 200.), ()),
}
})⚠️ Unsupported.
This feature isn't relevant with ReScript. Instead you can do the following:
open Style
let styles = {
"wrapper": style(
~width=switch Platform.os {
| os if os == Platform.ios => 100.
| os if os == Platform.android => 200.
| os if os == Platform.web => 250.
| os if os == Platform.unsafe("windows") => 300.
| _ => 150.
}->pct,
(),
),
}->StyleSheet.createAlso since spreading things in ReScript is not supported (because of the unsafety aspect), it's even less relevant to have this binding.
| Back | FazBrowse Home | New Git URL |