Platform
Platform.os
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
Platform.ioswhen running on iOSPlatform.androidwhen running on Android.Platform.webwhen running on the web (viareact-native-web).
If you need an unsupported platform, you can use Platform.unsafe(string).
For conditional style depending on the platform, you can do the following:
open Style
let styles = StyleSheet.create({
"wrapper": s({width: (Platform.os == Platform.ios ? 100. : 200.)->pct}),
})
Platform.select
⚠️ Unsupported.
This feature isn't relevant with ReScript. Instead you can do the following:
open Style
let styles = StyleSheet.create({
"wrapper": s({
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,
}),
})
Also since spreading things in ReScript is not supported (because of the unsafety aspect), it's even less relevant to have this binding.