Instruction file imported from Thereallo1026/expo-native-storage (
.cursor/rules/native-platform-consistency.mdc). Copyright stays with the author.
globs: .swift,.kt,src/ExpoNativeStorageModule.web.ts description: Guidelines for maintaining consistency across native platform implementations
Native Platform Consistency
Ensure all platform implementations provide identical functionality and behavior.
iOS Implementation (src/ios/ExpoNativeStorage.swift)
- Storage Backend: Use
UserDefaults.standardfor persistence - Synchronization: Always call
synchronize()after write operations - Module Name: Must match "ExpoNativeStorage" across all platforms
- Function Signatures: Match exact parameter and return types
Android Implementation (src/android/ExpoNativeStorageModule.kt)
- Storage Backend: Use
SharedPreferenceswith name "ExpoNativeStorage" - Context: Access through
appContext.reactContext - Write Operations: Use
apply()for asynchronous commits - Module Name: Must match "ExpoNativeStorage" across all platforms
Web Implementation (src/ExpoNativeStorageModule.web.ts)
- Storage Backend: Use
localStoragewith feature detection - Fallback Behavior: Return appropriate defaults when localStorage unavailable
- Async Consistency: Maintain async signatures even though localStorage is synchronous
- Error Handling: Return false/null instead of throwing when storage unavailable
API Contract Requirements
All implementations must provide these exact function signatures:
setItem(key: string, value: string): Promise<boolean>getItem(key: string): Promise<string | null>removeItem(key: string): Promise<boolean>clear(): Promise<boolean>
Testing Considerations
- Cross-Platform: Test identical behavior on all supported platforms
- Error Cases: Verify graceful degradation when storage unavailable
- Data Persistence: Ensure data survives app restarts on native platforms