From 7d4e3d94dde148b3805851fef691c04302c178ec Mon Sep 17 00:00:00 2001
From: Florent Maitre <florent.maitre@orange.com>
Date: Fri, 22 Sep 2023 15:07:48 +0200
Subject: [PATCH] [#634] Fix background color of components in dark mode

---
 .../java/com/orange/ods/app/ui/MainScreen.kt  |  1 -
 changelog.md                                  |  1 +
 .../component/textfield/OdsTextField.kt       | 91 +++++++++----------
 .../compose/component/utilities/Preview.kt    |  3 +-
 .../com/orange/ods/compose/theme/OdsTheme.kt  |  3 +-
 5 files changed, 48 insertions(+), 51 deletions(-)

diff --git a/app/src/main/java/com/orange/ods/app/ui/MainScreen.kt b/app/src/main/java/com/orange/ods/app/ui/MainScreen.kt
index c8ac64622..ebd43fead 100644
--- a/app/src/main/java/com/orange/ods/app/ui/MainScreen.kt
+++ b/app/src/main/java/com/orange/ods/app/ui/MainScreen.kt
@@ -117,7 +117,6 @@ fun MainScreen(themeConfigurations: Set<OdsThemeConfigurationContract>, mainView
 
             Scaffold(
                 modifier = modifier,
-                backgroundColor = OdsTheme.colors.background,
                 topBar = {
                     Surface(elevation = if (isSystemInDarkTheme()) 0.dp else AppBarDefaults.TopAppBarElevation) {
                         Column {
diff --git a/changelog.md b/changelog.md
index 7d0e85caa..69feede2c 100644
--- a/changelog.md
+++ b/changelog.md
@@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 
 - \[Lib\] Fix a bug where `OdsDropdownMenu` was not dismissed on user click ([#617](https://github.com/Orange-OpenSource/ods-android/issues/617))
 - \[Lib\] Fix disabled color of text and icon in `OdsDropdownMenu` ([#617](https://github.com/Orange-OpenSource/ods-android/issues/617))
+- \[Lib\] Fix background color of components in dark mode ([#634](https://github.com/Orange-OpenSource/ods-android/issues/634))
 
 ## [0.15.0](https://github.com/Orange-OpenSource/ods-android/compare/0.14.0...0.15.0) - 2023-09-12
 
diff --git a/lib/src/main/java/com/orange/ods/compose/component/textfield/OdsTextField.kt b/lib/src/main/java/com/orange/ods/compose/component/textfield/OdsTextField.kt
index ac24b015a..750afc82b 100644
--- a/lib/src/main/java/com/orange/ods/compose/component/textfield/OdsTextField.kt
+++ b/lib/src/main/java/com/orange/ods/compose/component/textfield/OdsTextField.kt
@@ -13,7 +13,6 @@ package com.orange.ods.compose.component.textfield
 import androidx.compose.foundation.layout.fillMaxWidth
 import androidx.compose.foundation.text.KeyboardActions
 import androidx.compose.foundation.text.KeyboardOptions
-import androidx.compose.material.Surface
 import androidx.compose.material.Text
 import androidx.compose.material.TextField
 import androidx.compose.material.Typography
@@ -204,52 +203,50 @@ fun OdsTextField(
 ) {
     val filledTextField = OdsTheme.componentsConfiguration.textFieldStyle == OdsComponentsConfiguration.ComponentStyle.Filled
 
-    Surface { // Nest text field in a Surface in order to have correct content text color in dark mode
-        if (filledTextField) {
-            OdsFilledTextField(
-                value = value,
-                onValueChange = onValueChange,
-                modifier = modifier,
-                enabled = enabled,
-                readOnly = readOnly,
-                label = label,
-                placeholder = placeholder,
-                leadingIcon = leadingIcon,
-                leadingIconContentDescription = leadingIconContentDescription,
-                onLeadingIconClick = onLeadingIconClick,
-                trailing = trailing,
-                isError = isError,
-                errorMessage = errorMessage,
-                visualTransformation = visualTransformation,
-                keyboardOptions = keyboardOptions,
-                keyboardActions = keyboardActions,
-                singleLine = singleLine,
-                maxLines = maxLines,
-                characterCounter = characterCounter
-            )
-        } else {
-            OdsOutlinedTextField(
-                value = value,
-                onValueChange = onValueChange,
-                modifier = modifier,
-                enabled = enabled,
-                readOnly = readOnly,
-                label = label,
-                placeholder = placeholder,
-                leadingIcon = leadingIcon,
-                leadingIconContentDescription = leadingIconContentDescription,
-                onLeadingIconClick = onLeadingIconClick,
-                trailing = trailing,
-                isError = isError,
-                errorMessage = errorMessage,
-                visualTransformation = visualTransformation,
-                keyboardOptions = keyboardOptions,
-                keyboardActions = keyboardActions,
-                singleLine = singleLine,
-                maxLines = maxLines,
-                characterCounter = characterCounter
-            )
-        }
+    if (filledTextField) {
+        OdsFilledTextField(
+            value = value,
+            onValueChange = onValueChange,
+            modifier = modifier,
+            enabled = enabled,
+            readOnly = readOnly,
+            label = label,
+            placeholder = placeholder,
+            leadingIcon = leadingIcon,
+            leadingIconContentDescription = leadingIconContentDescription,
+            onLeadingIconClick = onLeadingIconClick,
+            trailing = trailing,
+            isError = isError,
+            errorMessage = errorMessage,
+            visualTransformation = visualTransformation,
+            keyboardOptions = keyboardOptions,
+            keyboardActions = keyboardActions,
+            singleLine = singleLine,
+            maxLines = maxLines,
+            characterCounter = characterCounter
+        )
+    } else {
+        OdsOutlinedTextField(
+            value = value,
+            onValueChange = onValueChange,
+            modifier = modifier,
+            enabled = enabled,
+            readOnly = readOnly,
+            label = label,
+            placeholder = placeholder,
+            leadingIcon = leadingIcon,
+            leadingIconContentDescription = leadingIconContentDescription,
+            onLeadingIconClick = onLeadingIconClick,
+            trailing = trailing,
+            isError = isError,
+            errorMessage = errorMessage,
+            visualTransformation = visualTransformation,
+            keyboardOptions = keyboardOptions,
+            keyboardActions = keyboardActions,
+            singleLine = singleLine,
+            maxLines = maxLines,
+            characterCounter = characterCounter
+        )
     }
 }
 
diff --git a/lib/src/main/java/com/orange/ods/compose/component/utilities/Preview.kt b/lib/src/main/java/com/orange/ods/compose/component/utilities/Preview.kt
index 63c94650f..09e428838 100644
--- a/lib/src/main/java/com/orange/ods/compose/component/utilities/Preview.kt
+++ b/lib/src/main/java/com/orange/ods/compose/component/utilities/Preview.kt
@@ -11,7 +11,6 @@
 package com.orange.ods.compose.component.utilities
 
 import android.content.res.Configuration
-import androidx.compose.material.Surface
 import androidx.compose.runtime.Composable
 import androidx.compose.ui.tooling.preview.Preview
 import androidx.compose.ui.tooling.preview.PreviewParameterProvider
@@ -26,7 +25,7 @@ import kotlin.reflect.KClass
  */
 @Composable
 internal fun Preview(content: @Composable () -> Unit) = OdsTheme(BuildConfig.PREVIEW_THEME_CONFIGURATION) {
-    Surface(color = OdsTheme.colors.surface, content = content)
+    content()
 }
 
 /**
diff --git a/lib/src/main/java/com/orange/ods/compose/theme/OdsTheme.kt b/lib/src/main/java/com/orange/ods/compose/theme/OdsTheme.kt
index cfe3b2918..069cfb26d 100644
--- a/lib/src/main/java/com/orange/ods/compose/theme/OdsTheme.kt
+++ b/lib/src/main/java/com/orange/ods/compose/theme/OdsTheme.kt
@@ -13,6 +13,7 @@ package com.orange.ods.compose.theme
 import androidx.compose.foundation.isSystemInDarkTheme
 import androidx.compose.material.MaterialTheme
 import androidx.compose.material.Shapes
+import androidx.compose.material.Surface
 import androidx.compose.material.Typography
 import androidx.compose.material.ripple.LocalRippleTheme
 import androidx.compose.runtime.Composable
@@ -98,7 +99,7 @@ fun OdsTheme(
         MaterialTheme(
             colors = colors.materialColors
         ) {
-            content()
+            Surface(color = colors.background, content = content)
         }
     }
 }
\ No newline at end of file