@@ -124,95 +124,93 @@ fun ForYouScreen(
124124 onNewsResourcesCheckedChanged : (String , Boolean ) -> Unit ,
125125 modifier : Modifier = Modifier ,
126126) {
127- NiaGradientBackground {
128- Scaffold (
129- topBar = {
130- NiaTopAppBar (
131- titleRes = R .string.top_app_bar_title,
132- actionIcon = NiaIcons .AccountCircle ,
133- actionIconContentDescription = stringResource(
134- id = R .string.for_you_top_app_bar_action_my_account
135- ),
136- colors = TopAppBarDefaults .centerAlignedTopAppBarColors(
137- containerColor = Color .Transparent
138- )
127+ Scaffold (
128+ topBar = {
129+ NiaTopAppBar (
130+ titleRes = R .string.top_app_bar_title,
131+ actionIcon = NiaIcons .AccountCircle ,
132+ actionIconContentDescription = stringResource(
133+ id = R .string.for_you_top_app_bar_action_my_account
134+ ),
135+ colors = TopAppBarDefaults .centerAlignedTopAppBarColors(
136+ containerColor = Color .Transparent
139137 )
140- },
141- containerColor = Color .Transparent ,
142- contentWindowInsets = WindowInsets (0 , 0 , 0 , 0 )
143- ) { innerPadding ->
144- // Workaround to call Activity.reportFullyDrawn from Jetpack Compose.
145- // This code should be called when the UI is ready for use
146- // and relates to Time To Full Display.
147- val interestsLoaded =
148- interestsSelectionState !is ForYouInterestsSelectionUiState .Loading
149- val feedLoaded = feedState !is NewsFeedUiState .Loading
138+ )
139+ },
140+ containerColor = Color .Transparent ,
141+ contentWindowInsets = WindowInsets (0 , 0 , 0 , 0 )
142+ ) { innerPadding ->
143+ // Workaround to call Activity.reportFullyDrawn from Jetpack Compose.
144+ // This code should be called when the UI is ready for use
145+ // and relates to Time To Full Display.
146+ val interestsLoaded =
147+ interestsSelectionState !is ForYouInterestsSelectionUiState .Loading
148+ val feedLoaded = feedState !is NewsFeedUiState .Loading
150149
151- if (interestsLoaded && feedLoaded) {
152- val localView = LocalView .current
153- // We use Unit to call reportFullyDrawn only on the first recomposition,
154- // however it will be called again if this composable goes out of scope.
155- // Activity.reportFullyDrawn() has its own check for this
156- // and is safe to call multiple times though.
157- LaunchedEffect (Unit ) {
158- // We're leveraging the fact, that the current view is directly set as content of Activity.
159- val activity = localView.context as ? Activity ? : return @LaunchedEffect
160- // To be sure not to call in the middle of a frame draw.
161- localView.doOnPreDraw { activity.reportFullyDrawn() }
162- }
150+ if (interestsLoaded && feedLoaded) {
151+ val localView = LocalView .current
152+ // We use Unit to call reportFullyDrawn only on the first recomposition,
153+ // however it will be called again if this composable goes out of scope.
154+ // Activity.reportFullyDrawn() has its own check for this
155+ // and is safe to call multiple times though.
156+ LaunchedEffect (Unit ) {
157+ // We're leveraging the fact, that the current view is directly set as content of Activity.
158+ val activity = localView.context as ? Activity ? : return @LaunchedEffect
159+ // To be sure not to call in the middle of a frame draw.
160+ localView.doOnPreDraw { activity.reportFullyDrawn() }
163161 }
162+ }
164163
165- val tag = " forYou:feed"
164+ val tag = " forYou:feed"
166165
167- val lazyGridState = rememberLazyGridState()
168- TrackScrollJank (scrollableState = lazyGridState, stateName = tag)
166+ val lazyGridState = rememberLazyGridState()
167+ TrackScrollJank (scrollableState = lazyGridState, stateName = tag)
169168
170- LazyVerticalGrid (
171- columns = Adaptive (300 .dp),
172- contentPadding = PaddingValues (16 .dp),
173- horizontalArrangement = Arrangement .spacedBy(16 .dp),
174- verticalArrangement = Arrangement .spacedBy(24 .dp),
175- modifier = modifier
176- .padding(innerPadding)
177- .consumedWindowInsets(innerPadding)
178- .fillMaxSize()
179- .testTag(" forYou:feed" ),
180- state = lazyGridState
181- ) {
182- interestsSelection(
183- interestsSelectionState = interestsSelectionState,
184- onAuthorCheckedChanged = onAuthorCheckedChanged,
185- onTopicCheckedChanged = onTopicCheckedChanged,
186- saveFollowedTopics = saveFollowedTopics,
187- // Custom LayoutModifier to remove the enforced parent 16.dp contentPadding
188- // from the LazyVerticalGrid and enable edge-to-edge scrolling for this section
189- interestsItemModifier = Modifier .layout { measurable, constraints ->
190- val placeable = measurable.measure(
191- constraints.copy(
192- maxWidth = constraints.maxWidth + 32 .dp.roundToPx()
193- )
169+ LazyVerticalGrid (
170+ columns = Adaptive (300 .dp),
171+ contentPadding = PaddingValues (16 .dp),
172+ horizontalArrangement = Arrangement .spacedBy(16 .dp),
173+ verticalArrangement = Arrangement .spacedBy(24 .dp),
174+ modifier = modifier
175+ .padding(innerPadding)
176+ .consumedWindowInsets(innerPadding)
177+ .fillMaxSize()
178+ .testTag(" forYou:feed" ),
179+ state = lazyGridState
180+ ) {
181+ interestsSelection(
182+ interestsSelectionState = interestsSelectionState,
183+ onAuthorCheckedChanged = onAuthorCheckedChanged,
184+ onTopicCheckedChanged = onTopicCheckedChanged,
185+ saveFollowedTopics = saveFollowedTopics,
186+ // Custom LayoutModifier to remove the enforced parent 16.dp contentPadding
187+ // from the LazyVerticalGrid and enable edge-to-edge scrolling for this section
188+ interestsItemModifier = Modifier .layout { measurable, constraints ->
189+ val placeable = measurable.measure(
190+ constraints.copy(
191+ maxWidth = constraints.maxWidth + 32 .dp.roundToPx()
194192 )
195- layout(placeable.width, placeable.height) {
196- placeable.place( 0 , 0 )
197- }
193+ )
194+ layout( placeable.width, placeable.height) {
195+ placeable.place( 0 , 0 )
198196 }
199- )
197+ }
198+ )
200199
201- newsFeed(
202- feedState = feedState,
203- // Avoid showing a second loading wheel if we already are for the interests
204- // selection
205- showLoadingUIIfLoading =
206- interestsSelectionState !is ForYouInterestsSelectionUiState .Loading ,
207- onNewsResourcesCheckedChanged = onNewsResourcesCheckedChanged,
208- loadingContentDescription = R .string.for_you_loading
209- )
200+ newsFeed(
201+ feedState = feedState,
202+ // Avoid showing a second loading wheel if we already are for the interests
203+ // selection
204+ showLoadingUIIfLoading =
205+ interestsSelectionState !is ForYouInterestsSelectionUiState .Loading ,
206+ onNewsResourcesCheckedChanged = onNewsResourcesCheckedChanged,
207+ loadingContentDescription = R .string.for_you_loading
208+ )
210209
211- item(span = { GridItemSpan (maxLineSpan) }) {
212- Column {
213- Spacer (modifier = Modifier .height(8 .dp))
214- Spacer (Modifier .windowInsetsBottomHeight(WindowInsets .safeDrawing))
215- }
210+ item(span = { GridItemSpan (maxLineSpan) }) {
211+ Column {
212+ Spacer (modifier = Modifier .height(8 .dp))
213+ Spacer (Modifier .windowInsetsBottomHeight(WindowInsets .safeDrawing))
216214 }
217215 }
218216 }
0 commit comments