Skip to content

Commit bb496b0

Browse files
authored
Merge pull request #7 from dokar3/v0.1.2
V0.1.2
2 parents b947719 + 48d237c commit bb496b0

File tree

6 files changed

+18
-12
lines changed

6 files changed

+18
-12
lines changed

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,10 @@ BottomSheet(state = state) {
8787

8888
**Skip peek state**
8989

90-
To skip peek state, set `peekHeight` to a value at least equal to the content height, eg. `PeekHeight.px(Int.MAX_VALUE)`, `PeekHeight.fraction(1f)`:
91-
9290
```kotlin
9391
BottomSheet(
9492
state = state,
95-
peekHeight = PeekHeight.fraction(1f),
93+
skipPeek = true,
9694
) {
9795
...
9896
}

build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ buildscript {
2121

2222
allprojects {
2323
plugins.withId("com.vanniktech.maven.publish") {
24+
mavenPublish {
25+
androidVariantToPublish = "release"
26+
}
2427
mavenPublishing {
2528
publishToMavenCentral("S01")
2629
signAllPublications()

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ android.enableJetifier=false
2020
# Kotlin code style for this project: "official" or "obsolete":
2121
kotlin.code.style=official
2222

23-
VERSION_NAME=0.1.1
23+
VERSION_NAME=0.1.2
2424
GROUP=io.github.dokar3
2525

2626
POM_NAME=sheets

sample/src/main/java/com/dokar/sheets/sample/MainActivity.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ class MainActivity : ComponentActivity() {
5555
}
5656
}
5757

58-
@Suppress("deprecation")
5958
@Composable
6059
fun App() {
6160
var dark by remember { mutableStateOf(false) }
@@ -149,7 +148,7 @@ fun SimpleBottomSheet(
149148
BottomSheet(
150149
state = state,
151150
modifier = modifier,
152-
peekHeight = PeekHeight.px(Int.MAX_VALUE),
151+
skipPeek = true,
153152
) {
154153
SimpleSheetContent(state)
155154
}
@@ -206,7 +205,7 @@ private fun TextFieldBottomSheet(
206205
BottomSheet(
207206
state = state,
208207
modifier = modifier,
209-
peekHeight = PeekHeight.fraction(1f),
208+
skipPeek = true,
210209
) {
211210
TextFieldSheetContent(state = state)
212211
}
@@ -221,7 +220,7 @@ private fun EmbeddedBottomSheet(
221220
BottomSheetLayout(
222221
state = state,
223222
modifier = modifier,
224-
peekHeight = PeekHeight.fraction(1f),
223+
skipPeek = true,
225224
) {
226225
Box(
227226
modifier = Modifier

sheets/src/main/java/com/dokar/sheets/BottomSheet.kt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,8 @@ import kotlin.math.min
5353
*
5454
* @param state The bottom sheet state. Call [rememberBottomSheetState] to create one.
5555
* @param modifier Modifier for bottom sheet content.
56-
* @param peekHeight Peek height, could be a dp, px, or fraction value. To skip the peek state,
57-
* set the peek height to a value at least equal to the content height, e.g, PeekHeight.fraction(1f),
58-
* PeekHeight.px(Int.MAX_VALUE). Defaults to PeekHeight.fraction(0.5f).
56+
* @param skipPeek Skip the peek state if set to true. Defaults to false.
57+
* @param peekHeight Peek height, could be a dp, px, or fraction value.
5958
* @param backgroundColor Background color for sheet content.
6059
* @param dimColor Dim color. Defaults to [Color.Black].
6160
* @param maxDimAmount Maximum dim amount. Defaults to 0.45f.
@@ -67,6 +66,7 @@ import kotlin.math.min
6766
fun BottomSheet(
6867
state: BottomSheetState,
6968
modifier: Modifier = Modifier,
69+
skipPeek: Boolean = false,
7070
peekHeight: PeekHeight = PeekHeight.fraction(0.5f),
7171
shape: Shape = MaterialTheme.shapes.medium.copy(
7272
bottomStart = CornerSize(0.dp),
@@ -87,6 +87,7 @@ fun BottomSheet(
8787
val scope = rememberCoroutineScope()
8888

8989
val currentState by rememberUpdatedState(state)
90+
val currentSkipPeek by rememberUpdatedState(skipPeek)
9091
val currentPeekHeight by rememberUpdatedState(peekHeight)
9192
val currentShape by rememberUpdatedState(shape)
9293
val currentBackgroundColor by rememberUpdatedState(backgroundColor)
@@ -120,6 +121,7 @@ fun BottomSheet(
120121
BottomSheetLayout(
121122
state = currentState,
122123
modifier = modifier,
124+
skipPeek = currentSkipPeek,
123125
peekHeight = currentPeekHeight,
124126
shape = currentShape,
125127
backgroundColor = currentBackgroundColor,
@@ -156,6 +158,7 @@ fun BottomSheet(
156158
fun BottomSheetLayout(
157159
state: BottomSheetState,
158160
modifier: Modifier = Modifier,
161+
skipPeek: Boolean = false,
159162
peekHeight: PeekHeight = PeekHeight.fraction(0.5f),
160163
shape: Shape = MaterialTheme.shapes.medium.copy(
161164
bottomStart = CornerSize(0.dp),
@@ -184,6 +187,7 @@ fun BottomSheetLayout(
184187

185188
SideEffect {
186189
state.peekHeight = peekHeight
190+
state.forceSkipPeek = skipPeek
187191
state.maxDimAmount = maxDimAmount
188192
}
189193

sheets/src/main/java/com/dokar/sheets/BottomSheetState.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ class BottomSheetState(
7676

7777
internal lateinit var peekHeight: PeekHeight
7878

79+
internal var forceSkipPeek: Boolean = false
80+
7981
private var pendingToStartAnimation = false
8082

8183
internal val isAnimating: Boolean
@@ -370,7 +372,7 @@ class BottomSheetState(
370372
if (contentHeight == 0 || !::peekHeight.isInitialized) {
371373
return false
372374
}
373-
return getPeekHeightInPx() >= contentHeight
375+
return forceSkipPeek || getPeekHeightInPx() >= contentHeight
374376
}
375377

376378
internal fun getPeekHeightInPx(): Float {

0 commit comments

Comments
 (0)