Tweak SearchScreen code

This commit is contained in:
vfsfitvnm 2022-09-28 17:06:25 +02:00
parent 6f56cab129
commit 7a3c0ca110
3 changed files with 42 additions and 53 deletions

View file

@ -1,20 +1,14 @@
package it.vfsfitvnm.vimusic.ui.screens.search
import androidx.compose.animation.ExperimentalAnimationApi
import androidx.compose.animation.core.tween
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.text.BasicText
import androidx.compose.foundation.text.BasicTextField
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.SolidColor
import androidx.compose.ui.text.input.ImeAction
@ -37,7 +31,6 @@ import it.vfsfitvnm.vimusic.utils.asMediaItem
import it.vfsfitvnm.vimusic.utils.forcePlay
import it.vfsfitvnm.vimusic.utils.medium
import it.vfsfitvnm.vimusic.utils.produceSaveableState
import it.vfsfitvnm.vimusic.utils.secondary
import it.vfsfitvnm.youtubemusic.models.NavigationEndpoint
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.flowOn
@ -47,7 +40,8 @@ import kotlinx.coroutines.flow.flowOn
@Composable
fun LocalSongSearch(
textFieldValue: TextFieldValue,
onTextFieldValueChanged: (TextFieldValue) -> Unit
onTextFieldValueChanged: (TextFieldValue) -> Unit,
decorationBox: @Composable (@Composable () -> Unit) -> Unit
) {
val (colorPalette, typography) = LocalAppearance.current
val binder = LocalPlayerServiceBinder.current
@ -86,25 +80,7 @@ fun LocalSongSearch(
maxLines = 1,
keyboardOptions = KeyboardOptions(imeAction = ImeAction.Done),
cursorBrush = SolidColor(colorPalette.text),
decorationBox = { innerTextField ->
Box {
androidx.compose.animation.AnimatedVisibility(
visible = textFieldValue.text.isEmpty(),
enter = fadeIn(tween(200)),
exit = fadeOut(tween(200)),
modifier = Modifier
.align(Alignment.CenterEnd)
) {
BasicText(
text = "Enter a name",
maxLines = 1,
style = typography.xxl.secondary
)
}
innerTextField()
}
}
decorationBox = decorationBox
)
},
actionsContent = {

View file

@ -1,8 +1,5 @@
package it.vfsfitvnm.vimusic.ui.screens.search
import androidx.compose.animation.core.tween
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.foundation.clickable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.Box
@ -65,7 +62,8 @@ fun OnlineSearch(
textFieldValue: TextFieldValue,
onTextFieldValueChanged: (TextFieldValue) -> Unit,
onSearch: (String) -> Unit,
onViewPlaylist: (String) -> Unit
onViewPlaylist: (String) -> Unit,
decorationBox: @Composable (@Composable () -> Unit) -> Unit
) {
val (colorPalette, typography) = LocalAppearance.current
@ -135,25 +133,7 @@ fun OnlineSearch(
}
),
cursorBrush = SolidColor(colorPalette.text),
decorationBox = { innerTextField ->
Box {
androidx.compose.animation.AnimatedVisibility(
visible = textFieldValue.text.isEmpty(),
enter = fadeIn(tween(200)),
exit = fadeOut(tween(200)),
modifier = Modifier
.align(Alignment.CenterEnd)
) {
BasicText(
text = "Enter a name",
maxLines = 1,
style = typography.xxl.secondary
)
}
innerTextField()
}
},
decorationBox = decorationBox,
modifier = Modifier
.focusRequester(focusRequester)
)
@ -299,7 +279,7 @@ fun OnlineSearch(
)
}
}
} ?: suggestionsResult?.exceptionOrNull()?.let { throwable ->
} ?: suggestionsResult?.exceptionOrNull()?.let {
item {
Box(
modifier = Modifier

View file

@ -1,17 +1,27 @@
package it.vfsfitvnm.vimusic.ui.screens.search
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.ExperimentalAnimationApi
import androidx.compose.animation.core.tween
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.text.BasicText
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.saveable.rememberSaveableStateHolder
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.TextRange
import androidx.compose.ui.text.input.TextFieldValue
import it.vfsfitvnm.route.RouteHandler
import it.vfsfitvnm.vimusic.R
import it.vfsfitvnm.vimusic.ui.components.themed.Scaffold
import it.vfsfitvnm.vimusic.ui.screens.globalRoutes
import it.vfsfitvnm.vimusic.ui.styling.LocalAppearance
import it.vfsfitvnm.vimusic.utils.secondary
@ExperimentalFoundationApi
@ExperimentalAnimationApi
@ -43,6 +53,26 @@ fun SearchScreen(
globalRoutes()
host {
val decorationBox: @Composable (@Composable () -> Unit) -> Unit = { innerTextField ->
Box {
AnimatedVisibility(
visible = textFieldValue.text.isEmpty(),
enter = fadeIn(tween(300)),
exit = fadeOut(tween(300)),
modifier = Modifier
.align(Alignment.CenterEnd)
) {
BasicText(
text = "Enter a name",
maxLines = 1,
style = LocalAppearance.current.typography.xxl.secondary
)
}
innerTextField()
}
}
Scaffold(
topIconButtonId = R.drawable.chevron_back,
onTopIconButtonClick = pop,
@ -59,11 +89,14 @@ fun SearchScreen(
textFieldValue = textFieldValue,
onTextFieldValueChanged = onTextFieldValueChanged,
onSearch = onSearch,
onViewPlaylist = onViewPlaylist
onViewPlaylist = onViewPlaylist,
decorationBox = decorationBox
)
1 -> LocalSongSearch(
textFieldValue = textFieldValue,
onTextFieldValueChanged = onTextFieldValueChanged
onTextFieldValueChanged = onTextFieldValueChanged,
decorationBox = decorationBox
)
}
}