The Platform Module
ThePlatform module from React Native provides information about the current platform.
Platform.OS
Check which platform your code is running on:Platform.Version
Get the platform version:- iOS
- Android
Platform Implementation from Source
From the React Native source code:Platform.select()
Return different values based on platform:Platform.select() with Components
Real Example from React Native Source
FromLibraries/Components/Button.js:
Button.js (source)
Platform-Specific File Extensions
Create separate files for each platform:Example: Platform-Specific Components
Real Example from React Native
From the React Native source,ToastAndroid has platform-specific implementations:
Platform-Specific Props
Some components have platform-specific props:- iOS Only
- Android Only
Conditional Rendering
Platform-Specific APIs
Some APIs are platform-specific:iOS Only APIs
iOS Only APIs
Android Only APIs
Android Only APIs
Styling Differences
Shadows vs Elevation
Device-Specific Code
Check for iPad
Check for TV
Best Practices
Use Platform.select() for styles
Keeps your code clean and readable when differences are minor
Use .ios.js/.android.js for major differences
Better for completely different implementations
Test on both platforms
Always test platform-specific code on actual devices
Document platform differences
Comment why platform-specific code is needed
Common Patterns
Safe Area Handling
Navigation Bar Height
Next Steps
Networking
Learn about fetching data from APIs
Navigation
Navigate between screens in your app