Skip to content

Commit 6406909

Browse files
authored
Merge pull request #899 from tunjid/tj/centralize-splash
Centralize splash screen logic
2 parents e7ee371 + aa5af26 commit 6406909

File tree

4 files changed

+26
-77
lines changed

4 files changed

+26
-77
lines changed

composeApp/src/androidMain/res/animator/splash_heron_body_animation.xml

Lines changed: 0 additions & 25 deletions
This file was deleted.

composeApp/src/androidMain/res/animator/splash_heron_head_animation.xml

Lines changed: 0 additions & 24 deletions
This file was deleted.

composeApp/src/androidMain/res/drawable/ic_splash_icon.xml

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,4 @@
33
android:width="288dp"
44
android:height="288dp"
55
android:viewportWidth="35"
6-
android:viewportHeight="48">
7-
<target
8-
android:name="head"
9-
android:animation="@animator/splash_heron_head_animation" />
10-
<target
11-
android:name="beak"
12-
android:animation="@animator/splash_heron_body_animation" />
13-
<target
14-
android:name="torso"
15-
android:animation="@animator/splash_heron_body_animation" />
16-
<target
17-
android:name="feet"
18-
android:animation="@animator/splash_heron_body_animation" />
19-
</animated-vector>
6+
android:viewportHeight="48"/>

scaffold/src/commonMain/kotlin/com/tunjid/heron/scaffold/navigation/NavigationMutator.kt

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,12 @@ import heron.scaffold.generated.resources.messages
7272
import heron.scaffold.generated.resources.notifications
7373
import heron.scaffold.generated.resources.search
7474
import heron.scaffold.generated.resources.splash
75+
import kotlin.time.Duration.Companion.seconds
76+
import kotlin.time.TimeSource
7577
import kotlin.uuid.ExperimentalUuidApi
7678
import kotlin.uuid.Uuid
7779
import kotlinx.coroutines.CoroutineScope
80+
import kotlinx.coroutines.delay
7881
import kotlinx.coroutines.flow.Flow
7982
import kotlinx.coroutines.flow.SharingStarted
8083
import kotlinx.coroutines.flow.StateFlow
@@ -85,6 +88,7 @@ import kotlinx.coroutines.flow.filter
8588
import kotlinx.coroutines.flow.first
8689
import kotlinx.coroutines.flow.flatMapLatest
8790
import kotlinx.coroutines.flow.flow
91+
import kotlinx.coroutines.flow.merge
8892
import kotlinx.coroutines.flow.onEach
8993
import kotlinx.coroutines.launch
9094
import org.jetbrains.compose.resources.StringResource
@@ -439,14 +443,10 @@ class PersistedNavigationStateHolder(
439443
ActionStateMutator<NavigationMutation, StateFlow<MultiStackNav>> by appMainScope.actionStateFlowMutator(
440444
initialState = InitialNavigationState,
441445
started = SharingStarted.Eagerly,
442-
inputs = listOf(
443-
forceSignOutMutations(
444-
authRepository = authRepository,
445-
userDataRepository = userDataRepository,
446-
),
447-
),
448446
actionTransform = { navActions ->
449447
flow {
448+
val startTime = TimeSource.Monotonic.markNow()
449+
450450
// Restore saved nav from disk first
451451
val savedNavigation = userDataRepository.navigation
452452
// Wait for a non empty saved state to be read
@@ -466,17 +466,26 @@ class PersistedNavigationStateHolder(
466466
}
467467
}
468468

469+
val elapsed = startTime.elapsedNow()
470+
if (elapsed < SplashDelay) delay(SplashDelay - elapsed)
471+
469472
emit { multiStackNav }
470473

471474
emitAll(
472-
navActions.mapToMutation { navMutation ->
473-
navMutation(
474-
ImmutableNavigationContext(
475-
state = this,
476-
routeParser = routeParser,
477-
),
478-
)
479-
},
475+
merge(
476+
navActions.mapToMutation { navMutation ->
477+
navMutation(
478+
ImmutableNavigationContext(
479+
state = this,
480+
routeParser = routeParser,
481+
),
482+
)
483+
},
484+
forceSignOutMutations(
485+
authRepository = authRepository,
486+
userDataRepository = userDataRepository,
487+
),
488+
),
480489
)
481490
}
482491
},
@@ -661,5 +670,7 @@ private fun AppStack.toStackNav() = StackNav(
661670
children = listOf(rootRoute),
662671
)
663672

673+
private val SplashDelay = 1.seconds
674+
664675
private const val ReferringRouteQueryParam = "referringRoute"
665676
private const val OAuthUrlPathSegment = "oauth"

0 commit comments

Comments
 (0)