1616
1717package com.google.samples.apps.nowinandroid.feature.foryou
1818
19- import android.app.Activity
19+ import androidx.activity.compose.ReportDrawnWhen
2020import androidx.compose.animation.AnimatedVisibility
2121import androidx.compose.animation.fadeIn
2222import androidx.compose.animation.fadeOut
@@ -57,13 +57,11 @@ import androidx.compose.material3.MaterialTheme
5757import androidx.compose.material3.Surface
5858import androidx.compose.material3.Text
5959import androidx.compose.runtime.Composable
60- import androidx.compose.runtime.LaunchedEffect
6160import androidx.compose.runtime.getValue
6261import androidx.compose.ui.Alignment
6362import androidx.compose.ui.Modifier
6463import androidx.compose.ui.layout.layout
6564import androidx.compose.ui.platform.LocalDensity
66- import androidx.compose.ui.platform.LocalView
6765import androidx.compose.ui.platform.testTag
6866import androidx.compose.ui.res.painterResource
6967import androidx.compose.ui.res.stringResource
@@ -73,7 +71,6 @@ import androidx.compose.ui.unit.dp
7371import androidx.compose.ui.unit.max
7472import androidx.compose.ui.unit.sp
7573import androidx.compose.ui.util.trace
76- import androidx.core.view.doOnPreDraw
7774import androidx.hilt.navigation.compose.hiltViewModel
7875import androidx.lifecycle.compose.collectAsStateWithLifecycle
7976import com.google.samples.apps.nowinandroid.core.designsystem.component.DynamicAsyncImage
@@ -126,23 +123,8 @@ internal fun ForYouScreen(
126123 val isOnboardingLoading = onboardingUiState is OnboardingUiState .Loading
127124 val isFeedLoading = feedState is NewsFeedUiState .Loading
128125
129- // Workaround to call Activity.reportFullyDrawn from Jetpack Compose.
130- // This code should be called when the UI is ready for use
131- // and relates to Time To Full Display.
132- // TODO replace with ReportDrawnWhen { } once androidx.activity-compose 1.7.0 is used (currently alpha)
133- if (! isSyncing && ! isOnboardingLoading && ! isFeedLoading) {
134- val localView = LocalView .current
135- // We use Unit to call reportFullyDrawn only on the first recomposition,
136- // however it will be called again if this composable goes out of scope.
137- // Activity.reportFullyDrawn() has its own check for this
138- // and is safe to call multiple times though.
139- LaunchedEffect (Unit ) {
140- // We're leveraging the fact, that the current view is directly set as content of Activity.
141- val activity = localView.context as ? Activity ? : return @LaunchedEffect
142- // To be sure not to call in the middle of a frame draw.
143- localView.doOnPreDraw { activity.reportFullyDrawn() }
144- }
145- }
126+ // This code should be called when the UI is ready for use and relates to Time To Full Display.
127+ ReportDrawnWhen { ! isSyncing && ! isOnboardingLoading && ! isFeedLoading }
146128
147129 val state = rememberLazyGridState()
148130 TrackScrollJank (scrollableState = state, stateName = " forYou:feed" )
0 commit comments