@@ -44,6 +44,11 @@ import androidx.compose.ui.res.stringResource
4444import androidx.compose.ui.tooling.preview.Preview
4545import androidx.compose.ui.unit.IntOffset
4646import androidx.compose.ui.unit.dp
47+ import dev.chrisbanes.haze.HazeState
48+ import dev.chrisbanes.haze.hazeEffect
49+ import dev.chrisbanes.haze.materials.CupertinoMaterials
50+ import dev.chrisbanes.haze.materials.ExperimentalHazeMaterialsApi
51+ import dev.chrisbanes.haze.rememberHazeState
4752import kotlinx.coroutines.launch
4853import to.bitkit.R
4954import to.bitkit.models.Toast
@@ -52,10 +57,12 @@ import to.bitkit.ui.theme.AppThemeSurface
5257import to.bitkit.ui.theme.Colors
5358import kotlin.math.roundToInt
5459
60+ @OptIn(ExperimentalHazeMaterialsApi ::class )
5561@Composable
5662fun ToastView (
5763 toast : Toast ,
5864 onDismiss : () -> Unit ,
65+ hazeState : HazeState = rememberHazeState(blurEnabled = true),
5966 onDragStart : () -> Unit = {},
6067 onDragEnd : () -> Unit = {},
6168) {
@@ -74,6 +81,11 @@ fun ToastView(
7481 .then(toast.testTag?.let { Modifier .testTag(it) } ? : Modifier ),
7582 ) {
7683 // Main toast content
84+ val backgroundAlpha = 0.7f
85+ val toastMaterial = CupertinoMaterials .ultraThin(
86+ containerColor = MaterialTheme .colorScheme.surface.copy(alpha = backgroundAlpha)
87+ )
88+
7789 Box (
7890 modifier = Modifier
7991 .fillMaxWidth()
@@ -85,9 +97,15 @@ fun ToastView(
8597 spotColor = Color .Black .copy(alpha = 0.4f )
8698 )
8799 .background(
88- color = MaterialTheme .colorScheme.surface.copy(alpha = 0.85f ),
100+ color = MaterialTheme .colorScheme.surface.copy(alpha = backgroundAlpha ),
89101 shape = MaterialTheme .shapes.medium
90102 )
103+ .then(
104+ Modifier .hazeEffect(
105+ state = hazeState,
106+ style = toastMaterial
107+ )
108+ )
91109 .background(
92110 color = tintColor.copy(alpha = 0.32f ),
93111 shape = MaterialTheme .shapes.medium
@@ -207,6 +225,7 @@ fun ToastView(
207225@Composable
208226private fun ToastHost (
209227 toast : Toast ? ,
228+ hazeState : HazeState ,
210229 onDismiss : () -> Unit ,
211230 onDragStart : () -> Unit = {},
212231 onDragEnd : () -> Unit = {},
@@ -225,6 +244,7 @@ private fun ToastHost(
225244 ToastView (
226245 toast = it,
227246 onDismiss = onDismiss,
247+ hazeState = hazeState,
228248 onDragStart = onDragStart,
229249 onDragEnd = onDragEnd
230250 )
@@ -236,6 +256,7 @@ private fun ToastHost(
236256fun ToastOverlay (
237257 toast : Toast ? ,
238258 modifier : Modifier = Modifier ,
259+ hazeState : HazeState = rememberHazeState(blurEnabled = true),
239260 onDismiss : () -> Unit ,
240261 onDragStart : () -> Unit = {},
241262 onDragEnd : () -> Unit = {},
@@ -246,6 +267,7 @@ fun ToastOverlay(
246267 ) {
247268 ToastHost (
248269 toast = toast,
270+ hazeState = hazeState,
249271 onDismiss = onDismiss,
250272 onDragStart = onDragStart,
251273 onDragEnd = onDragEnd
@@ -264,11 +286,11 @@ private fun ToastViewPreview() {
264286 ToastView (
265287 toast = Toast (
266288 type = Toast .ToastType .WARNING ,
267- title = " You’ re still offline" ,
289+ title = " You' re still offline" ,
268290 description = " Check your connection to keep using Bitkit." ,
269291 autoHide = true ,
270292 ),
271- onDismiss = {}
293+ onDismiss = {},
272294 )
273295 ToastView (
274296 toast = Toast (
@@ -277,16 +299,16 @@ private fun ToastViewPreview() {
277299 description = " You can now pay anyone, anywhere, instantly." ,
278300 autoHide = true ,
279301 ),
280- onDismiss = {}
302+ onDismiss = {},
281303 )
282304 ToastView (
283305 toast = Toast (
284306 type = Toast .ToastType .SUCCESS ,
285- title = " You’ re Back Online!" ,
307+ title = " You' re Back Online!" ,
286308 description = " Successfully reconnected to the Internet." ,
287309 autoHide = true ,
288310 ),
289- onDismiss = {}
311+ onDismiss = {},
290312 )
291313 ToastView (
292314 toast = Toast (
@@ -295,7 +317,7 @@ private fun ToastViewPreview() {
295317 description = " Used for neutral content to inform the user." ,
296318 autoHide = false ,
297319 ),
298- onDismiss = {}
320+ onDismiss = {},
299321 )
300322 ToastView (
301323 toast = Toast (
@@ -304,7 +326,7 @@ private fun ToastViewPreview() {
304326 description = " This is a toast message." ,
305327 autoHide = true ,
306328 ),
307- onDismiss = {}
329+ onDismiss = {},
308330 )
309331 }
310332 }
0 commit comments