Reset search bar position
This commit is contained in:
parent
7d8ac528b7
commit
a37748621f
@ -1068,16 +1068,20 @@ internal class LauncherScaffoldState(
|
|||||||
isLocked = false
|
isLocked = false
|
||||||
if (isSearchBarHidden) {
|
if (isSearchBarHidden) {
|
||||||
isSearchBarHidden = false
|
isSearchBarHidden = false
|
||||||
searchBarAnimatable.snapTo(currentSearchBarOffset)
|
resetSearchBarOffset()
|
||||||
searchBarAnimatable.animateTo(
|
}
|
||||||
0f,
|
}
|
||||||
tween(500)
|
|
||||||
) {
|
suspend fun resetSearchBarOffset() {
|
||||||
if (isSettledOnSecondaryPage) {
|
searchBarAnimatable.snapTo(currentSearchBarOffset)
|
||||||
secondaryPageSearchBarOffset = this.value
|
searchBarAnimatable.animateTo(
|
||||||
} else {
|
0f,
|
||||||
homePageSearchBarOffset = this.value
|
tween(500)
|
||||||
}
|
) {
|
||||||
|
if (isSettledOnSecondaryPage) {
|
||||||
|
secondaryPageSearchBarOffset = this.value
|
||||||
|
} else {
|
||||||
|
homePageSearchBarOffset = this.value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1171,6 +1175,14 @@ internal fun LauncherScaffold(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LaunchedEffect(state.isAtTop, state.isAtBottom) {
|
||||||
|
when(state.currentComponent?.reverseScrolling) {
|
||||||
|
true -> if (state.isAtBottom) state.resetSearchBarOffset()
|
||||||
|
false -> if (state.isAtTop) state.resetSearchBarOffset()
|
||||||
|
else -> {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
val searchBarHeight by animateDpAsState(
|
val searchBarHeight by animateDpAsState(
|
||||||
if (state.isSearchBarHidden) 0.dp
|
if (state.isSearchBarHidden) 0.dp
|
||||||
else if (searchActions.isEmpty()) 56.dp
|
else if (searchActions.isEmpty()) 56.dp
|
||||||
|
|||||||
@ -58,17 +58,22 @@ internal abstract class ScaffoldComponent {
|
|||||||
*/
|
*/
|
||||||
open val isAtBottom: State<Boolean?> = mutableStateOf(null)
|
open val isAtBottom: State<Boolean?> = mutableStateOf(null)
|
||||||
|
|
||||||
@Composable abstract fun Component(
|
open val reverseScrolling: Boolean = false
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
abstract fun Component(
|
||||||
modifier: Modifier,
|
modifier: Modifier,
|
||||||
insets: PaddingValues,
|
insets: PaddingValues,
|
||||||
state: LauncherScaffoldState,
|
state: LauncherScaffoldState,
|
||||||
)
|
)
|
||||||
|
|
||||||
@SuppressLint("ModifierFactoryExtensionFunction")
|
@SuppressLint("ModifierFactoryExtensionFunction")
|
||||||
open fun homePageModifier(state: LauncherScaffoldState, defaultModifier: Modifier): Modifier = defaultModifier
|
open fun homePageModifier(state: LauncherScaffoldState, defaultModifier: Modifier): Modifier =
|
||||||
|
defaultModifier
|
||||||
|
|
||||||
@SuppressLint("ModifierFactoryExtensionFunction")
|
@SuppressLint("ModifierFactoryExtensionFunction")
|
||||||
open fun searchBarModifier(state: LauncherScaffoldState, defaultModifier: Modifier): Modifier = defaultModifier
|
open fun searchBarModifier(state: LauncherScaffoldState, defaultModifier: Modifier): Modifier =
|
||||||
|
defaultModifier
|
||||||
|
|
||||||
protected var isActive by mutableStateOf(false)
|
protected var isActive by mutableStateOf(false)
|
||||||
|
|
||||||
|
|||||||
@ -1,13 +1,10 @@
|
|||||||
package de.mm20.launcher2.ui.launcher.scaffold
|
package de.mm20.launcher2.ui.launcher.scaffold
|
||||||
|
|
||||||
import androidx.compose.foundation.layout.PaddingValues
|
import androidx.compose.foundation.layout.PaddingValues
|
||||||
import androidx.compose.foundation.lazy.LazyListState
|
|
||||||
import androidx.compose.foundation.lazy.rememberLazyListState
|
import androidx.compose.foundation.lazy.rememberLazyListState
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
import androidx.compose.runtime.MutableState
|
import androidx.compose.runtime.MutableState
|
||||||
import androidx.compose.runtime.State
|
|
||||||
import androidx.compose.runtime.derivedStateOf
|
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
@ -28,6 +25,8 @@ internal class SearchComponent(
|
|||||||
|
|
||||||
override val isAtBottom: MutableState<Boolean?> = mutableStateOf(true)
|
override val isAtBottom: MutableState<Boolean?> = mutableStateOf(true)
|
||||||
|
|
||||||
|
override val reverseScrolling: Boolean = reverse
|
||||||
|
|
||||||
override val hasIme: Boolean = true
|
override val hasIme: Boolean = true
|
||||||
|
|
||||||
|
|
||||||
@ -52,8 +51,10 @@ internal class SearchComponent(
|
|||||||
}
|
}
|
||||||
|
|
||||||
LaunchedEffect(lazyListState.canScrollForward, lazyListState.canScrollBackward) {
|
LaunchedEffect(lazyListState.canScrollForward, lazyListState.canScrollBackward) {
|
||||||
isAtBottom.value = !lazyListState.canScrollForward && !reverse || !lazyListState.canScrollBackward && reverse
|
isAtBottom.value =
|
||||||
isAtTop.value = !lazyListState.canScrollForward && reverse || !lazyListState.canScrollBackward && !reverse
|
!lazyListState.canScrollForward && !reverse || !lazyListState.canScrollBackward && reverse
|
||||||
|
isAtTop.value =
|
||||||
|
!lazyListState.canScrollForward && reverse || !lazyListState.canScrollBackward && !reverse
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user