A fully functional Android app built entirely with Kotlin and Jetpack Compose
Add workaround for Activity.reportFullyDrawn
Tomáš Mlynaričb6f262d94cf3
diff --git a/feature-foryou/src/main/java/com/google/samples/apps/nowinandroid/feature/foryou/ForYouScreen.kt b/feature-foryou/src/main/java/com/google/samples/apps/nowinandroid/feature/foryou/ForYouScreen.ktindex 5c3f4962f..185f7e06c 100644--- a/feature-foryou/src/main/java/com/google/samples/apps/nowinandroid/feature/foryou/ForYouScreen.kt+++ b/feature-foryou/src/main/java/com/google/samples/apps/nowinandroid/feature/foryou/ForYouScreen.kt@@ -16,6 +16,7 @@package com.google.samples.apps.nowinandroid.feature.foryou+import android.app.Activityimport android.content.Intentimport android.net.Uriimport androidx.annotation.IntRange@@ -58,6 +59,7 @@ import androidx.compose.material3.windowsizeclass.ExperimentalMaterial3WindowSizimport androidx.compose.material3.windowsizeclass.WindowSizeClassimport androidx.compose.material3.windowsizeclass.WindowWidthSizeClassimport androidx.compose.runtime.Composable+import androidx.compose.runtime.LaunchedEffectimport androidx.compose.runtime.collectAsStateimport androidx.compose.runtime.getValueimport androidx.compose.ui.Alignment@@ -65,6 +67,7 @@ import androidx.compose.ui.Modifierimport androidx.compose.ui.graphics.Colorimport androidx.compose.ui.platform.LocalContextimport androidx.compose.ui.platform.LocalDensity+import androidx.compose.ui.platform.LocalViewimport androidx.compose.ui.platform.testTagimport androidx.compose.ui.res.painterResourceimport androidx.compose.ui.res.stringResource@@ -75,6 +78,7 @@ import androidx.compose.ui.unit.dpimport androidx.compose.ui.unit.maximport androidx.compose.ui.unit.spimport androidx.core.content.ContextCompat+import androidx.core.view.doOnPreDrawimport androidx.hilt.navigation.compose.hiltViewModelimport coil.compose.AsyncImageimport com.google.samples.apps.nowinandroid.core.designsystem.component.NiaFilledButton@@ -161,6 +165,20 @@ fun ForYouScreen(else -> floor(maxWidth / 300.dp).toInt().coerceAtLeast(1)}+ // Workaround to call Activity.reportFullyDrawn from Jetpack Compose.+ // This code should be called when the UI is ready for use and relates to Time To Full Display.+ if (interestsSelectionState !is ForYouInterestsSelectionUiState.Loading && feedState !is ForYouFeedUiState.Loading) {+ val localView = LocalView.current+ // Unit prevents calling it only once on recomposition, but doesn't prevent when the composable goes out of scope.+ // Activity.reportFullyDrawn has inside check to be called only once.+ LaunchedEffect(Unit) {+ // We're leveraging the fact, that the current view is directly set as content of Activity.+ val activity = localView.context as? Activity ?: return@LaunchedEffect+ // To be sure not to call in the middle of a frame draw.+ localView.doOnPreDraw { activity.reportFullyDrawn() }+ }+ }+LazyColumn(modifier = Modifier.fillMaxSize()