diff --git a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/MainActivity.kt b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/MainActivity.kt index 450f161f9..dbea3d245 100644 --- a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/MainActivity.kt +++ b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/MainActivity.kt @@ -1,5 +1,10 @@ package net.aliasvault.app +import android.content.res.Configuration +import android.os.Build import android.os.Bundle +import android.util.Log +import android.view.WindowInsetsController +import androidx.core.content.ContextCompat import com.facebook.react.ReactActivity import com.facebook.react.ReactActivityDelegate import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.fabricEnabled @@ -11,6 +16,10 @@ import expo.modules.splashscreen.SplashScreenManager * The main activity of the app. */ class MainActivity : ReactActivity() { + companion object { + private const val TAG = "MainActivity" + } + /** * Called when the activity is created. */ @@ -24,6 +33,77 @@ class MainActivity : ReactActivity() { // @generated end expo-splashscreen super.onCreate(null) + + // Configure system bars based on dark mode + configureSystemBars() + } + + override fun onResume() { + super.onResume() + // Reapply system bar configuration when app resumes + // This ensures our settings persist even if other code tries to override them + configureSystemBars() + } + + override fun onConfigurationChanged(newConfig: Configuration) { + super.onConfigurationChanged(newConfig) + // Reapply system bar configuration when theme changes + configureSystemBars() + } + + /** + * Configure system bars (status bar and navigation bar) colors and appearance + * based on current theme (light/dark mode) + */ + private fun configureSystemBars() { + val isDarkMode = (resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES + Log.d(TAG, "Configuring system bars - isDarkMode: $isDarkMode") + + window.apply { + if (isDarkMode) { + // Dark mode: black background with light icons + val bgColor = ContextCompat.getColor(context, R.color.av_background) + Log.d(TAG, "Setting dark mode colors - bgColor: ${String.format("#%06X", 0xFFFFFF and bgColor)}") + statusBarColor = bgColor + navigationBarColor = bgColor + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { + // Android 11+ (API 30+): Use WindowInsetsController + insetsController?.apply { + setSystemBarsAppearance( + 0, // Light icons/text + WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS or WindowInsetsController.APPEARANCE_LIGHT_NAVIGATION_BARS, + ) + } + } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + // Android 8-10 (API 26-29): Use deprecated flags + @Suppress("DEPRECATION") + decorView.systemUiVisibility = decorView.systemUiVisibility and + android.view.View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR.inv() and + android.view.View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR.inv() + } + } else { + // Light mode: light gray background with dark icons + statusBarColor = ContextCompat.getColor(context, R.color.av_background) + navigationBarColor = ContextCompat.getColor(context, R.color.av_background) + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { + // Android 11+ (API 30+): Use WindowInsetsController + insetsController?.apply { + setSystemBarsAppearance( + WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS or WindowInsetsController.APPEARANCE_LIGHT_NAVIGATION_BARS, + WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS or WindowInsetsController.APPEARANCE_LIGHT_NAVIGATION_BARS, + ) + } + } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + // Android 8-10 (API 26-29): Use deprecated flags + @Suppress("DEPRECATION") + decorView.systemUiVisibility = decorView.systemUiVisibility or + android.view.View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR or + android.view.View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR + } + } + } } /** diff --git a/apps/mobile-app/android/app/src/main/res/values-night/styles.xml b/apps/mobile-app/android/app/src/main/res/values-night/styles.xml index 6dcf2f04f..4b5e161dd 100644 --- a/apps/mobile-app/android/app/src/main/res/values-night/styles.xml +++ b/apps/mobile-app/android/app/src/main/res/values-night/styles.xml @@ -1,4 +1,16 @@ + + +