android-patterns
Android Platform Patterns
Core Principles
Use PlatformIs.android() for readable platform detection. The utility function is more readable than Platform.OS === 'android' and provides type safety with consistent API across the codebase.
Always handle hardware back button on Android. Android devices have a physical or virtual back button that requires explicit handling. Use BackHandler API to control back button behavior and prevent unwanted app exits.
Always clean up BackHandler listeners. BackHandler subscriptions must be removed in useEffect cleanup to prevent memory leaks and unexpected behavior when components unmount.
Use Zest shadow tokens for cross-platform shadows. Zest automatically applies Android elevation from shadow tokens, eliminating manual elevation management while ensuring consistent visual design across platforms.
Why: Android has unique platform requirements including hardware back button handling, status bar color control, material design elevation, and specific UX patterns. Following these standards ensures native Android user experience while maintaining cross-platform code quality.
When to Use This Skill
Use these patterns when: