Hide keyboard on scroll
This commit is contained in:
parent
10be596036
commit
c577a4911d
@ -29,6 +29,7 @@ import androidx.compose.ui.input.nestedscroll.NestedScrollSource
|
|||||||
import androidx.compose.ui.input.nestedscroll.nestedScroll
|
import androidx.compose.ui.input.nestedscroll.nestedScroll
|
||||||
import androidx.compose.ui.platform.LocalDensity
|
import androidx.compose.ui.platform.LocalDensity
|
||||||
import androidx.compose.ui.platform.LocalLayoutDirection
|
import androidx.compose.ui.platform.LocalLayoutDirection
|
||||||
|
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.unit.IntOffset
|
import androidx.compose.ui.unit.IntOffset
|
||||||
import androidx.compose.ui.unit.LayoutDirection
|
import androidx.compose.ui.unit.LayoutDirection
|
||||||
@ -47,6 +48,7 @@ import de.mm20.launcher2.ui.launcher.widgets.WidgetColumn
|
|||||||
import de.mm20.launcher2.ui.launcher.widgets.clock.ClockWidget
|
import de.mm20.launcher2.ui.launcher.widgets.clock.ClockWidget
|
||||||
import de.mm20.launcher2.ui.utils.rememberNotificationShadeController
|
import de.mm20.launcher2.ui.utils.rememberNotificationShadeController
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlin.math.absoluteValue
|
||||||
import kotlin.math.roundToInt
|
import kotlin.math.roundToInt
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
@ -191,6 +193,8 @@ fun PagerScaffold(
|
|||||||
val notificationDragThreshold = with(LocalDensity.current) { 200.dp.toPx() }
|
val notificationDragThreshold = with(LocalDensity.current) { 200.dp.toPx() }
|
||||||
val notificationShadeController = rememberNotificationShadeController()
|
val notificationShadeController = rememberNotificationShadeController()
|
||||||
|
|
||||||
|
val keyboardController = LocalSoftwareKeyboardController.current
|
||||||
|
|
||||||
val nestedScrollConnection = remember {
|
val nestedScrollConnection = remember {
|
||||||
object : NestedScrollConnection {
|
object : NestedScrollConnection {
|
||||||
private var pullDownTotalY: Float? = 0f
|
private var pullDownTotalY: Float? = 0f
|
||||||
@ -222,6 +226,15 @@ fun PagerScaffold(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val searchNestedScrollConnection = remember { object: NestedScrollConnection {
|
||||||
|
override fun onPreScroll(available: Offset, source: NestedScrollSource): Offset {
|
||||||
|
if (source == NestedScrollSource.Drag && available.y.absoluteValue > available.x.absoluteValue * 2) {
|
||||||
|
keyboardController?.hide()
|
||||||
|
}
|
||||||
|
return super.onPreScroll(available, source)
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
|
||||||
val insets = WindowInsets.safeDrawing.asPaddingValues()
|
val insets = WindowInsets.safeDrawing.asPaddingValues()
|
||||||
|
|
||||||
Box(
|
Box(
|
||||||
@ -335,6 +348,7 @@ fun PagerScaffold(
|
|||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.requiredWidth(width)
|
.requiredWidth(width)
|
||||||
.fillMaxHeight()
|
.fillMaxHeight()
|
||||||
|
.nestedScroll(searchNestedScrollConnection)
|
||||||
.padding(
|
.padding(
|
||||||
start = windowInsets.calculateStartPadding(LocalLayoutDirection.current),
|
start = windowInsets.calculateStartPadding(LocalLayoutDirection.current),
|
||||||
end = windowInsets.calculateStartPadding(LocalLayoutDirection.current),
|
end = windowInsets.calculateStartPadding(LocalLayoutDirection.current),
|
||||||
|
|||||||
@ -27,6 +27,7 @@ import androidx.compose.ui.input.nestedscroll.NestedScrollSource
|
|||||||
import androidx.compose.ui.input.nestedscroll.nestedScroll
|
import androidx.compose.ui.input.nestedscroll.nestedScroll
|
||||||
import androidx.compose.ui.platform.LocalDensity
|
import androidx.compose.ui.platform.LocalDensity
|
||||||
import androidx.compose.ui.platform.LocalLayoutDirection
|
import androidx.compose.ui.platform.LocalLayoutDirection
|
||||||
|
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.unit.IntOffset
|
import androidx.compose.ui.unit.IntOffset
|
||||||
import androidx.compose.ui.unit.Velocity
|
import androidx.compose.ui.unit.Velocity
|
||||||
@ -43,6 +44,7 @@ import de.mm20.launcher2.ui.launcher.search.SearchVM
|
|||||||
import de.mm20.launcher2.ui.launcher.widgets.WidgetColumn
|
import de.mm20.launcher2.ui.launcher.widgets.WidgetColumn
|
||||||
import de.mm20.launcher2.ui.launcher.widgets.clock.ClockWidget
|
import de.mm20.launcher2.ui.launcher.widgets.clock.ClockWidget
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlin.math.absoluteValue
|
||||||
import kotlin.math.roundToInt
|
import kotlin.math.roundToInt
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
@ -193,10 +195,15 @@ fun PullDownScaffold(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val keyboardController = LocalSoftwareKeyboardController.current
|
||||||
|
|
||||||
val nestedScrollConnection = remember {
|
val nestedScrollConnection = remember {
|
||||||
object : NestedScrollConnection {
|
object : NestedScrollConnection {
|
||||||
override fun onPreScroll(available: Offset, source: NestedScrollSource): Offset {
|
override fun onPreScroll(available: Offset, source: NestedScrollSource): Offset {
|
||||||
if (isWidgetEditMode) return Offset.Zero
|
if (isWidgetEditMode) return Offset.Zero
|
||||||
|
if (source == NestedScrollSource.Drag && available.y.absoluteValue > available.x.absoluteValue * 2) {
|
||||||
|
keyboardController?.hide()
|
||||||
|
}
|
||||||
val canPullDown = if (isSearchOpen) {
|
val canPullDown = if (isSearchOpen) {
|
||||||
isSearchAtStart
|
isSearchAtStart
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user