Skip to main content

Beginner-Friendly Topic

Take your time - it's perfectly normal to re-read this topic 2-3 times. Try the interactive code editor below to run code yourself. Use the Q&A section to check your understanding before moving on.You've got this!

Lesson 8 of 10

Platform API - iOS & Android Differences

iOS and Android follow very different design languages and hardware conventions. React Native's Platform API and the `.ios.tsx` / `.android.tsx` file extension system let you write platform-appropriate code cleanly.

20 minBy Priygop Editorial TeamUpdated 2026Peer Reviewed & Verified

Platform Detection Patterns

Platform Detection Patterns
import { Platform, StyleSheet } from 'react-native';

// ---- Platform.OS ----
const isIOS = Platform.OS === 'ios';
const isAndroid = Platform.OS === 'android';

// ---- Platform.select - return different values per platform ----
const styles = StyleSheet.create({
  header: {
    ...Platform.select({
      ios: {
        shadowColor: '#000',
        shadowOffset: { width: 0, height: 1 },
        shadowOpacity: 0.15,
        shadowRadius: 4,
      },
      android: {
        elevation: 4,
      },
    }),
    backgroundColor: '#fff',
    height: Platform.select({ ios: 44, android: 56 }),
  },
  font: {
    fontFamily: Platform.select({
      ios: 'SF Pro Display',
      android: 'Roboto',
      default: 'System',
    }),
  },
});

// ---- Platform.Version ----
if (Platform.OS === 'android' && Platform.Version < 29) {
  // Android 9 (API 28) or below - some APIs behave differently
}

// ---- Status bar height (varies by device) ----
import { StatusBar } from 'react-native';
const STATUS_BAR_HEIGHT = Platform.OS === 'android'
  ? StatusBar.currentHeight ?? 24
  : 44; // approximate for most iPhones

Platform-Specific Files

Platform-Specific Files
// Metro automatically picks the right file based on platform:
// Button.ios.tsx   ← loaded on iOS
// Button.android.tsx ← loaded on Android
// Button.tsx       ← fallback (loaded if no platform-specific version exists)

// Button.ios.tsx
import { TouchableOpacity, Text } from 'react-native';
export function Button({ title, onPress }: ButtonProps) {
  // iOS-native look with SF font and rounded corners
  return (
    <TouchableOpacity
      style={{ backgroundColor: '#007AFF', paddingVertical: 14, borderRadius: 10 }}
      onPress={onPress}
      activeOpacity={0.8}
    >
      <Text style={{ color: 'white', fontSize: 17, fontWeight: '600', textAlign: 'center' }}>{title}</Text>
    </TouchableOpacity>
  );
}

// Button.android.tsx
import { Pressable, Text } from 'react-native';
export function Button({ title, onPress }: ButtonProps) {
  // Android Material Design with ripple
  return (
    <Pressable
      style={{ backgroundColor: '#6200EE', paddingVertical: 12, borderRadius: 4 }}
      onPress={onPress}
      android_ripple={{ color: '#ffffff33' }}
    >
      <Text style={{ color: 'white', fontSize: 16, fontWeight: '500', textAlign: 'center', letterSpacing: 0.5 }}>{title}</Text>
    </Pressable>
  );
}

Tip

Tip

Practice Platform API iOS Android Differences in small, isolated examples before integrating into larger projects. Breaking concepts into small experiments builds genuine understanding faster than reading alone.

Diagram
Loading diagram…

Platform.OS, Platform.select, and platform file extensions (.ios.tsx / .android.tsx)

Practice Task

Note

Practice Task - (1) Write a working example of Platform API iOS Android Differences from scratch without looking at notes. (2) Modify it to handle an edge case (empty input, null value, or error state). (3) Share your solution in the Priygop community for feedback.

Quick Quiz

Common Mistake

Warning

A common mistake with Platform API iOS Android Differences is skipping edge case testing - empty inputs, null values, and unexpected data types. Always validate boundary conditions to write robust, production-ready react native code.

Topics in This Module

0/10 done