Skip to content

Commit 96b4558

Browse files
committed
style(theme): 优化样式
1 parent ee76fbc commit 96b4558

File tree

5 files changed

+65
-45
lines changed

5 files changed

+65
-45
lines changed

app/src/main/java/com/jyn/composecalculator/ui/TopResultView.kt

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.jyn.composecalculator.ui
22

33
import androidx.activity.OnBackPressedCallback
44
import androidx.activity.compose.LocalOnBackPressedDispatcherOwner
5+
import androidx.compose.foundation.background
56
import androidx.compose.foundation.clickable
67
import androidx.compose.foundation.gestures.Orientation
78
import androidx.compose.foundation.interaction.MutableInteractionSource
@@ -13,11 +14,9 @@ import androidx.compose.material.*
1314
import androidx.compose.material.SwipeableDefaults.resistanceConfig
1415
import androidx.compose.material.TabRowDefaults.Divider
1516
import androidx.compose.material3.Surface
16-
import androidx.compose.runtime.Composable
17-
import androidx.compose.runtime.DisposableEffect
18-
import androidx.compose.runtime.remember
19-
import androidx.compose.runtime.rememberCoroutineScope
17+
import androidx.compose.runtime.*
2018
import androidx.compose.ui.Modifier
19+
import androidx.compose.ui.draw.shadow
2120
import androidx.compose.ui.platform.LocalConfiguration
2221
import androidx.compose.ui.platform.LocalDensity
2322
import androidx.compose.ui.tooling.preview.Preview
@@ -28,6 +27,7 @@ import com.apkfuns.logutils.LogUtils
2827
import com.jyn.composecalculator.BOTTOM_FRACTION
2928
import com.jyn.composecalculator.DateViewModel
3029
import com.jyn.composecalculator.isPortrait
30+
import com.jyn.composecalculator.ui.theme.evaluator
3131
import com.jyn.composecalculator.ui.theme.myTheme
3232
import com.jyn.composecalculator.ui.view.InputText
3333
import com.jyn.composecalculator.ui.view.ItemText
@@ -63,7 +63,7 @@ fun TopResultView() {
6363

6464
val coroutineScope = rememberCoroutineScope()
6565

66-
val process = state.offset.value / blockSizePx
66+
val process = 1 - state.offset.value / blockSizePx
6767

6868
Surface(
6969
modifier = Modifier
@@ -83,7 +83,10 @@ fun TopResultView() {
8383
velocityThreshold = 60.dp
8484
),
8585
color = myTheme.topBg,
86-
shape = RoundedCornerShape(bottomStart = 25.dp, bottomEnd = 25.dp),
86+
shape = RoundedCornerShape(
87+
bottomStart = 25.dp * (1 - process),
88+
bottomEnd = 25.dp * (1 - process)
89+
),
8790
tonalElevation = 3.dp,
8891
shadowElevation = 3.dp
8992
) {
@@ -123,7 +126,9 @@ fun TextBox(process: Float) {
123126
) {
124127
LazyColumn(
125128
modifier = Modifier
126-
.weight(1f),
129+
.weight(1f)
130+
.background(myTheme.topListBg)
131+
.padding(start = 10.dp, end = 10.dp),
127132
reverseLayout = true,
128133
userScrollEnabled = true,
129134
) {
@@ -143,16 +148,20 @@ fun TextBox(process: Float) {
143148
}
144149
}
145150

146-
InputText(process)
147-
148-
Spacer(modifier = Modifier.height(5.dp))
151+
Surface(
152+
modifier = Modifier.background(myTheme.topListBg),
153+
color = myTheme.topListBg,
154+
shape = RoundedCornerShape(topStart = 25.dp, topEnd = 25.dp),
155+
tonalElevation = 3.dp * (process),
156+
shadowElevation = 3.dp * (process),
157+
) {
158+
InputText(process)
159+
}
149160

150161
Box(
151162
modifier = Modifier
152-
.padding(
153-
top = 10.dp,
154-
bottom = 10.dp
155-
)
163+
.background(evaluator(1 - process, myTheme.bottomBg, myTheme.topBg))
164+
.padding(top = 10.dp, bottom = 10.dp)
156165
.fillMaxWidth()
157166
) {
158167
SlideIndicator(process)

app/src/main/java/com/jyn/composecalculator/ui/theme/Color.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ val btnEqualBgLight = Color(0xFFD1E3FD)
2929
val btnClearBgLight = Color(0xFFC3EFD0)
3030
val bottomBgLight = Color(0xFFFFFFFF)
3131
val topBgLight = Color(0xFFEAEFFA)
32+
val topListBgLight = Color(0xFFF1F6FD)
3233

3334
val textColorDark = Color(0xFFC0E7FB)
3435
val btnNumBgDark = Color(0xFF29292B)
@@ -37,3 +38,4 @@ val btnEqualBgDark = Color(0xFF0742A0)
3738
val btnClearBgDark = Color(0xFF105225)
3839
val bottomBgDark = Color(0xFF1F1F1F)
3940
val topBgDark = Color(0xFF38393C)
41+
val topListBgDark = Color(0xFF2E2F32)

app/src/main/java/com/jyn/composecalculator/ui/theme/Theme.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ open class MyTheme(
3131
val btnClearBg: Color, // C号
3232
val bottomBg:Color, // 底部背景色
3333
val topBg: Color, // 顶部背景色
34+
val topListBg: Color, // 顶部列表背景色
3435
)
3536

3637
private val MyLightColor = MyTheme(
@@ -41,6 +42,7 @@ private val MyLightColor = MyTheme(
4142
btnClearBg = btnClearBgLight,
4243
bottomBg = bottomBgLight,
4344
topBg = topBgLight,
45+
topListBg = topListBgLight,
4446
)
4547

4648
private val MyDarkColor = MyTheme(
@@ -51,6 +53,7 @@ private val MyDarkColor = MyTheme(
5153
btnClearBg = btnClearBgDark,
5254
bottomBg = bottomBgDark,
5355
topBg = topBgDark,
56+
topListBg = topListBgDark,
5457
)
5558

5659
val myTheme: MyTheme

app/src/main/java/com/jyn/composecalculator/ui/view/ItemTextView.kt

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import androidx.compose.foundation.horizontalScroll
55
import androidx.compose.foundation.layout.*
66
import androidx.compose.foundation.rememberScrollState
77
import androidx.compose.foundation.shape.RoundedCornerShape
8-
import androidx.compose.foundation.text.selection.SelectionContainer
98
import androidx.compose.material3.Surface
109
import androidx.compose.material3.Text
1110
import androidx.compose.runtime.Composable
@@ -15,26 +14,21 @@ import androidx.compose.runtime.remember
1514
import androidx.compose.ui.Alignment
1615
import androidx.compose.ui.Modifier
1716
import androidx.compose.ui.draw.alpha
18-
import androidx.compose.ui.draw.clip
19-
import androidx.compose.ui.draw.shadow
2017
import androidx.compose.ui.graphics.Color
2118
import androidx.compose.ui.layout.onSizeChanged
2219
import androidx.compose.ui.text.ExperimentalTextApi
2320
import androidx.compose.ui.text.PlatformTextStyle
2421
import androidx.compose.ui.text.TextStyle
25-
import androidx.compose.ui.text.font.FontStyle
2622
import androidx.compose.ui.text.style.TextAlign
2723
import androidx.compose.ui.tooling.preview.Preview
2824
import androidx.compose.ui.unit.dp
29-
import androidx.compose.ui.unit.em
3025
import androidx.compose.ui.unit.sp
3126
import androidx.lifecycle.viewmodel.compose.viewModel
3227
import com.jyn.composecalculator.DateViewModel
3328
import com.jyn.composecalculator.isPortrait
3429
import com.jyn.composecalculator.ui.theme.evaluator
3530
import com.jyn.composecalculator.ui.theme.myTheme
3631

37-
3832
@Composable
3933
fun InputText(process: Float) {
4034
val viewModel = viewModel<DateViewModel>()
@@ -51,40 +45,52 @@ fun InputText(process: Float) {
5145
resultScrollState.scrollTo(resultTextWidth.value) //自动滚动到最后一个
5246
}
5347

54-
Column(
55-
modifier = Modifier
56-
.background(evaluator(process, myTheme.bottomBg, myTheme.topBg))
57-
.height(viewModel.textBoxHeight * 1f)
58-
.alpha(1f)
59-
.padding(start = 10.dp, end = 10.dp),
60-
verticalArrangement = Arrangement.Center
61-
) {
62-
Row(verticalAlignment = Alignment.CenterVertically) {
48+
Box {
49+
Column(
50+
modifier = Modifier
51+
.align(Alignment.CenterEnd)
52+
.background(evaluator(1- process, myTheme.bottomBg, myTheme.topBg))
53+
.height(viewModel.textBoxHeight * 1f)
54+
.alpha(1f)
55+
.padding(start = 10.dp, end = 10.dp),
56+
verticalArrangement = Arrangement.Center
57+
) {
58+
Row(verticalAlignment = Alignment.CenterVertically) {
59+
Text(
60+
modifier = Modifier
61+
.weight(1f)
62+
.horizontalScroll(inputScrollState)
63+
.onSizeChanged { inputTextWidth.value = it.width },
64+
text = viewModel.inputText.value,
65+
color = myTheme.textColor,
66+
maxLines = 1,
67+
fontSize = if (isPortrait) 50.sp else 25.sp,
68+
textAlign = TextAlign.End,
69+
)
70+
CursorView(if (isPortrait) 50.dp else 25.dp)
71+
}
72+
6373
Text(
74+
text = viewModel.resultText.value,
6475
modifier = Modifier
65-
.weight(1f)
66-
.horizontalScroll(inputScrollState)
67-
.onSizeChanged { inputTextWidth.value = it.width },
68-
text = viewModel.inputText.value,
69-
color = myTheme.textColor,
76+
.fillMaxWidth()
77+
.padding(end = 5.dp)
78+
.horizontalScroll(resultScrollState)
79+
.onSizeChanged { resultTextWidth.value = it.width },
7080
maxLines = 1,
71-
fontSize = if (isPortrait) 50.sp else 25.sp,
81+
fontSize = if (isPortrait) 30.sp else 15.sp,
82+
color = Color.Gray,
7283
textAlign = TextAlign.End,
7384
)
74-
CursorView(if (isPortrait) 50.dp else 25.dp)
7585
}
7686

7787
Text(
78-
text = viewModel.resultText.value,
7988
modifier = Modifier
80-
.fillMaxWidth()
81-
.padding(end = 5.dp)
82-
.horizontalScroll(resultScrollState)
83-
.onSizeChanged { resultTextWidth.value = it.width },
84-
maxLines = 1,
85-
fontSize = if (isPortrait) 30.sp else 15.sp,
89+
.padding(10.dp)
90+
.alpha(process),
91+
text = "当前表达式",
8692
color = Color.Gray,
87-
textAlign = TextAlign.End,
93+
fontSize = if (isPortrait) 20.sp else 10.sp,
8894
)
8995
}
9096
}

app/src/main/java/com/jyn/composecalculator/ui/view/SlideIndicator.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import com.jyn.composecalculator.ui.theme.myTheme
2222
*/
2323
@Composable
2424
fun SlideIndicator(process: Float) {
25-
var offsetProcess = 1 - process
25+
var offsetProcess = process
2626
if (offsetProcess < 0) offsetProcess *= 10
2727
LogUtils.tag("SlideIndicator").i("process: $offsetProcess")
2828
val width = 30.dp

0 commit comments

Comments
 (0)