Skip to content

Commit 5f10afe

Browse files
committed
Add SnackbarHostState.dismissCurrentSnackbarAndShow & TimeInterpolator.toEasing | Move Modifier.kt to /extensions
1 parent 91d91a6 commit 5f10afe

File tree

4 files changed

+45
-1
lines changed

4 files changed

+45
-1
lines changed

composed/src/main/kotlin/com/w2sv/composed/Modifier.kt renamed to composed/src/main/kotlin/com/w2sv/composed/extensions/Modifier.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.w2sv.composed
1+
package com.w2sv.composed.extensions
22

33
import androidx.compose.ui.Modifier
44

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.w2sv.composed.extensions
2+
3+
import androidx.compose.material3.SnackbarDuration
4+
import androidx.compose.material3.SnackbarHostState
5+
import androidx.compose.material3.SnackbarVisuals
6+
7+
/**
8+
* Dismisses the currently showing snackbar if there is one and shows a new one with the given [snackbarVisuals].
9+
*
10+
* @see SnackbarHostState.showSnackbar
11+
*/
12+
suspend fun SnackbarHostState.dismissCurrentSnackbarAndShow(snackbarVisuals: SnackbarVisuals) {
13+
currentSnackbarData?.dismiss()
14+
showSnackbar(snackbarVisuals)
15+
}
16+
17+
/**
18+
* Dismisses the currently showing snackbar if there is one and shows a new one with the given parameters.
19+
*
20+
* @see SnackbarHostState.showSnackbar
21+
*/
22+
suspend fun SnackbarHostState.dismissCurrentSnackbarAndShow(
23+
message: String,
24+
actionLabel: String? = null,
25+
withDismissAction: Boolean = false,
26+
duration: SnackbarDuration = if (actionLabel == null) SnackbarDuration.Short else SnackbarDuration.Indefinite
27+
) {
28+
currentSnackbarData?.dismiss()
29+
showSnackbar(
30+
message = message,
31+
actionLabel = actionLabel,
32+
withDismissAction = withDismissAction,
33+
duration = duration
34+
)
35+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.w2sv.composed.extensions
2+
3+
import android.animation.TimeInterpolator
4+
import androidx.compose.animation.core.Easing
5+
6+
fun TimeInterpolator.toEasing() = Easing {
7+
getInterpolation(it)
8+
}

composed/src/test/kotlin/com/w2sv/composed/ModifierKtTest.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import androidx.compose.foundation.layout.padding
55
import androidx.compose.ui.Modifier
66
import androidx.compose.ui.graphics.Color
77
import androidx.compose.ui.unit.dp
8+
import com.w2sv.composed.extensions.thenIf
89
import junit.framework.TestCase.assertEquals
910
import org.junit.Test
1011

0 commit comments

Comments
 (0)