Skip to content

feat: add setUserInterfaceStyle API with local persistence#16

Merged
huhuanming merged 11 commits intomainfrom
feat/set-user-interface-style
Feb 4, 2026
Merged

feat: add setUserInterfaceStyle API with local persistence#16
huhuanming merged 11 commits intomainfrom
feat/set-user-interface-style

Conversation

@huhuanming
Copy link
Contributor

Summary

  • Add setUserInterfaceStyle(style: string) API to react-native-device-utils supporting light, dark, and unspecified (system default)
  • Persist user preference locally (iOS: UserDefaults, Android: SharedPreferences) and restore on app launch
  • Add test buttons (Light / Dark / System) to the example app
  • Bump all native module versions from 1.1.16 to 1.1.17

Test plan

  • Verify light/dark/system style switches correctly on iOS
  • Verify light/dark/system style switches correctly on Android
  • Verify persisted style is restored after app restart on both platforms
  • Verify example app test buttons work as expected

🤖 Generated with Claude Code

huhuanming and others added 11 commits February 3, 2026 16:22
Add setUserInterfaceStyle(style) to react-native-device-utils for
forcing light/dark/system theme. The style is persisted locally
(UserDefaults on iOS, SharedPreferences on Android) and automatically
restored on module initialization.

Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Narrow style parameter type to 'light' | 'dark' | 'unspecified' union,
fix iOS style application by deferring to next runloop and using modern
connectedScenes API on iOS 15+, and fix Android by running night mode
changes on UI thread and migrating to androidx.preference.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- iOS: remove redundant double DispatchQueue.main.async in
  restoreUserInterfaceStyle since applyUserInterfaceStyle already
  dispatches to main thread
- Android: use Handler(Looper.getMainLooper()) to guarantee main
  thread execution regardless of Activity availability
- Test page: fix spanning listener memory leak by saving listener ID
  and cleaning up on unmount via useEffect

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…otocol conformance

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@huhuanming huhuanming merged commit 728a56a into main Feb 4, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants