Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Loading Screen #43

Merged
merged 3 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions example/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ dependencies {
implementation("androidx.compose.material3:material3")
implementation("androidx.navigation:navigation-compose:2.7.7")
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.8.4")
implementation("app.rive:rive-android:8.7.0")
implementation("androidx.startup:startup-runtime:1.1.1")
implementation(project(mapOf("path" to ":MobileSdk")))
implementation("com.google.zxing:core:3.5.1")
implementation("io.ktor:ktor-client-core:2.3.12")
Expand Down
8 changes: 8 additions & 0 deletions example/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@
<data android:scheme="openid4vp" />
</intent-filter>
</activity>
<provider
android:name="androidx.startup.InitializationProvider"
android:authorities="${applicationId}.androidx-startup"
android:exported="false"
tools:node="merge">
<meta-data android:name="app.rive.runtime.kotlin.RiveInitializer"
android:value="androidx.startup" />
</provider>
</application>

</manifest>
90 changes: 90 additions & 0 deletions example/src/main/java/com/spruceid/mobilesdkexample/LoadingView.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package com.spruceid.mobilesdkexample

import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.compose.ui.viewinterop.AndroidView
import app.rive.runtime.kotlin.RiveAnimationView
import app.rive.runtime.kotlin.core.ExperimentalAssetLoader
import com.spruceid.mobilesdkexample.ui.theme.CodeBorder
import com.spruceid.mobilesdkexample.ui.theme.ColorBase800
import com.spruceid.mobilesdkexample.ui.theme.Inter

@OptIn(ExperimentalAssetLoader::class)
@Composable
fun LoadingView(
loadingText: String,
cancelButtonLabel: String = "Cancel",
onCancel: (() -> Unit)? = null
) {
Box(modifier = Modifier.fillMaxSize()) {
Column(
modifier = Modifier.fillMaxSize(),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center
) {
AndroidView(
modifier = Modifier.size(60.dp),
factory = { context ->
RiveAnimationView(context).also {
it.setRiveResource(
resId = R.raw.loading_spinner,
)
}
}
)
Text(
text = loadingText,
fontFamily = Inter,
fontWeight = FontWeight.Normal,
color = ColorBase800,
fontSize = 20.sp,
modifier = Modifier.padding(top = 10.dp)
)
}
if (onCancel != null) {
Column(
modifier = Modifier.fillMaxSize(),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Bottom
) {
Button(
onClick = {
onCancel()
},
shape = RoundedCornerShape(5.dp),
colors = ButtonDefaults.buttonColors(
containerColor = Color.Transparent,
contentColor = Color.Black,
),
border = BorderStroke(1.dp, CodeBorder),
modifier = Modifier
.fillMaxWidth()
) {
Text(
text = cancelButtonLabel,
fontFamily = Inter,
fontWeight = FontWeight.SemiBold,
color = Color.Black,
)
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ val VerifierRequestBadgeFieldFill = Color(0xFFF7F5F0)
val VerifierRequestBadgeFieldText = Color(0xFF0C0A09)
val VerifiedGreenValid = Color(0xFF047857)
val VerifiedRedInvalid = Color(0xFFBE123C)
val VerifierCloseButton = Color(0xFF44403C)
val VerifierCloseButton = Color(0xFF44403C)
val ColorBase800 = Color(0xFF75675C)
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import com.spruceid.mobile.sdk.rs.HttpResponse
import com.spruceid.mobile.sdk.rs.Oid4vci
import com.spruceid.mobile.sdk.rs.generatePopComplete
import com.spruceid.mobile.sdk.rs.generatePopPrepare
import com.spruceid.mobilesdkexample.LoadingView
import com.spruceid.mobilesdkexample.R
import com.spruceid.mobilesdkexample.ScanningComponent
import com.spruceid.mobilesdkexample.ScanningType
Expand Down Expand Up @@ -145,13 +146,7 @@ fun OID4VCIView(
}

if (loading) {
Column(
modifier = Modifier.fillMaxSize(),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
) {
Text("Loading...")
}
LoadingView(loadingText = "Loading...")
} else if (err != null) {
Column(
modifier = Modifier.fillMaxSize(),
Expand Down
Binary file added example/src/main/res/raw/loading_spinner.riv
Binary file not shown.
1 change: 1 addition & 0 deletions example/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@
<color name="spruce_blue">#FF2F6AE1</color>
<color name="secondary_button_red">#FFE11D48</color>
<color name="cta_button_green">#FF087455</color>
<color name="color_base_800">#FF75675C</color>
</resources>
Loading