@@ -3,16 +3,15 @@ package com.jyn.composecalculator.ui
3
3
import androidx.compose.foundation.gestures.Orientation
4
4
import androidx.compose.foundation.layout.*
5
5
import androidx.compose.foundation.shape.RoundedCornerShape
6
- import androidx.compose.material.ExperimentalMaterialApi
7
- import androidx.compose.material.FractionalThreshold
8
- import androidx.compose.material.rememberSwipeableState
9
- import androidx.compose.material.swipeable
6
+ import androidx.compose.material.*
7
+ import androidx.compose.material.SwipeableDefaults.resistanceConfig
10
8
import androidx.compose.material3.Surface
11
9
import androidx.compose.material3.Text
12
10
import androidx.compose.runtime.Composable
13
11
import androidx.compose.ui.Modifier
14
12
import androidx.compose.ui.platform.LocalConfiguration
15
13
import androidx.compose.ui.platform.LocalDensity
14
+ import androidx.compose.ui.text.style.TextAlign
16
15
import androidx.compose.ui.tooling.preview.Preview
17
16
import androidx.compose.ui.unit.IntOffset
18
17
import androidx.compose.ui.unit.dp
@@ -28,7 +27,7 @@ import kotlinx.coroutines.DelicateCoroutinesApi
28
27
* Created by jiaoyaning on 2022/8/6.
29
28
*/
30
29
31
- @OptIn(ExperimentalMaterialApi ::class , DelicateCoroutinesApi :: class )
30
+ @OptIn(ExperimentalMaterialApi ::class )
32
31
@Preview(showBackground = true )
33
32
@Composable
34
33
fun TopResultView () {
@@ -40,13 +39,13 @@ fun TopResultView() {
40
39
val screenWidth = configuration.screenWidthDp.dp
41
40
// 偏移量
42
41
val topHeight = screenHeight * BOTTOM_FRACTION + 10 .dp
42
+ val textBoxHeight = screenHeight - topHeight
43
+ viewModel.textBoxHeight = textBoxHeight
43
44
44
45
// 记录是否是最小值
45
- val state = rememberSwipeableState(true , confirmStateChange = {
46
- LogUtils .tag(" rememberSwipeableState" ).i(" confirmStateChange: $it " )
47
- true
48
- })
46
+ val state = rememberSwipeableState(true )
49
47
val blockSizePx = with (LocalDensity .current) { - topHeight.toPx() }
48
+ val anchors = mapOf (0f to false , blockSizePx to true )
50
49
Surface (
51
50
modifier = Modifier
52
51
.width(screenWidth)
@@ -55,27 +54,51 @@ fun TopResultView() {
55
54
.swipeable(
56
55
orientation = Orientation .Vertical ,
57
56
state = state,
58
- anchors = mapOf ( 0f to false , blockSizePx to true ) ,
57
+ anchors = anchors ,
59
58
thresholds = { _, _ -> FractionalThreshold (0.2f ) },
59
+ resistance = resistanceConfig(
60
+ anchors.keys,
61
+ 10 .dp.value,
62
+ 5f
63
+ ),
64
+ velocityThreshold = 60 .dp
60
65
),
61
66
shape = RoundedCornerShape (bottomStart = 25 .dp, bottomEnd = 25 .dp),
62
67
tonalElevation = 3 .dp,
63
68
shadowElevation = 3 .dp
64
69
) {
65
- Column (
70
+ TextBox (process = 100 - (state.offset.value / blockSizePx * 100 ))
71
+ }
72
+ }
73
+
74
+ @Composable
75
+ fun TextBox (process : Float ) {
76
+ val isMax = process >= 100
77
+ val viewModel = viewModel<DateViewModel >()
78
+ Column (
79
+ modifier = Modifier
80
+ .fillMaxWidth()
81
+ .padding(10 .dp),
82
+ verticalArrangement = Arrangement .Bottom
83
+ ) {
84
+ ItemText (viewModel.inputText.value, " " )
85
+
86
+ Text (" process $process " , fontSize = 18 .sp)
87
+
88
+ Spacer (modifier = Modifier .height(5 .dp))
89
+
90
+ Box (
66
91
modifier = Modifier
67
92
.fillMaxWidth()
68
- .padding(15 .dp),
69
- verticalArrangement = Arrangement .Bottom
70
93
) {
71
- Text (" TopResultView ${state.offset.value} " , fontSize = 18 .sp)
72
-
73
- Box (
74
- modifier = Modifier
75
- .fillMaxWidth()
76
- ) {
77
- SlideIndicator (100 - (state.offset.value / blockSizePx * 100 ))
78
- }
94
+ SlideIndicator (process)
79
95
}
80
96
}
97
+ }
98
+
99
+ @Composable
100
+ fun ItemText (input : String , result : String ) {
101
+ Column (verticalArrangement = Arrangement .Bottom ) {
102
+ Text (modifier = Modifier .fillMaxWidth(), text = input, textAlign = TextAlign .End )
103
+ }
81
104
}
0 commit comments