Skip to content

Commit ef1b20e

Browse files
committed
调整SearchBar动画
1 parent 97cc719 commit ef1b20e

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

example/src/commonMain/kotlin/MainPage.kt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,11 @@ fun MainPage(
9191
SmallTitle(text = "SearchBar")
9292
SearchBar(
9393
modifier = Modifier
94-
.padding(start = 12.dp, end = 12.dp, bottom = 6.dp),
94+
.padding(start = 12.dp, bottom = 6.dp),
9595
inputField = {
9696
InputField(
97+
modifier = Modifier
98+
.padding(end = 12.dp),
9799
query = miuixSearchValue,
98100
onQueryChange = { miuixSearchValue = it },
99101
onSearch = { expanded = false },
@@ -105,7 +107,7 @@ fun MainPage(
105107
outsideRightAction = {
106108
Text(
107109
modifier = Modifier
108-
.padding(start = 12.dp)
110+
.padding(end = 12.dp)
109111
.clickable(
110112
interactionSource = null,
111113
indication = null
@@ -169,9 +171,11 @@ fun MainPage(
169171
SmallTitle(text = "SearchBar")
170172
SearchBar(
171173
modifier = Modifier
172-
.padding(start = 12.dp, end = 12.dp, bottom = 6.dp),
174+
.padding(start = 12.dp, bottom = 6.dp),
173175
inputField = {
174176
InputField(
177+
modifier = Modifier
178+
.padding(end = 12.dp),
175179
query = miuixSearchValue,
176180
onQueryChange = { miuixSearchValue = it },
177181
onSearch = { expanded = false },
@@ -183,7 +187,7 @@ fun MainPage(
183187
outsideRightAction = {
184188
Text(
185189
modifier = Modifier
186-
.padding(start = 12.dp)
190+
.padding(end = 12.dp)
187191
.clickable(
188192
interactionSource = null,
189193
indication = null

miuix/src/commonMain/kotlin/top/yukonga/miuix/kmp/basic/SearchBar.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
package top.yukonga.miuix.kmp.basic
22

33
import androidx.compose.animation.AnimatedVisibility
4+
import androidx.compose.animation.expandHorizontally
45
import androidx.compose.animation.fadeIn
56
import androidx.compose.animation.fadeOut
7+
import androidx.compose.animation.shrinkHorizontally
8+
import androidx.compose.animation.slideInHorizontally
9+
import androidx.compose.animation.slideOutHorizontally
610
import androidx.compose.foundation.background
711
import androidx.compose.foundation.clickable
812
import androidx.compose.foundation.interaction.Interaction
@@ -80,7 +84,9 @@ fun SearchBar(
8084
inputField()
8185
}
8286
AnimatedVisibility(
83-
visible = expanded
87+
visible = expanded,
88+
enter = expandHorizontally() + slideInHorizontally(initialOffsetX = { it }),
89+
exit = shrinkHorizontally() + slideOutHorizontally(targetOffsetX = { it })
8490
) {
8591
outsideRightAction?.invoke()
8692
}

0 commit comments

Comments
 (0)