Skip to content

Commit 4198ffd

Browse files
committed
library: Allows custom Overscroll enabled platforms
1 parent 448791b commit 4198ffd

File tree

9 files changed

+24
-39
lines changed

9 files changed

+24
-39
lines changed

miuix/src/androidMain/kotlin/top/yukonga/miuix/kmp/utils/Overscroll.android.kt

Lines changed: 0 additions & 3 deletions
This file was deleted.

miuix/src/androidMain/kotlin/top/yukonga/miuix/kmp/utils/Utils.android.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,12 @@ import androidx.compose.ui.platform.LocalDensity
99
import androidx.compose.ui.platform.LocalView
1010
import androidx.compose.ui.unit.Dp
1111
import androidx.compose.ui.unit.dp
12-
import androidx.window.layout.WindowMetrics
1312
import androidx.window.layout.WindowMetricsCalculator
1413

1514
@Composable
1615
actual fun getWindowSize(): WindowSize {
1716
val context = LocalContext.current
18-
val windowMetrics: WindowMetrics = WindowMetricsCalculator.getOrCreate().computeCurrentWindowMetrics(context)
17+
val windowMetrics = WindowMetricsCalculator.getOrCreate().computeCurrentWindowMetrics(context)
1918
val widthPx = windowMetrics.bounds.width()
2019
val heightPx = windowMetrics.bounds.height()
2120
return WindowSize(widthPx, heightPx)

miuix/src/commonMain/kotlin/top/yukonga/miuix/kmp/basic/LazyColumn.kt

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ import androidx.compose.runtime.remember
1111
import androidx.compose.ui.Modifier
1212
import androidx.compose.ui.input.nestedscroll.nestedScroll
1313
import androidx.compose.ui.unit.dp
14-
import top.yukonga.miuix.kmp.utils.enableOverscroll
14+
import top.yukonga.miuix.kmp.utils.Platform
1515
import top.yukonga.miuix.kmp.utils.overScrollVertical
16+
import top.yukonga.miuix.kmp.utils.platform
1617
import top.yukonga.miuix.kmp.utils.rememberOverscrollFlingBehavior
1718

1819
/**
@@ -22,7 +23,7 @@ import top.yukonga.miuix.kmp.utils.rememberOverscrollFlingBehavior
2223
* @param state The state of the [LazyColumn].
2324
* @param contentPadding The padding to apply to the content.
2425
* @param userScrollEnabled Whether the user can scroll the [LazyColumn].
25-
* @param enableOverScroll Whether to enable over-scroll.
26+
* @param isEnabledOverScroll Whether the Overscroll is enabled.
2627
* @param topAppBarScrollBehavior The scroll behavior of the top app bar.
2728
* @param content The [Composable] content of the [LazyColumn].
2829
*/
@@ -32,13 +33,13 @@ fun LazyColumn(
3233
state: LazyListState = rememberLazyListState(),
3334
contentPadding: PaddingValues = PaddingValues(0.dp),
3435
userScrollEnabled: Boolean = true,
35-
enableOverScroll: Boolean = true,
36+
isEnabledOverScroll: () -> Boolean = { platform() == Platform.Android },
3637
topAppBarScrollBehavior: ScrollBehavior? = null,
3738
content: LazyListScope.() -> Unit
3839
) {
39-
val firstModifier = remember(enableOverScroll, enableOverscroll()) {
40-
if (enableOverScroll && enableOverscroll()) {
41-
modifier.overScrollVertical(onOverscroll = { topAppBarScrollBehavior?.isPinned = it })
40+
val firstModifier = remember(isEnabledOverScroll) {
41+
if (isEnabledOverScroll.invoke()) {
42+
modifier.overScrollVertical(onOverscroll = { topAppBarScrollBehavior?.isPinned = it }, isEnabled = isEnabledOverScroll)
4243
} else {
4344
modifier
4445
}
@@ -49,7 +50,7 @@ fun LazyColumn(
4950
} ?: firstModifier
5051
}
5152
val flingBehavior =
52-
if (enableOverScroll && enableOverscroll()) {
53+
if (isEnabledOverScroll.invoke()) {
5354
rememberOverscrollFlingBehavior { state }
5455
} else {
5556
ScrollableDefaults.flingBehavior()

miuix/src/commonMain/kotlin/top/yukonga/miuix/kmp/utils/Overscroll.kt

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,9 @@ fun Modifier.overScrollVertical(
8484
scrollEasing: ((currentOffset: Float, newOffset: Float) -> Float)? = null,
8585
springStiff: Float = OutBoundSpringStiff,
8686
springDamp: Float = OutBoundSpringDamp,
87-
onOverscroll: ((Boolean) -> Unit)? = null
88-
): Modifier = overScrollOutOfBound(isVertical = true, nestedScrollToParent, scrollEasing, springStiff, springDamp, onOverscroll)
87+
onOverscroll: ((Boolean) -> Unit)? = null,
88+
isEnabled: () -> Boolean = { platform() == Platform.Android }
89+
): Modifier = overScrollOutOfBound(isVertical = true, nestedScrollToParent, scrollEasing, springStiff, springDamp, onOverscroll, isEnabled)
8990

9091
/**
9192
* @see overScrollOutOfBound
@@ -96,22 +97,25 @@ fun Modifier.overScrollHorizontal(
9697
scrollEasing: ((currentOffset: Float, newOffset: Float) -> Float)? = null,
9798
springStiff: Float = OutBoundSpringStiff,
9899
springDamp: Float = OutBoundSpringDamp,
99-
onOverscroll: ((Boolean) -> Unit)? = null
100-
): Modifier = overScrollOutOfBound(isVertical = false, nestedScrollToParent, scrollEasing, springStiff, springDamp, onOverscroll)
100+
onOverscroll: ((Boolean) -> Unit)? = null,
101+
isEnabled: () -> Boolean = { platform() == Platform.Android }
102+
): Modifier = overScrollOutOfBound(isVertical = false, nestedScrollToParent, scrollEasing, springStiff, springDamp, onOverscroll, isEnabled)
101103

102104
/**
103105
* OverScroll effect for scrollable Composable.
104106
*
105107
* @Author: cormor
106108
107-
* @param isVertical is vertical, or horizontal ?
108-
* @param nestedScrollToParent Whether to dispatch nested scroll events to parent
109+
* @param isVertical is vertical, or horizontal?
110+
* @param nestedScrollToParent Whether to dispatch nested scroll events to parent.
109111
* @param scrollEasing U can refer to [DefaultParabolaScrollEasing], The incoming values are the currently existing overscroll Offset
110112
* and the new offset from the gesture.
111113
* modify it to cooperate with [springStiff] to customize the sliding damping effect.
112114
* The current default easing comes from iOS, you don't need to modify it!
113115
* @param springStiff springStiff for overscroll effect,For better user experience, the new value is not recommended to be higher than[StiffnessMediumLow]
114-
* @param springDamp springDamp for overscroll effect,generally do not need to set
116+
* @param springDamp springDamp for overscroll effect,generally do not need to set。
117+
* @param onOverscroll Callback when the overscroll state changes, the parameter is whether the current state is Overscrolling.
118+
* @param isEnabled Whether to enable Overscroll effect, default is true.
115119
*/
116120
@Stable
117121
@Suppress("NAME_SHADOWING")
@@ -121,9 +125,10 @@ fun Modifier.overScrollOutOfBound(
121125
scrollEasing: ((currentOffset: Float, newOffset: Float) -> Float)?,
122126
springStiff: Float = OutBoundSpringStiff,
123127
springDamp: Float = OutBoundSpringDamp,
124-
onOverscroll: ((Boolean) -> Unit)? = null
128+
onOverscroll: ((Boolean) -> Unit)? = null,
129+
isEnabled: () -> Boolean = { platform() == Platform.Android }
125130
): Modifier = composed {
126-
if (!enableOverscroll()) return@composed this
131+
if (!isEnabled()) return@composed this
127132
val onOverscroll by rememberUpdatedState(onOverscroll)
128133
val nestedScrollToParent by rememberUpdatedState(nestedScrollToParent)
129134
val scrollEasing by rememberUpdatedState(scrollEasing ?: DefaultParabolaScrollEasing)
@@ -307,6 +312,4 @@ fun rememberOverscrollFlingBehavior(
307312
}
308313
}
309314
}
310-
}
311-
312-
expect fun enableOverscroll(): Boolean
315+
}

miuix/src/desktopMain/kotlin/top/yukonga/miuix/kmp/utils/Overscroll.desktop.kt

Lines changed: 0 additions & 3 deletions
This file was deleted.

miuix/src/iosMain/kotlin/top/yukonga/miuix/kmp/utils/Overscroll.ios.kt

Lines changed: 0 additions & 3 deletions
This file was deleted.

miuix/src/jsMain/kotlin/top/yukonga/miuix/kmp/utils/Overscroll.js.kt

Lines changed: 0 additions & 3 deletions
This file was deleted.

miuix/src/macosMain/kotlin/top/yukonga/miuix/kmp/utils/Overscroll.macos.kt

Lines changed: 0 additions & 3 deletions
This file was deleted.

miuix/src/wasmJsMain/kotlin/top/yukonga/miuix/kmp/utils/Overscroll.wasmJs.kt

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)