Skip to main content
React Native makes it easy to write code that works on both iOS and Android, but sometimes you need platform-specific logic. This guide covers the various ways to handle platform differences.

The Platform Module

The Platform 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:

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

From Libraries/Components/Button.js:
Button.js (source)

Platform-Specific File Extensions

Create separate files for each platform:
1

Create platform-specific files

2

Import without extension

React Native automatically picks the right file based on 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:

Conditional Rendering

Platform-Specific APIs

Some APIs are platform-specific:

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

Next Steps

Networking

Learn about fetching data from APIs

Navigation

Navigate between screens in your app