A fully functional Android app built entirely with Kotlin and Jetpack Compose
Use ReportDrawnWhen
mlykotom3b7e7e3c028e
diff --git a/feature/foryou/build.gradle.kts b/feature/foryou/build.gradle.ktsindex 4fa032a88..ad50e531b 100644--- a/feature/foryou/build.gradle.kts+++ b/feature/foryou/build.gradle.kts@@ -29,4 +29,5 @@ android {dependencies {implementation(libs.accompanist.flowlayout)implementation(libs.kotlinx.datetime)+ implementation(libs.androidx.activity.compose)}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 fe549b79e..767bede9a 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,7 +16,7 @@package com.google.samples.apps.nowinandroid.feature.foryou-import android.app.Activity+import androidx.activity.compose.ReportDrawnWhenimport androidx.compose.animation.AnimatedVisibilityimport androidx.compose.animation.fadeInimport androidx.compose.animation.fadeOut@@ -57,13 +57,11 @@ import androidx.compose.material3.MaterialThemeimport androidx.compose.material3.Surfaceimport androidx.compose.material3.Textimport androidx.compose.runtime.Composable-import androidx.compose.runtime.LaunchedEffectimport androidx.compose.runtime.getValueimport androidx.compose.ui.Alignmentimport androidx.compose.ui.Modifierimport androidx.compose.ui.layout.layoutimport 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@@ -73,7 +71,6 @@ import androidx.compose.ui.unit.dpimport androidx.compose.ui.unit.maximport androidx.compose.ui.unit.spimport androidx.compose.ui.util.trace-import androidx.core.view.doOnPreDrawimport androidx.hilt.navigation.compose.hiltViewModelimport androidx.lifecycle.compose.collectAsStateWithLifecycleimport com.google.samples.apps.nowinandroid.core.designsystem.component.DynamicAsyncImage@@ -126,23 +123,8 @@ internal fun ForYouScreen(val isOnboardingLoading = onboardingUiState is OnboardingUiState.Loadingval isFeedLoading = feedState is NewsFeedUiState.Loading- // 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.- // TODO replace with ReportDrawnWhen { } once androidx.activity-compose 1.7.0 is used (currently alpha)- if (!isSyncing && !isOnboardingLoading && !isFeedLoading) {- val localView = LocalView.current- // We use Unit to call reportFullyDrawn only on the first recomposition,- // however it will be called again if this composable goes out of scope.- // Activity.reportFullyDrawn() has its own check for this- // and is safe to call multiple times though.- 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() }- }- }+ // This code should be called when the UI is ready for use and relates to Time To Full Display.+ ReportDrawnWhen { !isSyncing && !isOnboardingLoading && !isFeedLoading }val state = rememberLazyGridState()TrackScrollJank(scrollableState = state, stateName = "forYou:feed")diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.tomlindex 8826089a8..c3648e5b6 100644--- a/gradle/libs.versions.toml+++ b/gradle/libs.versions.toml@@ -2,7 +2,7 @@accompanist = "0.28.0"androidDesugarJdkLibs = "1.2.2"androidGradlePlugin = "7.4.1"-androidxActivity = "1.6.1"+androidxActivity = "1.7.0"androidxAppCompat = "1.5.1"androidxBrowser = "1.4.0"androidxComposeBom = "2023.01.00"