mirror of
https://github.com/gkd-kit/gkd.git
synced 2024-11-16 11:42:22 +08:00
perf: app search bar style
This commit is contained in:
parent
9e79f1eab6
commit
6f2d47ea04
|
@ -7,14 +7,12 @@ import androidx.compose.foundation.layout.heightIn
|
|||
import androidx.compose.foundation.text.BasicTextField
|
||||
import androidx.compose.foundation.text.KeyboardActions
|
||||
import androidx.compose.foundation.text.KeyboardOptions
|
||||
import androidx.compose.foundation.text.selection.LocalTextSelectionColors
|
||||
import androidx.compose.material3.LocalTextStyle
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextFieldDefaults
|
||||
import androidx.compose.material3.TextFieldDefaults.indicatorLine
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.CompositionLocalProvider
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
|
@ -22,9 +20,7 @@ import androidx.compose.runtime.setValue
|
|||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.SolidColor
|
||||
import androidx.compose.ui.graphics.takeOrElse
|
||||
import androidx.compose.ui.text.TextRange
|
||||
import androidx.compose.ui.text.TextStyle
|
||||
import androidx.compose.ui.text.input.TextFieldValue
|
||||
import androidx.compose.ui.text.input.VisualTransformation
|
||||
import androidx.compose.ui.unit.dp
|
||||
|
@ -42,19 +38,17 @@ fun AppBarTextField(
|
|||
keyboardActions: KeyboardActions = KeyboardActions.Default,
|
||||
) {
|
||||
val interactionSource = remember { MutableInteractionSource() }
|
||||
val textStyle = LocalTextStyle.current
|
||||
|
||||
// make sure there is no background color in the decoration box
|
||||
val colors = TextFieldDefaults.colors(
|
||||
focusedContainerColor = Color.Unspecified,
|
||||
unfocusedContainerColor = Color.Unspecified,
|
||||
disabledContainerColor = Color.Unspecified,
|
||||
focusedContainerColor = Color.Transparent,
|
||||
unfocusedContainerColor = Color.Transparent,
|
||||
disabledContainerColor = Color.Transparent,
|
||||
focusedIndicatorColor = Color.Transparent,
|
||||
unfocusedIndicatorColor = Color.Transparent,
|
||||
)
|
||||
|
||||
// If color is not provided via the text style, use content color as a default
|
||||
val textColor = textStyle.color.takeOrElse {
|
||||
MaterialTheme.colorScheme.onSurface
|
||||
}
|
||||
val mergedTextStyle = textStyle.merge(TextStyle(color = textColor))
|
||||
val mergedTextStyle = LocalTextStyle.current.merge(MaterialTheme.typography.titleMedium)
|
||||
|
||||
// request focus when this composable is first initialized
|
||||
// val focusRequester = FocusRequester()
|
||||
|
@ -68,9 +62,6 @@ fun AppBarTextField(
|
|||
}
|
||||
textFieldValue = textFieldValue.copy(text = value) // make sure to keep the value updated
|
||||
|
||||
CompositionLocalProvider(
|
||||
LocalTextSelectionColors provides LocalTextSelectionColors.current
|
||||
) {
|
||||
BasicTextField(
|
||||
value = textFieldValue,
|
||||
onValueChange = {
|
||||
|
@ -111,4 +102,3 @@ fun AppBarTextField(
|
|||
},
|
||||
)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user