From 0b0bf216558fd0f4d156c47d5458ac70c03f5423 Mon Sep 17 00:00:00 2001 From: songzhiling <17630035658@163.com> Date: Thu, 8 May 2025 13:25:15 +0800 Subject: [PATCH] =?UTF-8?q?refactor(servicing):=20=E9=87=8D=E6=9E=84?= =?UTF-8?q?=E5=A4=B4=E9=83=A8=E6=A0=B7=E5=BC=8F=E5=B9=B6=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E4=B8=BB=E9=A2=98=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit -将 headBgColor 从 val改为 var,以便于后续可能的动态修改 - 移除了 head.kt 中的 systemBarsPadding() 和多余的背景颜色设置 - 调整了 Theme.kt 中的窗口装饰和系统栏设置,优化了头部样式 --- .../src/main/java/com/za/base/theme/Color.kt | 2 +- .../src/main/java/com/za/base/theme/Theme.kt | 83 ++++++++++--------- .../src/main/java/com/za/base/view/head.kt | 52 ++++++------ 3 files changed, 71 insertions(+), 66 deletions(-) diff --git a/servicing/src/main/java/com/za/base/theme/Color.kt b/servicing/src/main/java/com/za/base/theme/Color.kt index bcab4cc..627a580 100644 --- a/servicing/src/main/java/com/za/base/theme/Color.kt +++ b/servicing/src/main/java/com/za/base/theme/Color.kt @@ -16,7 +16,7 @@ val MainBottomSelectColor = Color(0xFF3D4B7C) val MainBottomUnSelectColor = Color(0xFFA9AEBD) //标题颜色 -val headBgColor = Color(0xFF3D4B7C) +var headBgColor = Color(0xFF3D4B7C) //标题颜色 val headTitleColor = Color(0xB3FFFFFF) diff --git a/servicing/src/main/java/com/za/base/theme/Theme.kt b/servicing/src/main/java/com/za/base/theme/Theme.kt index 414466d..7833c28 100644 --- a/servicing/src/main/java/com/za/base/theme/Theme.kt +++ b/servicing/src/main/java/com/za/base/theme/Theme.kt @@ -20,50 +20,57 @@ import androidx.core.view.ViewCompat import androidx.core.view.WindowCompat import androidx.core.view.WindowInsetsCompat import androidx.core.view.updateLayoutParams +import androidx.core.view.updatePadding private val LightColorScheme = lightColorScheme( - primary = Purple40, - secondary = PurpleGrey40, - tertiary = Pink40, - background = bgColor, - onBackground = bgColor, + primary = Purple40, + secondary = PurpleGrey40, + tertiary = Pink40, + background = bgColor, + onBackground = bgColor, ) @OptIn(ExperimentalMaterial3Api::class) @Composable -fun DealerTheme( - darkTheme: Boolean = isSystemInDarkTheme(), - content: @Composable () -> Unit -) { - val colorScheme = when { - darkTheme -> LightColorScheme - else -> LightColorScheme - } - val view = LocalView.current - if (!view.isInEditMode) { - SideEffect { - val window = (view.context as Activity).window - window.statusBarColor = Color.Transparent.toArgb() - WindowCompat.getInsetsController(window, view).isAppearanceLightStatusBars = !darkTheme - WindowCompat.setDecorFitsSystemWindows(window, false) - ViewCompat.setOnApplyWindowInsetsListener(window.decorView.findViewById(android.R.id.content)) { view, windowInsets -> - val insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars()) - view as ViewGroup - view.updateLayoutParams { - leftMargin = insets.left - bottomMargin = insets.bottom - rightMargin = insets.right - topMargin = 0 - } - WindowInsetsCompat.CONSUMED - } - } - } - MaterialTheme(colorScheme = colorScheme) { - CompositionLocalProvider(LocalRippleConfiguration provides RippleConfiguration(rippleAlpha = RippleAlpha(0f, 0f, 0f, 0f))) { - ProvideTextStyle(value = MaterialTheme.typography.bodyLarge, content = content) - } - } +fun DealerTheme(darkTheme : Boolean = isSystemInDarkTheme(), content : @Composable () -> Unit) { + val colorScheme = when { + darkTheme -> LightColorScheme + else -> LightColorScheme + } + val view = LocalView.current + if (! view.isInEditMode) { + SideEffect { + val window = (view.context as Activity).window + window.statusBarColor = Color.Transparent.toArgb() + WindowCompat.getInsetsController(window, view).isAppearanceLightStatusBars = ! darkTheme + WindowCompat.setDecorFitsSystemWindows(window, false) + ViewCompat.setOnApplyWindowInsetsListener(window.decorView.findViewById(android.R.id.content)) { view, windowInsets -> + val insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars()) + view as ViewGroup + view.setBackgroundColor(headBgColor.toArgb()) + view.updateLayoutParams { + leftMargin = insets.left + bottomMargin = insets.bottom + rightMargin = insets.right + topMargin = 0 + } + view.updatePadding(top = insets.top, + bottom = insets.bottom, + left = view.paddingLeft, + right = view.paddingRight) + WindowInsetsCompat.CONSUMED + } + } + } + MaterialTheme(colorScheme = colorScheme) { + CompositionLocalProvider(LocalRippleConfiguration provides RippleConfiguration(rippleAlpha = RippleAlpha( + 0f, + 0f, + 0f, + 0f))) { + ProvideTextStyle(value = MaterialTheme.typography.bodyLarge, content = content) + } + } } //object NoRippleTheme : RippleTheme { diff --git a/servicing/src/main/java/com/za/base/view/head.kt b/servicing/src/main/java/com/za/base/view/head.kt index 937f2c7..41fd136 100644 --- a/servicing/src/main/java/com/za/base/view/head.kt +++ b/servicing/src/main/java/com/za/base/view/head.kt @@ -1,11 +1,9 @@ package com.za.base.view -import androidx.compose.foundation.background import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size -import androidx.compose.foundation.layout.systemBarsPadding import androidx.compose.material3.CenterAlignedTopAppBar import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.Text @@ -18,37 +16,37 @@ import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import coil.compose.AsyncImage import com.za.base.theme.headBgColor -import com.za.base.theme.headPadding import com.za.servicing.R @OptIn(ExperimentalMaterial3Api::class) @Composable -fun HeadView(title: String, onBack: () -> Unit = {}, isCanBack: Boolean = true, action: @Composable () -> Unit = {}) { - CenterAlignedTopAppBar(modifier = Modifier - .fillMaxWidth() - .background(color = headBgColor) - .systemBarsPadding() - .padding(top = 20.dp), - colors = TopAppBarDefaults.centerAlignedTopAppBarColors().copy(containerColor = headBgColor, titleContentColor = Color.White), - title = { Text(text = title, fontSize = 15.sp, fontWeight = FontWeight.Medium) }, - navigationIcon = { - if (isCanBack) { - AsyncImage(model = R.drawable.sv_back, contentDescription = "", modifier = Modifier - .size(40.dp) - .clickable { onBack() } - .padding(10.dp)) - } - }, actions = { action() }) +fun HeadView(title : String, + onBack : () -> Unit = {}, + isCanBack : Boolean = true, + action : @Composable () -> Unit = {}) { + CenterAlignedTopAppBar(modifier = Modifier.fillMaxWidth(), + colors = TopAppBarDefaults.centerAlignedTopAppBarColors() + .copy(containerColor = headBgColor, titleContentColor = Color.White), + title = { Text(text = title, fontSize = 15.sp, fontWeight = FontWeight.Medium) }, + navigationIcon = { + if (isCanBack) { + AsyncImage(model = R.drawable.sv_back, + contentDescription = "", + modifier = Modifier + .size(40.dp) + .clickable { onBack() } + .padding(10.dp)) + } + }, + actions = { action() }) } @OptIn(ExperimentalMaterial3Api::class) @Composable -fun HeadViewNotBack(title: String) { - CenterAlignedTopAppBar(modifier = Modifier - .fillMaxWidth() - .background(color = headBgColor) - .padding(top = headPadding), - colors = TopAppBarDefaults.centerAlignedTopAppBarColors().copy(containerColor = headBgColor, titleContentColor = Color.White), - title = { Text(text = title, fontSize = 15.sp, fontWeight = FontWeight.Medium) }, - navigationIcon = {}) +fun HeadViewNotBack(title : String) { + CenterAlignedTopAppBar(modifier = Modifier.fillMaxWidth(), + colors = TopAppBarDefaults.centerAlignedTopAppBarColors() + .copy(containerColor = headBgColor, titleContentColor = Color.White), + title = { Text(text = title, fontSize = 15.sp, fontWeight = FontWeight.Medium) }, + navigationIcon = {}) } \ No newline at end of file