smronju / nativephp-appearance
Force the app into light or dark mode independent of the system setting, or release it back to following the system automatically.
Package info
github.com/smronju/nativephp-appearance
Type:nativephp-plugin
pkg:composer/smronju/nativephp-appearance
Requires
- php: ^8.2
- nativephp/mobile: ^3.0|^4.0
Requires (Dev)
- pestphp/pest: ^3.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Forces a NativePHP Mobile app into light or dark mode independent of the OS setting, or releases it back to following the system automatically.
bg-theme-*/text-theme-* classes already resolve their dark companion
natively based on the OS color scheme — there is no PHP-facing API to override
that, only to read it (Native\Mobile\Facades\System::appearance()). This
plugin adds the missing write side.
Requirements
nativephp/mobile^3.0 or ^4.0- iOS 15.0+ — fully supported via
UIWindow.overrideUserInterfaceStyle. - Android — requires API 31+ (
UiModeManager.setApplicationNightMode, the only per-app override Android exposes outside ofAppCompatActivity). Below API 31,setMode()silently no-ops rather than partially applying.
Installation
composer require smronju/nativephp-appearance php artisan vendor:publish --tag=nativephp-plugins-provider php artisan native:plugin:register smronju/nativephp-appearance
Then rebuild: php artisan native:run.
Usage
use Smronju\NativephpAppearance\Facades\NativephpAppearance; NativephpAppearance::setMode('dark'); // force dark NativephpAppearance::setMode('light'); // force light NativephpAppearance::setMode('system'); // follow the OS again
Fire-and-forget: there's no event to listen for, and no result to branch on — either the override applies (iOS always; Android on API 31+) or the call is a safe no-op (Android below API 31).
License
MIT