-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Android][iOS] Confirmation of credential sent (#74)
This adds a toast component that informs the user when the credential is successfully shared with the verifier and updates the component that handles the QR code to add a new verification method and change how it's listed.
- Loading branch information
1 parent
acb35ae
commit e0ba60a
Showing
8 changed files
with
439 additions
and
274 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
example/src/main/java/com/spruceid/mobilesdkexample/utils/Toast.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
package com.spruceid.mobilesdkexample.utils | ||
|
||
import androidx.compose.foundation.Image | ||
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.border | ||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.height | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.layout.width | ||
import androidx.compose.foundation.layout.wrapContentHeight | ||
import androidx.compose.foundation.shape.RoundedCornerShape | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.LaunchedEffect | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.rememberCoroutineScope | ||
import androidx.compose.runtime.rememberUpdatedState | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.res.painterResource | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.text.font.FontWeight | ||
import androidx.compose.ui.unit.dp | ||
import androidx.compose.ui.unit.sp | ||
import com.spruceid.mobilesdkexample.R | ||
import com.spruceid.mobilesdkexample.ui.theme.ColorEmerald200 | ||
import com.spruceid.mobilesdkexample.ui.theme.ColorEmerald50 | ||
import com.spruceid.mobilesdkexample.ui.theme.ColorEmerald900 | ||
import com.spruceid.mobilesdkexample.ui.theme.Inter | ||
import kotlinx.coroutines.delay | ||
import kotlinx.coroutines.launch | ||
|
||
enum class ToastType { | ||
SUCCESS | ||
} | ||
|
||
object Toast { | ||
private val toastMessage = mutableStateOf<String?>(null) | ||
private val toastType = mutableStateOf(ToastType.SUCCESS) | ||
|
||
fun showSuccess(message: String) { | ||
toastType.value = ToastType.SUCCESS | ||
toastMessage.value = message | ||
} | ||
|
||
@Composable | ||
fun ToastHost( | ||
duration: Long = 3000L, | ||
onDismiss: () -> Unit = { toastMessage.value = null } | ||
) { | ||
val scope = rememberCoroutineScope() | ||
val currentMessage = rememberUpdatedState(toastMessage.value) | ||
|
||
currentMessage.value?.let { message -> | ||
LaunchedEffect(message) { | ||
scope.launch { | ||
delay(duration) | ||
onDismiss() | ||
} | ||
} | ||
when (toastType.value) { | ||
ToastType.SUCCESS -> SuccessToast(message = message) | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
fun SuccessToast( | ||
message: String, | ||
) { | ||
Box( | ||
modifier = Modifier | ||
.wrapContentHeight() | ||
.padding(all = 20.dp) | ||
.padding(top = 20.dp) | ||
.background( | ||
color = ColorEmerald50, | ||
shape = RoundedCornerShape(6.dp) | ||
) | ||
.border( | ||
width = 1.dp, | ||
color = ColorEmerald200, | ||
shape = RoundedCornerShape(6.dp) | ||
) | ||
) { | ||
Row( | ||
verticalAlignment = Alignment.CenterVertically, | ||
horizontalArrangement = Arrangement.Center, | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
.padding(vertical = 8.dp) | ||
) { | ||
Image( | ||
painter = painterResource(id = R.drawable.success_toast_icon), | ||
contentDescription = stringResource(id = R.string.success_toast_icon), | ||
modifier = Modifier | ||
.width(20.dp) | ||
.height(20.dp) | ||
) | ||
Text( | ||
text = message, | ||
color = ColorEmerald900, | ||
fontFamily = Inter, | ||
fontWeight = FontWeight.Normal, | ||
fontSize = 15.sp, | ||
modifier = Modifier.padding(start = 10.dp) | ||
) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.