Skip to content

Commit e746546

Browse files
committed
fix(顶部): 输入框横滑问题
1 parent 50d3601 commit e746546

File tree

2 files changed

+3
-30
lines changed

2 files changed

+3
-30
lines changed

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

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,25 @@
11
package com.jyn.composecalculator.ui
22

33
import androidx.compose.foundation.gestures.Orientation
4-
import androidx.compose.foundation.horizontalScroll
5-
import androidx.compose.foundation.indication
6-
import androidx.compose.foundation.interaction.MutableInteractionSource
74
import androidx.compose.foundation.layout.*
8-
import androidx.compose.foundation.rememberScrollState
95
import androidx.compose.foundation.shape.RoundedCornerShape
106
import androidx.compose.material.ExperimentalMaterialApi
117
import androidx.compose.material.FractionalThreshold
128
import androidx.compose.material.SwipeableDefaults.resistanceConfig
139
import androidx.compose.material.rememberSwipeableState
1410
import androidx.compose.material.swipeable
1511
import androidx.compose.material3.Surface
16-
import androidx.compose.material3.Text
1712
import androidx.compose.runtime.Composable
18-
import androidx.compose.runtime.LaunchedEffect
19-
import androidx.compose.runtime.mutableStateOf
20-
import androidx.compose.runtime.remember
21-
import androidx.compose.ui.Alignment
2213
import androidx.compose.ui.Modifier
23-
import androidx.compose.ui.graphics.Color
24-
import androidx.compose.ui.layout.onSizeChanged
2514
import androidx.compose.ui.platform.LocalConfiguration
2615
import androidx.compose.ui.platform.LocalDensity
27-
import androidx.compose.ui.text.style.TextAlign
2816
import androidx.compose.ui.tooling.preview.Preview
2917
import androidx.compose.ui.unit.IntOffset
3018
import androidx.compose.ui.unit.dp
31-
import androidx.compose.ui.unit.sp
3219
import androidx.lifecycle.viewmodel.compose.viewModel
3320
import com.apkfuns.logutils.LogUtils
3421
import com.jyn.composecalculator.BOTTOM_FRACTION
3522
import com.jyn.composecalculator.DateViewModel
36-
import com.jyn.composecalculator.ui.view.CursorView
3723
import com.jyn.composecalculator.ui.view.InputText
3824
import com.jyn.composecalculator.ui.view.SlideIndicator
3925

@@ -106,4 +92,5 @@ fun TextBox(process: Float) {
10692
SlideIndicator(process)
10793
}
10894
}
109-
}
95+
}
96+

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

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package com.jyn.composecalculator.ui.view
22

33
import androidx.compose.foundation.horizontalScroll
4-
import androidx.compose.foundation.indication
5-
import androidx.compose.foundation.interaction.MutableInteractionSource
64
import androidx.compose.foundation.layout.*
75
import androidx.compose.foundation.rememberScrollState
86
import androidx.compose.material3.Text
@@ -15,7 +13,6 @@ import androidx.compose.ui.Modifier
1513
import androidx.compose.ui.graphics.Color
1614
import androidx.compose.ui.layout.onSizeChanged
1715
import androidx.compose.ui.text.style.TextAlign
18-
import androidx.compose.ui.tooling.preview.Preview
1916
import androidx.compose.ui.unit.dp
2017
import androidx.compose.ui.unit.sp
2118
import androidx.lifecycle.viewmodel.compose.viewModel
@@ -26,7 +23,6 @@ import com.jyn.composecalculator.DateViewModel
2623
fun InputText(input: String) {
2724
val viewModel = viewModel<DateViewModel>()
2825

29-
val mutableInteractionSource = remember { MutableInteractionSource() }
3026
val inputScrollState = rememberScrollState()
3127
val resultScrollState = rememberScrollState()
3228
val inputTextWidth = remember { mutableStateOf(0) }
@@ -48,10 +44,6 @@ fun InputText(input: String) {
4844
modifier = Modifier
4945
.weight(1f)
5046
.horizontalScroll(inputScrollState)
51-
.indication( //水波纹效果怎么去除无效呢,bug?
52-
indication = null,
53-
interactionSource = mutableInteractionSource
54-
)
5547
.onSizeChanged { inputTextWidth.value = it.width },
5648
text = input,
5749
maxLines = 1,
@@ -66,7 +58,7 @@ fun InputText(input: String) {
6658
modifier = Modifier
6759
.fillMaxWidth()
6860
.padding(end = 5.dp)
69-
.horizontalScroll(inputScrollState)
61+
.horizontalScroll(resultScrollState)
7062
.onSizeChanged { resultTextWidth.value = it.width },
7163
maxLines = 1,
7264
fontSize = 30.sp,
@@ -81,10 +73,4 @@ fun ItemText(input: String, result: String) {
8173
Column(verticalArrangement = Arrangement.Bottom) {
8274
Text(modifier = Modifier.fillMaxWidth(), text = input, textAlign = TextAlign.End)
8375
}
84-
}
85-
86-
@Preview
87-
@Composable
88-
fun InputTextPreview() {
89-
InputText("12345678")
9076
}

0 commit comments

Comments
 (0)