Tweak SearchScreen code
This commit is contained in:
@@ -1,20 +1,14 @@
|
|||||||
package it.vfsfitvnm.vimusic.ui.screens.search
|
package it.vfsfitvnm.vimusic.ui.screens.search
|
||||||
|
|
||||||
import androidx.compose.animation.ExperimentalAnimationApi
|
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.ExperimentalFoundationApi
|
||||||
import androidx.compose.foundation.layout.Box
|
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
import androidx.compose.foundation.lazy.LazyColumn
|
import androidx.compose.foundation.lazy.LazyColumn
|
||||||
import androidx.compose.foundation.lazy.items
|
import androidx.compose.foundation.lazy.items
|
||||||
import androidx.compose.foundation.text.BasicText
|
|
||||||
import androidx.compose.foundation.text.BasicTextField
|
import androidx.compose.foundation.text.BasicTextField
|
||||||
import androidx.compose.foundation.text.KeyboardOptions
|
import androidx.compose.foundation.text.KeyboardOptions
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.ui.Alignment
|
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.graphics.SolidColor
|
import androidx.compose.ui.graphics.SolidColor
|
||||||
import androidx.compose.ui.text.input.ImeAction
|
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.forcePlay
|
||||||
import it.vfsfitvnm.vimusic.utils.medium
|
import it.vfsfitvnm.vimusic.utils.medium
|
||||||
import it.vfsfitvnm.vimusic.utils.produceSaveableState
|
import it.vfsfitvnm.vimusic.utils.produceSaveableState
|
||||||
import it.vfsfitvnm.vimusic.utils.secondary
|
|
||||||
import it.vfsfitvnm.youtubemusic.models.NavigationEndpoint
|
import it.vfsfitvnm.youtubemusic.models.NavigationEndpoint
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.flow.flowOn
|
import kotlinx.coroutines.flow.flowOn
|
||||||
@@ -47,7 +40,8 @@ import kotlinx.coroutines.flow.flowOn
|
|||||||
@Composable
|
@Composable
|
||||||
fun LocalSongSearch(
|
fun LocalSongSearch(
|
||||||
textFieldValue: TextFieldValue,
|
textFieldValue: TextFieldValue,
|
||||||
onTextFieldValueChanged: (TextFieldValue) -> Unit
|
onTextFieldValueChanged: (TextFieldValue) -> Unit,
|
||||||
|
decorationBox: @Composable (@Composable () -> Unit) -> Unit
|
||||||
) {
|
) {
|
||||||
val (colorPalette, typography) = LocalAppearance.current
|
val (colorPalette, typography) = LocalAppearance.current
|
||||||
val binder = LocalPlayerServiceBinder.current
|
val binder = LocalPlayerServiceBinder.current
|
||||||
@@ -86,25 +80,7 @@ fun LocalSongSearch(
|
|||||||
maxLines = 1,
|
maxLines = 1,
|
||||||
keyboardOptions = KeyboardOptions(imeAction = ImeAction.Done),
|
keyboardOptions = KeyboardOptions(imeAction = ImeAction.Done),
|
||||||
cursorBrush = SolidColor(colorPalette.text),
|
cursorBrush = SolidColor(colorPalette.text),
|
||||||
decorationBox = { innerTextField ->
|
decorationBox = decorationBox
|
||||||
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()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
actionsContent = {
|
actionsContent = {
|
||||||
|
|||||||
@@ -1,8 +1,5 @@
|
|||||||
package it.vfsfitvnm.vimusic.ui.screens.search
|
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.clickable
|
||||||
import androidx.compose.foundation.interaction.MutableInteractionSource
|
import androidx.compose.foundation.interaction.MutableInteractionSource
|
||||||
import androidx.compose.foundation.layout.Box
|
import androidx.compose.foundation.layout.Box
|
||||||
@@ -65,7 +62,8 @@ fun OnlineSearch(
|
|||||||
textFieldValue: TextFieldValue,
|
textFieldValue: TextFieldValue,
|
||||||
onTextFieldValueChanged: (TextFieldValue) -> Unit,
|
onTextFieldValueChanged: (TextFieldValue) -> Unit,
|
||||||
onSearch: (String) -> Unit,
|
onSearch: (String) -> Unit,
|
||||||
onViewPlaylist: (String) -> Unit
|
onViewPlaylist: (String) -> Unit,
|
||||||
|
decorationBox: @Composable (@Composable () -> Unit) -> Unit
|
||||||
) {
|
) {
|
||||||
val (colorPalette, typography) = LocalAppearance.current
|
val (colorPalette, typography) = LocalAppearance.current
|
||||||
|
|
||||||
@@ -135,25 +133,7 @@ fun OnlineSearch(
|
|||||||
}
|
}
|
||||||
),
|
),
|
||||||
cursorBrush = SolidColor(colorPalette.text),
|
cursorBrush = SolidColor(colorPalette.text),
|
||||||
decorationBox = { innerTextField ->
|
decorationBox = decorationBox,
|
||||||
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()
|
|
||||||
}
|
|
||||||
},
|
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.focusRequester(focusRequester)
|
.focusRequester(focusRequester)
|
||||||
)
|
)
|
||||||
@@ -299,7 +279,7 @@ fun OnlineSearch(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} ?: suggestionsResult?.exceptionOrNull()?.let { throwable ->
|
} ?: suggestionsResult?.exceptionOrNull()?.let {
|
||||||
item {
|
item {
|
||||||
Box(
|
Box(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
|
|||||||
@@ -1,17 +1,27 @@
|
|||||||
package it.vfsfitvnm.vimusic.ui.screens.search
|
package it.vfsfitvnm.vimusic.ui.screens.search
|
||||||
|
|
||||||
|
import androidx.compose.animation.AnimatedVisibility
|
||||||
import androidx.compose.animation.ExperimentalAnimationApi
|
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.ExperimentalFoundationApi
|
||||||
|
import androidx.compose.foundation.layout.Box
|
||||||
|
import androidx.compose.foundation.text.BasicText
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.runtime.saveable.rememberSaveable
|
import androidx.compose.runtime.saveable.rememberSaveable
|
||||||
import androidx.compose.runtime.saveable.rememberSaveableStateHolder
|
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.TextRange
|
||||||
import androidx.compose.ui.text.input.TextFieldValue
|
import androidx.compose.ui.text.input.TextFieldValue
|
||||||
import it.vfsfitvnm.route.RouteHandler
|
import it.vfsfitvnm.route.RouteHandler
|
||||||
import it.vfsfitvnm.vimusic.R
|
import it.vfsfitvnm.vimusic.R
|
||||||
import it.vfsfitvnm.vimusic.ui.components.themed.Scaffold
|
import it.vfsfitvnm.vimusic.ui.components.themed.Scaffold
|
||||||
import it.vfsfitvnm.vimusic.ui.screens.globalRoutes
|
import it.vfsfitvnm.vimusic.ui.screens.globalRoutes
|
||||||
|
import it.vfsfitvnm.vimusic.ui.styling.LocalAppearance
|
||||||
|
import it.vfsfitvnm.vimusic.utils.secondary
|
||||||
|
|
||||||
@ExperimentalFoundationApi
|
@ExperimentalFoundationApi
|
||||||
@ExperimentalAnimationApi
|
@ExperimentalAnimationApi
|
||||||
@@ -43,6 +53,26 @@ fun SearchScreen(
|
|||||||
globalRoutes()
|
globalRoutes()
|
||||||
|
|
||||||
host {
|
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(
|
Scaffold(
|
||||||
topIconButtonId = R.drawable.chevron_back,
|
topIconButtonId = R.drawable.chevron_back,
|
||||||
onTopIconButtonClick = pop,
|
onTopIconButtonClick = pop,
|
||||||
@@ -59,11 +89,14 @@ fun SearchScreen(
|
|||||||
textFieldValue = textFieldValue,
|
textFieldValue = textFieldValue,
|
||||||
onTextFieldValueChanged = onTextFieldValueChanged,
|
onTextFieldValueChanged = onTextFieldValueChanged,
|
||||||
onSearch = onSearch,
|
onSearch = onSearch,
|
||||||
onViewPlaylist = onViewPlaylist
|
onViewPlaylist = onViewPlaylist,
|
||||||
|
decorationBox = decorationBox
|
||||||
)
|
)
|
||||||
|
|
||||||
1 -> LocalSongSearch(
|
1 -> LocalSongSearch(
|
||||||
textFieldValue = textFieldValue,
|
textFieldValue = textFieldValue,
|
||||||
onTextFieldValueChanged = onTextFieldValueChanged
|
onTextFieldValueChanged = onTextFieldValueChanged,
|
||||||
|
decorationBox = decorationBox
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user