ui: scaffold owns the loading spinner, lint mandates it
- Commit
945dc33a279209d4274918cd942c6a2fff3d50af- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-22 23:37 UTC (13 days ago)
- Parents
0e2d545
AppScaffold gains isLoading (+ optional loadingMessage), forwarded through Detail/Setup/LazyList scaffolds; while loading the content lambda is not composed at all and the canonical indicator renders centred in the padded content area - no premature empty states under a spinner. New fatal lint detector ScaffoldLoading (14th repo check) flags whole-content hand-rolled indicators inside AppScaffold content; the SCAFFOLD LOADING EXCEPTION marker covers legitimate local spinners (buttons, sections, determinate progress). Migrated: appstore browse/updates, email list/viewer, emergency view-info, euicc profile, screentime dashboard, fooddelivery home/restaurant/deals/orders/tracking/ verification. Local-sized and section spinners stay inline by design. Verified: library/ui tests, lint-rules tests, lintVitalRelease on migrated apps.
Diff
appstore/src/main/java/com/vayunmathur/appstore/platform/AppStoreUiContract.kt
diff --git a/appstore/src/main/java/com/vayunmathur/appstore/platform/AppStoreUiContract.kt b/appstore/src/main/java/com/vayunmathur/appstore/platform/AppStoreUiContract.ktindex b47eb470ba..ad461f1db0 100644--- a/appstore/src/main/java/com/vayunmathur/appstore/platform/AppStoreUiContract.kt+++ b/appstore/src/main/java/com/vayunmathur/appstore/platform/AppStoreUiContract.kt@@ -157,6 +157,8 @@ data class LibraryUiState( val filter: SourceFilter = SourceFilter.ALL, val counts: Map<SourceFilter, Int> = emptyMap(), val installedIcons: Map<String, Drawable> = emptyMap(),+ /** False until the first installed-apps sweep lands, so an empty library can show a spinner. */+ val hasLoaded: Boolean = false, ) /**
appstore/src/main/java/com/vayunmathur/appstore/platform/AppStoreViewModel.kt
diff --git a/appstore/src/main/java/com/vayunmathur/appstore/platform/AppStoreViewModel.kt b/appstore/src/main/java/com/vayunmathur/appstore/platform/AppStoreViewModel.ktindex de6137a949..6c8329b712 100644--- a/appstore/src/main/java/com/vayunmathur/appstore/platform/AppStoreViewModel.kt+++ b/appstore/src/main/java/com/vayunmathur/appstore/platform/AppStoreViewModel.kt@@ -47,6 +47,7 @@ import kotlinx.coroutines.delay import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.StateFlow+import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.stateIn import kotlinx.coroutines.launch@@ -155,6 +156,11 @@ class AppStoreViewModel( private val libraryFilterFlow = MutableStateFlow(SourceFilter.ALL) + private val _hasLoadedLibrary = MutableStateFlow(false)++ /** Flips true once the first installed-apps sweep lands; the library starts empty. */+ val hasLoadedLibrary: StateFlow<Boolean> = _hasLoadedLibrary.asStateFlow()+ /** * Installed packages Play confirmed it actually hosts. *@@ -368,7 +374,8 @@ class AppStoreViewModel( ) { index, playPackages, accrescentPackages, filter, enabled -> LibraryInputs(index, playPackages, accrescentPackages, filter, enabled) },- ) { rows, inputs ->+ _hasLoadedLibrary,+ ) { rows, inputs, hasLoaded -> // Source attribution, highest priority first: // 1. Whatever the offline catalogue (F-Droid / Modern Apps / Proprietary) recorded. // 2. Accrescent, for packages its signed allowlist vouches for.@@ -395,6 +402,7 @@ class AppStoreViewModel( sourceOf(info.packageName)?.let { info.toUnifiedApp(it) } } LibraryUiState(+ hasLoaded = hasLoaded, apps = all.filter { inputs.filter.source == null || it.source == inputs.filter.source }, filter = inputs.filter, counts = SourceFilter.entries.associateWith { f ->@@ -424,6 +432,7 @@ class AppStoreViewModel( // every restart and keep feeding search, updates and the library (#845). catalog.purgeDisabled(enabled) installedRepo.refresh()+ _hasLoadedLibrary.value = true if (AppSource.PLAYSTORE in enabled) play.restore() loadHome(enabled) refreshPlayInstalledPackages(enabled)@@ -464,6 +473,7 @@ class AppStoreViewModel( fun refreshInstalled() { viewModelScope.launch { installedRepo.refresh()+ _hasLoadedLibrary.value = true refreshPlayInstalledPackages() } }
appstore/src/main/java/com/vayunmathur/appstore/ui/BrowseScreen.kt
diff --git a/appstore/src/main/java/com/vayunmathur/appstore/ui/BrowseScreen.kt b/appstore/src/main/java/com/vayunmathur/appstore/ui/BrowseScreen.ktindex a0f85fbccf..08714b6fcb 100644--- a/appstore/src/main/java/com/vayunmathur/appstore/ui/BrowseScreen.kt+++ b/appstore/src/main/java/com/vayunmathur/appstore/ui/BrowseScreen.kt@@ -3,7 +3,6 @@ import com.vayunmathur.appstore.R import com.vayunmathur.appstore.platform.BrowseUiState import com.vayunmathur.appstore.platform.loadBrowse-import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.padding@@ -13,7 +12,6 @@ import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue-import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp@@ -21,7 +19,6 @@ import com.vayunmathur.appstore.data.UnifiedApp import com.vayunmathur.appstore.platform.AppStoreViewModel import com.vayunmathur.library.ui.AppBarAlignment import com.vayunmathur.library.ui.AppScaffold-import com.vayunmathur.library.ui.CircularProgressIndicator import com.vayunmathur.library.ui.EmptyState import com.vayunmathur.library.ui.IconSearch @@ -45,15 +42,9 @@ fun BrowseScreen( title = state.title, onNavigateBack = onBack, alignment = AppBarAlignment.Start,+ isLoading = state.isLoading && state.apps.isEmpty(), ) { padding -> when {- state.isLoading && state.apps.isEmpty() -> Box(- Modifier.fillMaxSize().padding(padding),- contentAlignment = Alignment.Center,- ) {- CircularProgressIndicator()- }- state.apps.isEmpty() -> EmptyState( title = stringResource(R.string.browse_empty_title), message = stringResource(R.string.browse_empty_message),
appstore/src/main/java/com/vayunmathur/appstore/ui/LibraryScreen.kt
diff --git a/appstore/src/main/java/com/vayunmathur/appstore/ui/LibraryScreen.kt b/appstore/src/main/java/com/vayunmathur/appstore/ui/LibraryScreen.ktindex a78fe33ba4..07c3f6350d 100644--- a/appstore/src/main/java/com/vayunmathur/appstore/ui/LibraryScreen.kt+++ b/appstore/src/main/java/com/vayunmathur/appstore/ui/LibraryScreen.kt@@ -23,6 +23,7 @@ import androidx.compose.ui.unit.dp import com.vayunmathur.appstore.data.UnifiedApp import com.vayunmathur.appstore.platform.AppStoreViewModel import com.vayunmathur.library.ui.EmptyState+import com.vayunmathur.library.ui.LoadingState import com.vayunmathur.library.ui.FilterChip import com.vayunmathur.library.ui.IconPackage import com.vayunmathur.library.ui.AppScaffold@@ -64,7 +65,9 @@ fun LibraryScreen( } } - if (state.apps.isEmpty()) {+ if (!state.hasLoaded && state.apps.isEmpty()) {+ LoadingState(Modifier.fillMaxSize())+ } else if (state.apps.isEmpty()) { EmptyState( title = stringResource(R.string.library_empty_title), message = stringResource(R.string.library_empty_message),
appstore/src/main/java/com/vayunmathur/appstore/ui/UpdatesScreen.kt
diff --git a/appstore/src/main/java/com/vayunmathur/appstore/ui/UpdatesScreen.kt b/appstore/src/main/java/com/vayunmathur/appstore/ui/UpdatesScreen.ktindex 1a1a18356a..e459e63d0e 100644--- a/appstore/src/main/java/com/vayunmathur/appstore/ui/UpdatesScreen.kt+++ b/appstore/src/main/java/com/vayunmathur/appstore/ui/UpdatesScreen.kt@@ -30,7 +30,6 @@ import com.vayunmathur.appstore.platform.AppStoreViewModel import com.vayunmathur.library.ui.AppPullToRefreshBox import com.vayunmathur.library.ui.Button import com.vayunmathur.library.ui.EmptyState-import com.vayunmathur.library.ui.LoadingState import com.vayunmathur.library.ui.IconCheck import com.vayunmathur.library.ui.IconDownload import com.vayunmathur.library.ui.MaterialTheme@@ -46,7 +45,7 @@ fun UpdatesScreen( val anyInstalling = state.stages.values.any { it !is InstallStage.Failed } val total = state.updates.size + state.foreignUpdates.size - AppScaffold(topBar = {}) { padding ->+ AppScaffold(topBar = {}, isLoading = total == 0 && state.isChecking) { padding -> AppPullToRefreshBox( isRefreshing = state.isChecking, onRefresh = { actions.checkForUpdates() },@@ -93,9 +92,7 @@ fun UpdatesScreen( ) } - if (total == 0 && state.isChecking) {- LoadingState(modifier = Modifier.fillMaxSize())- } else if (total == 0) {+ if (total == 0) { EmptyState( title = stringResource(R.string.all_apps_up_to_date), message = stringResource(R.string.updates_empty_message),
build-logic/src/main/kotlin/common-conventions-app.gradle.kts
diff --git a/build-logic/src/main/kotlin/common-conventions-app.gradle.kts b/build-logic/src/main/kotlin/common-conventions-app.gradle.ktsindex 45eea3c635..e859e316ee 100644--- a/build-logic/src/main/kotlin/common-conventions-app.gradle.kts+++ b/build-logic/src/main/kotlin/common-conventions-app.gradle.kts@@ -297,6 +297,7 @@ configure<com.android.build.api.dsl.ApplicationExtension> { "OneComposablePerFile", "PackageStructure", "RawScaffoldInApp",+ "ScaffoldLoading", "Room2Usage", "WindowInsetsInReusableComponent", "ExceptionMarkerFormat",
build-logic/src/main/kotlin/common-conventions-library.gradle.kts
diff --git a/build-logic/src/main/kotlin/common-conventions-library.gradle.kts b/build-logic/src/main/kotlin/common-conventions-library.gradle.ktsindex 4cf632a030..a3ad0f8ed4 100644--- a/build-logic/src/main/kotlin/common-conventions-library.gradle.kts+++ b/build-logic/src/main/kotlin/common-conventions-library.gradle.kts@@ -87,6 +87,7 @@ configure<com.android.build.api.dsl.LibraryExtension> { "OneComposablePerFile", "PackageStructure", "RawScaffoldInApp",+ "ScaffoldLoading", "Room2Usage", "WindowInsetsInReusableComponent", "ExceptionMarkerFormat",
email/src/main/java/com/vayunmathur/email/platform/EmailViewModel.kt
diff --git a/email/src/main/java/com/vayunmathur/email/platform/EmailViewModel.kt b/email/src/main/java/com/vayunmathur/email/platform/EmailViewModel.ktindex 1669131705..11bd1f459c 100644--- a/email/src/main/java/com/vayunmathur/email/platform/EmailViewModel.kt+++ b/email/src/main/java/com/vayunmathur/email/platform/EmailViewModel.kt@@ -22,6 +22,7 @@ import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.StateFlow+import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.debounce import kotlinx.coroutines.flow.flatMapLatest@@ -59,8 +60,18 @@ class EmailViewModel(application: Application) : val isSyncing: StateFlow<Boolean> = EmailSyncState.isSyncing val syncProgress: StateFlow<Float> = EmailSyncState.progress + private val _hasLoadedOutbox = kotlinx.coroutines.flow.MutableStateFlow(false)+ /** Flips true once the outbox DAO emits at least once; the list starts empty. */+ val hasLoadedOutbox: kotlinx.coroutines.flow.StateFlow<Boolean> = _hasLoadedOutbox++ private val _hasLoadedDrafts = kotlinx.coroutines.flow.MutableStateFlow(false)+ /** Flips true once the drafts DAO emits at least once; the list starts empty. */+ val hasLoadedDrafts: kotlinx.coroutines.flow.StateFlow<Boolean> = _hasLoadedDrafts+ val outbox: Flow<List<OutboxEntry>> = outboxDao.getOutboxFlow()+ .onEach { _hasLoadedOutbox.value = true } val drafts: Flow<List<com.vayunmathur.email.data.DraftEntry>> = outboxDao.getDraftsFlow()+ .onEach { _hasLoadedDrafts.value = true } /** Block a sender (matched by email address) so their mail is hidden from the inbox. */ override fun blockSender(from: String) {
email/src/main/java/com/vayunmathur/email/ui/DraftsScreen.kt
diff --git a/email/src/main/java/com/vayunmathur/email/ui/DraftsScreen.kt b/email/src/main/java/com/vayunmathur/email/ui/DraftsScreen.ktindex b73d0f8fdb..188475f5a1 100644--- a/email/src/main/java/com/vayunmathur/email/ui/DraftsScreen.kt+++ b/email/src/main/java/com/vayunmathur/email/ui/DraftsScreen.kt@@ -14,6 +14,7 @@ import com.vayunmathur.email.R import com.vayunmathur.email.platform.EmailViewModel import com.vayunmathur.library.ui.AppScaffold import com.vayunmathur.library.ui.EmptyState+import com.vayunmathur.library.ui.LoadingState import com.vayunmathur.library.ui.HorizontalDivider import com.vayunmathur.library.ui.IconButton import com.vayunmathur.library.ui.IconDelete@@ -28,11 +29,14 @@ fun DraftsScreen( onOpenDraft: (Long) -> Unit, ) { val drafts by viewModel.drafts.collectAsStateWithLifecycle(emptyList())+ val hasLoaded by viewModel.hasLoadedDrafts.collectAsStateWithLifecycle() AppScaffold( title = stringResource(R.string.drafts), onNavigateBack = onBack, ) { padding ->- if (drafts.isEmpty()) {+ if (!hasLoaded && drafts.isEmpty()) {+ LoadingState(Modifier.fillMaxSize().padding(padding))+ } else if (drafts.isEmpty()) { EmptyState( title = stringResource(R.string.no_drafts), modifier = Modifier.fillMaxSize().padding(padding),
email/src/main/java/com/vayunmathur/email/ui/EmlViewerScreen.kt
diff --git a/email/src/main/java/com/vayunmathur/email/ui/EmlViewerScreen.kt b/email/src/main/java/com/vayunmathur/email/ui/EmlViewerScreen.ktindex 0c51e5f5f1..dcbaeb1044 100644--- a/email/src/main/java/com/vayunmathur/email/ui/EmlViewerScreen.kt+++ b/email/src/main/java/com/vayunmathur/email/ui/EmlViewerScreen.kt@@ -104,6 +104,7 @@ fun EmlViewerScreen( } AppScaffold(+ isLoading = loading, title = { val t = parsed?.message?.subject ?: uriString.substringAfterLast('/').substringAfterLast("%2F") Text(t.ifBlank { stringResource(R.string.e_mail_file) }, maxLines = 1, overflow = TextOverflow.Ellipsis)@@ -119,11 +120,6 @@ fun EmlViewerScreen( }, ) { padding -> when {- loading -> {- Box(modifier = Modifier.fillMaxSize().padding(padding), contentAlignment = Alignment.Center) {- CircularProgressIndicator()- }- } error != null -> { Box(modifier = Modifier.fillMaxSize().padding(padding).padding(16.dp), contentAlignment = Alignment.Center) { Column(horizontalAlignment = Alignment.CenterHorizontally) {
email/src/main/java/com/vayunmathur/email/ui/MessageListScreen.kt
diff --git a/email/src/main/java/com/vayunmathur/email/ui/MessageListScreen.kt b/email/src/main/java/com/vayunmathur/email/ui/MessageListScreen.ktindex 518812528a..a95d189edd 100644--- a/email/src/main/java/com/vayunmathur/email/ui/MessageListScreen.kt+++ b/email/src/main/java/com/vayunmathur/email/ui/MessageListScreen.kt@@ -147,6 +147,7 @@ fun MessageListScreen( } }, snackbarHost = { SnackbarHost(snackbarHostState) },+ isLoading = state.messages.isEmpty() && state.searchQuery.isEmpty() && state.isSyncing, ) { padding -> Column(modifier = Modifier.padding(padding).fillMaxSize()) { Box(modifier = Modifier.fillMaxWidth().height(2.dp)) {@@ -186,9 +187,7 @@ fun MessageListScreen( // so only a small clearance is needed; the slot stays centered. topClearance = 8.dp, ) {- if (state.messages.isEmpty() && state.searchQuery.isEmpty() && state.isSyncing) {- com.vayunmathur.library.ui.LoadingState(modifier = Modifier.fillMaxSize())- } else if (state.messages.isEmpty() && state.searchQuery.isEmpty()) {+ if (state.messages.isEmpty() && state.searchQuery.isEmpty()) { EmptyState( title = stringResource(R.string.no_messages_found_pull_down_to_refresh), modifier = Modifier.fillMaxSize(),
email/src/main/java/com/vayunmathur/email/ui/OutboxScreen.kt
diff --git a/email/src/main/java/com/vayunmathur/email/ui/OutboxScreen.kt b/email/src/main/java/com/vayunmathur/email/ui/OutboxScreen.ktindex a43b90abb4..8dc6e88618 100644--- a/email/src/main/java/com/vayunmathur/email/ui/OutboxScreen.kt+++ b/email/src/main/java/com/vayunmathur/email/ui/OutboxScreen.kt@@ -27,6 +27,7 @@ import com.vayunmathur.email.data.OutboxEntry import com.vayunmathur.email.platform.EmailViewModel import com.vayunmathur.library.ui.AppScaffold import com.vayunmathur.library.ui.EmptyState+import com.vayunmathur.library.ui.LoadingState import com.vayunmathur.library.ui.ExperimentalMaterial3Api import com.vayunmathur.library.ui.HorizontalDivider import com.vayunmathur.library.ui.IconButton@@ -43,6 +44,7 @@ fun OutboxScreen( onBack: () -> Unit, ) { val outbox by viewModel.outbox.collectAsStateWithLifecycle(emptyList())+ val hasLoaded by viewModel.hasLoadedOutbox.collectAsStateWithLifecycle() val context = LocalContext.current val resources = LocalResources.current @@ -58,7 +60,9 @@ fun OutboxScreen( } }, ) { padding ->- if (outbox.isEmpty()) {+ if (!hasLoaded && outbox.isEmpty()) {+ LoadingState(Modifier.padding(padding).fillMaxSize())+ } else if (outbox.isEmpty()) { EmptyState( title = stringResource(R.string.outbox_is_empty), modifier = Modifier.padding(padding).fillMaxSize(),
emergency/src/main/java/com/vayunmathur/emergency/ui/ViewInfoScreen.kt
diff --git a/emergency/src/main/java/com/vayunmathur/emergency/ui/ViewInfoScreen.kt b/emergency/src/main/java/com/vayunmathur/emergency/ui/ViewInfoScreen.ktindex 1883255bb1..76a2ccb3e7 100644--- a/emergency/src/main/java/com/vayunmathur/emergency/ui/ViewInfoScreen.kt+++ b/emergency/src/main/java/com/vayunmathur/emergency/ui/ViewInfoScreen.kt@@ -24,7 +24,6 @@ import com.vayunmathur.emergency.platform.EmergencyUiState import com.vayunmathur.emergency.platform.EmergencyViewModel import com.vayunmathur.library.ui.Card import com.vayunmathur.library.ui.LazyListScaffold-import com.vayunmathur.library.ui.LoadingState import com.vayunmathur.library.ui.Text import com.vayunmathur.library.ui.verticalShape @@ -34,6 +33,7 @@ fun ViewInfoScreen(state: EmergencyUiState) { // Resolved up front: the LazyListScope content below is not itself @Composable, // so stringResource() calls must happen here or inside item {} blocks. val ownerLabel = stringResource(R.string.group_owner)+ val loadingLabel = stringResource(R.string.contacts_loading) val contactLabel = stringResource(R.string.group_emergency_contact) val allergiesLabel = stringResource(R.string.section_allergies) val conditionsLabel = stringResource(R.string.section_conditions)@@ -44,12 +44,10 @@ fun ViewInfoScreen(state: EmergencyUiState) { LazyListScaffold( // No title and no actions: the scaffold draws no bar, so the content starts // at the top. scrollBehavior is still required for the nested-scroll wiring.+ isLoading = state.loading,+ loadingMessage = loadingLabel, ) {- if (state.loading) {- item {- LoadingState(modifier = Modifier.fillParentMaxSize())- }- } else if (ownerRows.isEmpty() && state.info.contacts.isEmpty() &&+ if (ownerRows.isEmpty() && state.info.contacts.isEmpty() && state.health.allergies.isEmpty() && state.health.conditions.isEmpty() && state.health.medications.isEmpty() ) {
euicc/src/main/java/com/vayunmathur/euicc/ui/ProfileDetailScreen.kt
diff --git a/euicc/src/main/java/com/vayunmathur/euicc/ui/ProfileDetailScreen.kt b/euicc/src/main/java/com/vayunmathur/euicc/ui/ProfileDetailScreen.ktindex 7d3801fbfa..97e21810e3 100644--- a/euicc/src/main/java/com/vayunmathur/euicc/ui/ProfileDetailScreen.kt+++ b/euicc/src/main/java/com/vayunmathur/euicc/ui/ProfileDetailScreen.kt@@ -15,7 +15,6 @@ import com.vayunmathur.euicc.platform.EuiccScreenState import com.vayunmathur.euicc.ui.dialogs.RenameDialog import com.vayunmathur.library.ui.ConfirmDialog import com.vayunmathur.library.ui.DetailScaffold-import com.vayunmathur.library.ui.LoadingState import com.vayunmathur.library.ui.SettingsRow import com.vayunmathur.library.ui.SettingsSection import com.vayunmathur.library.ui.Text@@ -48,9 +47,7 @@ fun ProfileDetailScreen( if (profile == null) { // Still loading, erased, or the eUICC was re-read and no longer reports it. if (state.loading) {- DetailScaffold(title = "", onNavigateBack = { backStack.pop() }) {- LoadingState()- }+ DetailScaffold(title = "", onNavigateBack = { backStack.pop() }, isLoading = true) {} } else { backStack.pop() }
fooddelivery/src/main/java/com/vayunmathur/fooddelivery/ui/DealsScreen.kt
diff --git a/fooddelivery/src/main/java/com/vayunmathur/fooddelivery/ui/DealsScreen.kt b/fooddelivery/src/main/java/com/vayunmathur/fooddelivery/ui/DealsScreen.ktindex 483a0b3dfd..58e49cf3e9 100644--- a/fooddelivery/src/main/java/com/vayunmathur/fooddelivery/ui/DealsScreen.kt+++ b/fooddelivery/src/main/java/com/vayunmathur/fooddelivery/ui/DealsScreen.kt@@ -1,7 +1,6 @@ package com.vayunmathur.fooddelivery.ui import androidx.compose.foundation.layout.Arrangement-import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.Row@@ -21,7 +20,6 @@ import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue-import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip import androidx.compose.ui.layout.ContentScale@@ -32,7 +30,6 @@ import androidx.compose.ui.unit.dp import androidx.compose.foundation.shape.RoundedCornerShape import com.vayunmathur.library.image.compose.AsyncImage import com.vayunmathur.library.ui.Card-import com.vayunmathur.library.ui.CircularProgressIndicator import com.vayunmathur.library.ui.EmptyState import com.vayunmathur.library.ui.IconEmojiEvents import com.vayunmathur.library.ui.LinearProgressIndicator@@ -78,13 +75,8 @@ fun DealsScreen(onMerchantClick: (Int) -> Unit) { } } - AppScaffold(topBar = {}) { padding ->+ AppScaffold(topBar = {}, isLoading = loading) { padding -> when {- loading -> Box(- Modifier.fillMaxSize().padding(padding),- contentAlignment = Alignment.Center,- ) { CircularProgressIndicator() }- deals.isEmpty() -> EmptyState( title = stringResource(R.string.no_deals_yet), message = stringResource(R.string.deals_will_appear_here),
fooddelivery/src/main/java/com/vayunmathur/fooddelivery/ui/EmailVerificationScreen.kt
diff --git a/fooddelivery/src/main/java/com/vayunmathur/fooddelivery/ui/EmailVerificationScreen.kt b/fooddelivery/src/main/java/com/vayunmathur/fooddelivery/ui/EmailVerificationScreen.ktindex 1cb2dd2e46..eb26ff04d7 100644--- a/fooddelivery/src/main/java/com/vayunmathur/fooddelivery/ui/EmailVerificationScreen.kt+++ b/fooddelivery/src/main/java/com/vayunmathur/fooddelivery/ui/EmailVerificationScreen.kt@@ -24,7 +24,6 @@ import com.vayunmathur.fooddelivery.network.BitesCustomers import com.vayunmathur.fooddelivery.platform.AppInit import com.vayunmathur.library.ui.AppScaffold import com.vayunmathur.library.ui.Button-import com.vayunmathur.library.ui.CircularProgressIndicator import com.vayunmathur.library.ui.IconCheck import com.vayunmathur.library.ui.IconWarning import com.vayunmathur.library.ui.MaterialTheme@@ -70,6 +69,8 @@ private fun EmailVerificationContent( AppScaffold( title = stringResource(R.string.email_verification), onClose = onDone,+ isLoading = state == VerifyState.LOADING,+ loadingMessage = stringResource(R.string.verifying_your_email), ) { padding -> Column( Modifier.fillMaxSize().padding(padding).padding(24.dp),@@ -77,11 +78,7 @@ private fun EmailVerificationContent( verticalArrangement = Arrangement.Center, ) { when (state) {- VerifyState.LOADING -> {- CircularProgressIndicator()- Spacer(Modifier.height(16.dp))- Text(stringResource(R.string.verifying_your_email))- }+ VerifyState.LOADING -> Unit VerifyState.SUCCESS -> { IconCheck( modifier = Modifier.size(64.dp),
fooddelivery/src/main/java/com/vayunmathur/fooddelivery/ui/HomeContent.kt
diff --git a/fooddelivery/src/main/java/com/vayunmathur/fooddelivery/ui/HomeContent.kt b/fooddelivery/src/main/java/com/vayunmathur/fooddelivery/ui/HomeContent.ktindex 17374fa23f..97da248ab6 100644--- a/fooddelivery/src/main/java/com/vayunmathur/fooddelivery/ui/HomeContent.kt+++ b/fooddelivery/src/main/java/com/vayunmathur/fooddelivery/ui/HomeContent.kt@@ -35,7 +35,6 @@ import androidx.compose.ui.unit.dp import com.vayunmathur.library.image.compose.AsyncImage import com.vayunmathur.library.ui.Button import com.vayunmathur.library.ui.Card-import com.vayunmathur.library.ui.LoadingIndicator import com.vayunmathur.library.ui.IconHome import com.vayunmathur.library.ui.IconStar import com.vayunmathur.library.ui.MaterialTheme@@ -60,12 +59,8 @@ fun HomeContent( noAddress: Boolean = false, onMerchantClick: (Int) -> Unit = {}, ) {- AppScaffold(topBar = {}) { padding ->- if (loading) {- Box(Modifier.fillMaxSize().padding(padding), contentAlignment = Alignment.Center) {- LoadingIndicator()- }- } else if (noAddress) {+ AppScaffold(topBar = {}, isLoading = loading) { padding ->+ if (noAddress) { Box(Modifier.fillMaxSize().padding(padding), contentAlignment = Alignment.Center) { Column(horizontalAlignment = Alignment.CenterHorizontally) { IconHome(modifier = Modifier.size(48.dp),
fooddelivery/src/main/java/com/vayunmathur/fooddelivery/ui/OrderTrackingScreen.kt
diff --git a/fooddelivery/src/main/java/com/vayunmathur/fooddelivery/ui/OrderTrackingScreen.kt b/fooddelivery/src/main/java/com/vayunmathur/fooddelivery/ui/OrderTrackingScreen.ktindex 8de5e13dda..e5c88317a9 100644--- a/fooddelivery/src/main/java/com/vayunmathur/fooddelivery/ui/OrderTrackingScreen.kt+++ b/fooddelivery/src/main/java/com/vayunmathur/fooddelivery/ui/OrderTrackingScreen.kt@@ -43,7 +43,6 @@ import com.vayunmathur.library.ui.AppScaffold import com.vayunmathur.library.util.ConnectivityMonitor import com.vayunmathur.library.ui.Button import com.vayunmathur.library.ui.Card-import com.vayunmathur.library.ui.CircularProgressIndicator import com.vayunmathur.library.ui.EmptyState import com.vayunmathur.library.ui.IconHome import com.vayunmathur.library.ui.IconDeliveryDining@@ -113,14 +112,10 @@ fun OrderTrackingScreen(orderId: Int, onBack: () -> Unit) { ) }, onNavigateBack = onBack,+ isLoading = loading, ) { padding -> val o = order when {- loading -> Box(- Modifier.fillMaxSize().padding(padding),- contentAlignment = Alignment.Center,- ) { CircularProgressIndicator() }- o == null -> EmptyState( title = stringResource(R.string.order_not_found), modifier = Modifier.fillMaxSize().padding(padding),
fooddelivery/src/main/java/com/vayunmathur/fooddelivery/ui/OrdersScreen.kt
diff --git a/fooddelivery/src/main/java/com/vayunmathur/fooddelivery/ui/OrdersScreen.kt b/fooddelivery/src/main/java/com/vayunmathur/fooddelivery/ui/OrdersScreen.ktindex a4a29ecbaf..cc31163856 100644--- a/fooddelivery/src/main/java/com/vayunmathur/fooddelivery/ui/OrdersScreen.kt+++ b/fooddelivery/src/main/java/com/vayunmathur/fooddelivery/ui/OrdersScreen.kt@@ -38,7 +38,6 @@ import com.vayunmathur.library.image.compose.AsyncImage import com.vayunmathur.library.ui.AlertDialog import com.vayunmathur.library.ui.Button import com.vayunmathur.library.ui.Card-import com.vayunmathur.library.ui.CircularProgressIndicator import com.vayunmathur.library.ui.FilterChip import com.vayunmathur.library.ui.IconButton import com.vayunmathur.library.ui.IconPackage@@ -112,12 +111,8 @@ fun OrdersScreen(onTrackOrder: (Int) -> Unit = {}) { loading = false } - AppScaffold(topBar = {}) { padding ->- if (loading) {- Box(Modifier.fillMaxSize().padding(padding), contentAlignment = Alignment.Center) {- CircularProgressIndicator()- }- } else if (!isLoggedIn) {+ AppScaffold(topBar = {}, isLoading = loading) { padding ->+ if (!isLoggedIn) { Box(Modifier.fillMaxSize().padding(padding), contentAlignment = Alignment.Center) { Column(horizontalAlignment = Alignment.CenterHorizontally) { IconPerson(modifier = Modifier.size(48.dp),
fooddelivery/src/main/java/com/vayunmathur/fooddelivery/ui/RestaurantContent.kt
diff --git a/fooddelivery/src/main/java/com/vayunmathur/fooddelivery/ui/RestaurantContent.kt b/fooddelivery/src/main/java/com/vayunmathur/fooddelivery/ui/RestaurantContent.ktindex b915199deb..0bdb21caca 100644--- a/fooddelivery/src/main/java/com/vayunmathur/fooddelivery/ui/RestaurantContent.kt+++ b/fooddelivery/src/main/java/com/vayunmathur/fooddelivery/ui/RestaurantContent.kt@@ -40,7 +40,6 @@ import com.vayunmathur.library.ui.AlertDialog import com.vayunmathur.library.ui.Button import com.vayunmathur.library.ui.Card import com.vayunmathur.library.ui.Checkbox-import com.vayunmathur.library.ui.LoadingIndicator import com.vayunmathur.library.ui.HorizontalDivider import com.vayunmathur.library.ui.IconAdd import com.vayunmathur.library.ui.IconBack@@ -106,12 +105,8 @@ fun RestaurantContent( ) } - AppScaffold(topBar = {}) { padding ->- if (loading) {- Box(Modifier.fillMaxSize().padding(padding), contentAlignment = Alignment.Center) {- LoadingIndicator()- }- } else if (merchant == null) {+ AppScaffold(topBar = {}, isLoading = loading) { padding ->+ if (merchant == null) { EmptyState( title = stringResource(R.string.restaurant_not_found), modifier = Modifier.fillMaxSize().padding(padding),
library/ui/src/main/java/com/vayunmathur/library/ui/AppScaffold.kt
diff --git a/library/ui/src/main/java/com/vayunmathur/library/ui/AppScaffold.kt b/library/ui/src/main/java/com/vayunmathur/library/ui/AppScaffold.ktindex 1dd55fbfd5..2556f80f67 100644--- a/library/ui/src/main/java/com/vayunmathur/library/ui/AppScaffold.kt+++ b/library/ui/src/main/java/com/vayunmathur/library/ui/AppScaffold.kt@@ -2,6 +2,8 @@ package com.vayunmathur.library.ui import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.RowScope+import androidx.compose.foundation.layout.fillMaxSize+import androidx.compose.foundation.layout.padding import androidx.compose.material3.Text import androidx.compose.material3.TopAppBarScrollBehavior import androidx.compose.runtime.Composable@@ -54,6 +56,17 @@ enum class AppBarSize { Small, MediumFlexible, LargeFlexible } * [scrollBehavior] defaults to [appBarScrollBehavior] for the chosen [size] — almost every * screen passed exactly that by hand (335 call sites), so it is now the default rather than * a per-screen statement. Pass one explicitly only to pair a size with a custom behaviour.+ *+ * Loading belongs here, not in the content: pass [isLoading] (with an optional+ * [loadingMessage]) and the scaffold renders the canonical [LoadingState] in the+ * content area instead of invoking [content] at all. The bars, FAB, bottom bar and+ * snackbar host keep rendering, so the screen's chrome does not jump while its data+ * arrives. That replacement semantics is deliberate — a screen whose content lambda+ * ran under a spinner would compose its empty state and fire its item effects for+ * data that has not arrived yet. Local waits that are not the whole screen (a+ * button's own progress, a determinate transfer, pull-to-refresh) are not this:+ * keep those inline; the `ScaffoldLoading` lint rule only flags whole-content+ * loading inside a scaffold. */ @Composable fun AppScaffold(@@ -71,6 +84,8 @@ fun AppScaffold( bottomBar: @Composable () -> Unit = {}, snackbarHost: (@Composable () -> Unit)? = null, containerColor: Color = MaterialTheme.colorScheme.background,+ isLoading: Boolean = false,+ loadingMessage: String? = null, content: @Composable (PaddingValues) -> Unit, ) = AppScaffold( title = { Text(title, modifier = Modifier.semantics { heading() }) },@@ -87,6 +102,8 @@ fun AppScaffold( bottomBar = bottomBar, snackbarHost = snackbarHost, containerColor = containerColor,+ isLoading = isLoading,+ loadingMessage = loadingMessage, content = content, ) @@ -112,6 +129,8 @@ fun AppScaffold( bottomBar: @Composable () -> Unit = {}, snackbarHost: (@Composable () -> Unit)? = null, containerColor: Color = MaterialTheme.colorScheme.background,+ isLoading: Boolean = false,+ loadingMessage: String? = null, content: @Composable (PaddingValues) -> Unit, ) { val resolvedNavigationIcon = resolveNavigationIcon(navigationIcon, onClose, onNavigateBack)@@ -133,8 +152,16 @@ fun AppScaffold( bottomBar = bottomBar, snackbarHost = snackbarHost, containerColor = containerColor,- content = content,- )+ ) { padding ->+ if (isLoading) {+ LoadingState(+ modifier = Modifier.fillMaxSize().padding(padding),+ message = loadingMessage,+ )+ } else {+ content(padding)+ }+ } } /**@@ -150,6 +177,8 @@ fun AppScaffold( bottomBar: @Composable () -> Unit = {}, snackbarHost: (@Composable () -> Unit)? = null, containerColor: Color = MaterialTheme.colorScheme.background,+ isLoading: Boolean = false,+ loadingMessage: String? = null, content: @Composable (PaddingValues) -> Unit, ) = Scaffold( modifier = modifier,@@ -158,8 +187,16 @@ fun AppScaffold( bottomBar = bottomBar, snackbarHost = snackbarHost, containerColor = containerColor,- content = content,-)+) { padding ->+ if (isLoading) {+ LoadingState(+ modifier = Modifier.fillMaxSize().padding(padding),+ message = loadingMessage,+ )+ } else {+ content(padding)+ }+} /** [AppScaffold] for a screen that owns a back stack, wiring the back button to it. */ @Composable@@ -178,6 +215,8 @@ fun <T : NavKey> AppScaffold( bottomBar: @Composable () -> Unit = {}, snackbarHost: (@Composable () -> Unit)? = null, containerColor: Color = MaterialTheme.colorScheme.background,+ isLoading: Boolean = false,+ loadingMessage: String? = null, content: @Composable (PaddingValues) -> Unit, ) = AppScaffold( title = title,@@ -194,6 +233,8 @@ fun <T : NavKey> AppScaffold( bottomBar = bottomBar, snackbarHost = snackbarHost, containerColor = containerColor,+ isLoading = isLoading,+ loadingMessage = loadingMessage, content = content, )
library/ui/src/main/java/com/vayunmathur/library/ui/DetailScaffold.kt
diff --git a/library/ui/src/main/java/com/vayunmathur/library/ui/DetailScaffold.kt b/library/ui/src/main/java/com/vayunmathur/library/ui/DetailScaffold.ktindex 23f7228fe0..d5c71df59a 100644--- a/library/ui/src/main/java/com/vayunmathur/library/ui/DetailScaffold.kt+++ b/library/ui/src/main/java/com/vayunmathur/library/ui/DetailScaffold.kt@@ -43,6 +43,9 @@ import com.vayunmathur.library.util.NavKey * [DetailLazyColumn] instead when the body is itself a long list that should * lazily compose. *+ * [isLoading] is forwarded to [AppScaffold]: while true the scaffold renders+ * the canonical loading state instead of the detail column (see AppScaffold).+ * * On wide windows the scrolling column is centred and capped at * [DesktopContentMaxWidth] so forms and detail blocks keep a readable * measure instead of stretching edge to edge. Pass [fullBleed] = true only@@ -62,6 +65,8 @@ fun DetailScaffold( scrollBehavior: TopAppBarScrollBehavior? = null, bottomBar: @Composable () -> Unit = {}, fullBleed: Boolean = false,+ isLoading: Boolean = false,+ loadingMessage: String? = null, content: @Composable ColumnScope.() -> Unit, ) = AppScaffold( title = title,@@ -74,6 +79,8 @@ fun DetailScaffold( actions = actions, scrollBehavior = scrollBehavior, bottomBar = bottomBar,+ isLoading = isLoading,+ loadingMessage = loadingMessage, ) { pad -> DetailColumn(pad, fillHeight = false, fullBleed = fullBleed, content) }@@ -93,6 +100,8 @@ fun DetailScaffold( bottomBar: @Composable () -> Unit = {}, fillHeight: Boolean = false, fullBleed: Boolean = false,+ isLoading: Boolean = false,+ loadingMessage: String? = null, content: @Composable ColumnScope.() -> Unit, ) = AppScaffold( title = title,@@ -105,6 +114,8 @@ fun DetailScaffold( actions = actions, scrollBehavior = scrollBehavior, bottomBar = bottomBar,+ isLoading = isLoading,+ loadingMessage = loadingMessage, ) { pad -> DetailColumn(pad, fillHeight, fullBleed, content) }@@ -123,6 +134,8 @@ fun <T : NavKey> DetailScaffold( scrollBehavior: TopAppBarScrollBehavior? = null, bottomBar: @Composable () -> Unit = {}, fullBleed: Boolean = false,+ isLoading: Boolean = false,+ loadingMessage: String? = null, content: @Composable ColumnScope.() -> Unit, ) = DetailScaffold( title = title,@@ -136,6 +149,8 @@ fun <T : NavKey> DetailScaffold( scrollBehavior = scrollBehavior, bottomBar = bottomBar, fullBleed = fullBleed,+ isLoading = isLoading,+ loadingMessage = loadingMessage, content = content, ) @@ -155,6 +170,8 @@ fun DetailLazyColumn( actions: @Composable RowScope.() -> Unit = {}, scrollBehavior: TopAppBarScrollBehavior? = null, bottomBar: @Composable () -> Unit = {},+ isLoading: Boolean = false,+ loadingMessage: String? = null, content: LazyListScope.() -> Unit, ) = AppScaffold( title = title,@@ -165,6 +182,8 @@ fun DetailLazyColumn( actions = actions, scrollBehavior = scrollBehavior, bottomBar = bottomBar,+ isLoading = isLoading,+ loadingMessage = loadingMessage, ) { pad -> DetailList(pad, content) }@@ -180,6 +199,8 @@ fun DetailLazyColumn( actions: @Composable RowScope.() -> Unit = {}, scrollBehavior: TopAppBarScrollBehavior? = null, bottomBar: @Composable () -> Unit = {},+ isLoading: Boolean = false,+ loadingMessage: String? = null, content: LazyListScope.() -> Unit, ) = AppScaffold( title = title,@@ -190,6 +211,8 @@ fun DetailLazyColumn( actions = actions, scrollBehavior = scrollBehavior, bottomBar = bottomBar,+ isLoading = isLoading,+ loadingMessage = loadingMessage, ) { pad -> DetailList(pad, content) }@@ -205,6 +228,8 @@ fun <T : NavKey> DetailLazyColumn( actions: @Composable RowScope.() -> Unit = {}, scrollBehavior: TopAppBarScrollBehavior? = null, bottomBar: @Composable () -> Unit = {},+ isLoading: Boolean = false,+ loadingMessage: String? = null, content: LazyListScope.() -> Unit, ) = DetailLazyColumn( title = title,@@ -215,6 +240,8 @@ fun <T : NavKey> DetailLazyColumn( actions = actions, scrollBehavior = scrollBehavior, bottomBar = bottomBar,+ isLoading = isLoading,+ loadingMessage = loadingMessage, content = content, )
library/ui/src/main/java/com/vayunmathur/library/ui/LazyListScaffold.kt
diff --git a/library/ui/src/main/java/com/vayunmathur/library/ui/LazyListScaffold.kt b/library/ui/src/main/java/com/vayunmathur/library/ui/LazyListScaffold.ktindex d92e4e32bb..c51d78ddf5 100644--- a/library/ui/src/main/java/com/vayunmathur/library/ui/LazyListScaffold.kt+++ b/library/ui/src/main/java/com/vayunmathur/library/ui/LazyListScaffold.kt@@ -10,6 +10,7 @@ import androidx.compose.foundation.layout.RowScope import androidx.compose.foundation.layout.calculateEndPadding import androidx.compose.foundation.layout.calculateStartPadding import androidx.compose.foundation.layout.fillMaxSize+import androidx.compose.foundation.layout.padding import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.LazyListScope import androidx.compose.foundation.lazy.LazyListState@@ -49,6 +50,9 @@ import androidx.compose.ui.unit.dp * already pass their own margin (e.g. 16.dp) can pass [Spacing.lg] explicitly * to stay fixed, or `0.dp` to opt out entirely. *+ * [isLoading] replaces the list with the canonical loading state (the scaffold's+ * bars stay); see [AppScaffold] for the whole-content loading semantics.+ * * [overlay] is drawn on top of the list in a [Box] exactly the list's size, * for chrome that must track the viewport itself - e.g. a fast-scroller whose * travel should run along the list, not the whole screen.@@ -70,6 +74,8 @@ fun LazyListScaffold( verticalArrangement: Arrangement.Vertical = Arrangement.Top, containerColor: Color = MaterialTheme.colorScheme.background, overlay: @Composable BoxScope.() -> Unit = {},+ isLoading: Boolean = false,+ loadingMessage: String? = null, content: LazyListScope.() -> Unit, ) { val behavior = scrollBehavior ?: appBarScrollBehavior()@@ -87,6 +93,13 @@ fun LazyListScaffold( floatingActionButtonPosition, containerColor, ) { pad ->+ if (isLoading) {+ LoadingState(+ modifier = Modifier.fillMaxSize().padding(pad),+ message = loadingMessage,+ )+ return@Scaffold+ } val dir = LocalLayoutDirection.current // Only the width class above compact adds padding; on phones this is // exactly [horizontalPadding], unchanged from before.
library/ui/src/main/java/com/vayunmathur/library/ui/SetupScaffold.kt
diff --git a/library/ui/src/main/java/com/vayunmathur/library/ui/SetupScaffold.kt b/library/ui/src/main/java/com/vayunmathur/library/ui/SetupScaffold.ktindex 2792104488..98292df032 100644--- a/library/ui/src/main/java/com/vayunmathur/library/ui/SetupScaffold.kt+++ b/library/ui/src/main/java/com/vayunmathur/library/ui/SetupScaffold.kt@@ -62,6 +62,8 @@ fun SetupScaffold( secondaryAction: SetupAction? = null, scrollBehavior: TopAppBarScrollBehavior? = null, fullBleed: Boolean = false,+ isLoading: Boolean = false,+ loadingMessage: String? = null, content: @Composable ColumnScope.() -> Unit = {}, ) = AppScaffold( title = "",@@ -70,6 +72,8 @@ fun SetupScaffold( onClose = onClose, scrollBehavior = scrollBehavior, bottomBar = { SetupFooter(primaryAction, secondaryAction) },+ isLoading = isLoading,+ loadingMessage = loadingMessage, ) { pad -> SetupColumn(pad, title, subtitle, icon, fullBleed, content) }@@ -86,6 +90,8 @@ fun <T : NavKey> SetupScaffold( secondaryAction: SetupAction? = null, scrollBehavior: TopAppBarScrollBehavior? = null, fullBleed: Boolean = false,+ isLoading: Boolean = false,+ loadingMessage: String? = null, content: @Composable ColumnScope.() -> Unit = {}, ) = SetupScaffold( title = title,@@ -97,6 +103,8 @@ fun <T : NavKey> SetupScaffold( secondaryAction = secondaryAction, scrollBehavior = scrollBehavior, fullBleed = fullBleed,+ isLoading = isLoading,+ loadingMessage = loadingMessage, content = content, )
library/ui/src/test/java/com/vayunmathur/library/ui/ScaffoldsSliceTest.kt
diff --git a/library/ui/src/test/java/com/vayunmathur/library/ui/ScaffoldsSliceTest.kt b/library/ui/src/test/java/com/vayunmathur/library/ui/ScaffoldsSliceTest.ktindex 35544dba54..529328f37a 100644--- a/library/ui/src/test/java/com/vayunmathur/library/ui/ScaffoldsSliceTest.kt+++ b/library/ui/src/test/java/com/vayunmathur/library/ui/ScaffoldsSliceTest.kt@@ -184,6 +184,82 @@ class ScaffoldsSliceTest { assertEquals(1, selected) } + @Test fun appScaffoldLoadingReplacesContentButKeepsChrome() {+ rule.setContent {+ AppScaffold(+ title = "Inbox",+ isLoading = true,+ loadingMessage = "Fetching mail",+ scrollBehavior = appBarScrollBehavior(),+ ) { Text("Body text") }+ }+ // Chrome stays, content is not composed, canonical loading message shows.+ rule.onNodeWithText("Inbox").assertIsDisplayed()+ rule.onNodeWithText("Fetching mail").assertIsDisplayed()+ rule.onNodeWithText("Body text").assertDoesNotExist()+ }++ @Test fun appScaffoldNotLoadingShowsContent() {+ rule.setContent {+ AppScaffold(+ title = "Inbox",+ isLoading = false,+ loadingMessage = "Fetching mail",+ scrollBehavior = appBarScrollBehavior(),+ ) { Text("Body text") }+ }+ rule.onNodeWithText("Body text").assertIsDisplayed()+ rule.onNodeWithText("Fetching mail").assertDoesNotExist()+ }++ @Test fun appScaffoldTopBarOverloadLoadingReplacesContent() {+ rule.setContent {+ AppScaffold(topBar = {}, isLoading = true, loadingMessage = "Loading browse") {+ Text("Browse body")+ }+ }+ rule.onNodeWithText("Loading browse").assertIsDisplayed()+ rule.onNodeWithText("Browse body").assertDoesNotExist()+ }++ @Test fun detailScaffoldLoadingReplacesContent() {+ rule.setContent {+ DetailScaffold(+ title = "Profile",+ isLoading = true,+ loadingMessage = "Loading profile",+ ) { Text("Profile body") }+ }+ rule.onNodeWithText("Loading profile").assertIsDisplayed()+ rule.onNodeWithText("Profile body").assertDoesNotExist()+ }++ @Test fun lazyListScaffoldLoadingReplacesList() {+ rule.setContent {+ LazyListScaffold(+ title = "Dashboard",+ isLoading = true,+ loadingMessage = "Loading usage",+ ) {+ item { Text("Usage row") }+ }+ }+ rule.onNodeWithText("Loading usage").assertIsDisplayed()+ rule.onNodeWithText("Usage row").assertDoesNotExist()+ }++ @Test fun setupScaffoldLoadingReplacesContent() {+ rule.setContent {+ SetupScaffold(+ title = "Pair your SIM",+ isLoading = true,+ loadingMessage = "Contacting carrier",+ ) { Text("Setup body") }+ }+ rule.onNodeWithText("Contacting carrier").assertIsDisplayed()+ rule.onNodeWithText("Setup body").assertDoesNotExist()+ }+ @Test fun topAppBarOverlayBackAndActions() { var backs = 0 var shares = 0
lint-rules/AGENTS.md
diff --git a/lint-rules/AGENTS.md b/lint-rules/AGENTS.mdindex 53a58b8b0d..aec4875973 100644--- a/lint-rules/AGENTS.md+++ b/lint-rules/AGENTS.md@@ -12,7 +12,7 @@ ## Overview **Purpose:** Custom Android-lint detectors enforcing repo conventions at build time — the executable form of root `AGENTS.md` §2. Fatal detectors break the build; advisory ones warn.-**Blocking:** every Modern-Apps detector is fatal in the app and library conventions. That includes `ToastUsage` (no `Toast` — use messenger), `DirectComposeAnimation` (no raw animation at call sites), `FileLength`, `DirectAndroidLog` (no direct `android.util.Log`), `DirectBuildDatabase` (subclass `RoomRepository`), `OneComposablePerFile`, `PackageStructure` (closed roots and flat `widget`), `RawScaffoldInApp` (use `AppScaffold`), `Room2Usage` (Room 3 only), `WindowInsetsInReusableComponent` (no padding in `library.ui`), and the comment-hygiene detectors (`CommentedOutCode`, `ExceptionMarkerFormat`, `TodoEvasion` with `CommentOnlyMatcher`).+**Blocking:** every Modern-Apps detector is fatal in the app and library conventions. That includes `ToastUsage` (no `Toast` — use messenger), `DirectComposeAnimation` (no raw animation at call sites), `FileLength`, `DirectAndroidLog` (no direct `android.util.Log`), `DirectBuildDatabase` (subclass `RoomRepository`), `OneComposablePerFile`, `PackageStructure` (closed roots and flat `widget`), `RawScaffoldInApp` (use `AppScaffold`), `ScaffoldLoading` (whole-content loading via the scaffold's `isLoading`), `Room2Usage` (Room 3 only), `WindowInsetsInReusableComponent` (no padding in `library.ui`), and the comment-hygiene detectors (`CommentedOutCode`, `ExceptionMarkerFormat`, `TodoEvasion` with `CommentOnlyMatcher`). **Entry points:** `ModernAppsIssueRegistry.kt` → the detector for your rule → `LintPackageExclusions.kt` for scope. **Gotchas:** New detectors need registry entries + severity decisions (fatal vs advisory is a deliberate call). Fix code to green modules, never relax config (`detekt.yml` rationale is inline per the root card). @@ -24,6 +24,7 @@ - com/vayunmathur/lint/DirectBuildDatabaseDetector.kt — RoomRepository rule - com/vayunmathur/lint/Room2UsageDetector.kt — Room 3 rule - com/vayunmathur/lint/RawScaffoldInAppDetector.kt — AppScaffold rule+- com/vayunmathur/lint/ScaffoldLoadingDetector.kt — scaffold-owned loading rule - com/vayunmathur/lint/PackageStructureDetector.kt — closed-roots rule - com/vayunmathur/lint/OneComposablePerFileDetector.kt - com/vayunmathur/lint/WindowInsetsInReusableComponentDetector.kt
lint-rules/build.gradle.kts
diff --git a/lint-rules/build.gradle.kts b/lint-rules/build.gradle.ktsindex 9820a082ec..bd09409e73 100644--- a/lint-rules/build.gradle.kts+++ b/lint-rules/build.gradle.kts@@ -10,6 +10,11 @@ plugins { dependencies { compileOnly(libs.lint.api) compileOnly(libs.lint.checks)++ testImplementation(libs.lint.api)+ testImplementation(libs.lint.checks)+ testImplementation(libs.lint.tests)+ testImplementation(libs.kotlin.test.junit) } kotlin {
lint-rules/src/main/java/com/vayunmathur/lint/ExceptionMarkerFormatDetector.kt
diff --git a/lint-rules/src/main/java/com/vayunmathur/lint/ExceptionMarkerFormatDetector.kt b/lint-rules/src/main/java/com/vayunmathur/lint/ExceptionMarkerFormatDetector.ktindex a8d7bd81fb..70a95d6075 100644--- a/lint-rules/src/main/java/com/vayunmathur/lint/ExceptionMarkerFormatDetector.kt+++ b/lint-rules/src/main/java/com/vayunmathur/lint/ExceptionMarkerFormatDetector.kt@@ -109,6 +109,22 @@ class ExceptionMarkerFormatDetector : Detector(), SourceCodeScanner { return } + if (text.contains(LOADING_KEYWORD)) {+ if (!text.contains(LOADING_PREFIX)) {+ report(context, node, file, source, base + text.indexOf(LOADING_KEYWORD), LOADING_KEYWORD.length,+ "Malformed Scaffold Loading exception marker: the colon is required and a marker without " ++ "it does NOT opt the file out. Use `// SCAFFOLD LOADING EXCEPTION: <reason>`.")+ return+ }+ val reason = reasonAfter(text, LOADING_PREFIX)+ if (!hasReason(source, comments, index, reason)) {+ report(context, node, file, source, base + text.indexOf(LOADING_PREFIX), LOADING_PREFIX.length,+ "Exception marker without a reason. Append `: <reason>` to " ++ "`// SCAFFOLD LOADING EXCEPTION:` so the opt-out stays reviewable.")+ }+ return+ }+ if (text.contains(TOAST_KEYWORD)) { if (!text.contains(TOAST_PREFIX)) { report(context, node, file, source, base + text.indexOf(TOAST_KEYWORD), TOAST_KEYWORD.length,@@ -201,6 +217,8 @@ class ExceptionMarkerFormatDetector : Detector(), SourceCodeScanner { private const val PACKAGE_KEYWORD = "PACKAGE STRUCTURE EXCEPTION" private const val SCAFFOLD_KEYWORD = "RAW SCAFFOLD EXCEPTION" private const val SCAFFOLD_PREFIX = "// RAW SCAFFOLD EXCEPTION"+ private const val LOADING_KEYWORD = "SCAFFOLD LOADING EXCEPTION"+ private const val LOADING_PREFIX = "// SCAFFOLD LOADING EXCEPTION:" private const val TOAST_KEYWORD = "TOAST EXCEPTION" private const val TOAST_PREFIX = "// TOAST EXCEPTION:" private const val ANIMATION_KEYWORD = "RAW ANIMATION EXCEPTION"@@ -217,7 +235,7 @@ class ExceptionMarkerFormatDetector : Detector(), SourceCodeScanner { missing colon silently does NOT opt the file out, so enforcement disappears \ with no signal. Use the canonical shapes — `// PACKAGE STRUCTURE EXCEPTION \ (JNI)` verbatim, `// RAW SCAFFOLD EXCEPTION: <reason>`, `// TOAST EXCEPTION: \- <reason>`, `// RAW ANIMATION EXCEPTION: <reason>` — each with a non-empty \+ <reason>`, `// RAW ANIMATION EXCEPTION: <reason>`, `// SCAFFOLD LOADING EXCEPTION: <reason>` — each with a non-empty \ reason (which may continue on following `//` lines), so every opt-out stays \ reviewable. """.trimIndent(),
lint-rules/src/main/java/com/vayunmathur/lint/ModernAppsIssueRegistry.kt
diff --git a/lint-rules/src/main/java/com/vayunmathur/lint/ModernAppsIssueRegistry.kt b/lint-rules/src/main/java/com/vayunmathur/lint/ModernAppsIssueRegistry.ktindex d54c86b1dc..979169070f 100644--- a/lint-rules/src/main/java/com/vayunmathur/lint/ModernAppsIssueRegistry.kt+++ b/lint-rules/src/main/java/com/vayunmathur/lint/ModernAppsIssueRegistry.kt@@ -17,6 +17,7 @@ class ModernAppsIssueRegistry : IssueRegistry() { OneComposablePerFileDetector.ISSUE, PackageStructureDetector.ISSUE, RawScaffoldInAppDetector.ISSUE,+ ScaffoldLoadingDetector.ISSUE, Room2UsageDetector.ISSUE, WindowInsetsInReusableComponentDetector.ISSUE, ExceptionMarkerFormatDetector.ISSUE,
lint-rules/src/main/java/com/vayunmathur/lint/ScaffoldLoadingDetector.kt
diff --git a/lint-rules/src/main/java/com/vayunmathur/lint/ScaffoldLoadingDetector.kt b/lint-rules/src/main/java/com/vayunmathur/lint/ScaffoldLoadingDetector.ktnew file mode 100644index 0000000000..709dbf8b07--- /dev/null+++ b/lint-rules/src/main/java/com/vayunmathur/lint/ScaffoldLoadingDetector.kt@@ -0,0 +1,213 @@+package com.vayunmathur.lint++import com.android.tools.lint.detector.api.Category+import com.android.tools.lint.detector.api.Detector+import com.android.tools.lint.detector.api.Implementation+import com.android.tools.lint.detector.api.Issue+import com.android.tools.lint.detector.api.JavaContext+import com.android.tools.lint.detector.api.Scope+import com.android.tools.lint.detector.api.Severity+import com.android.tools.lint.detector.api.SourceCodeScanner+import com.intellij.psi.PsiMethod+import org.jetbrains.kotlin.psi.KtFile+import org.jetbrains.uast.UCallExpression+import org.jetbrains.uast.UElement++/**+ * Flags whole-content loading hand-rolled inside a shared scaffold's content.+ *+ * The loading state belongs to the scaffold object: `AppScaffold` (and the+ * wrappers built on it — `DetailScaffold`, `DetailLazyColumn`,+ * `LazyListScaffold`, `SetupScaffold`) take `isLoading` / `loadingMessage`+ * and render the canonical `LoadingState` instead of the content while it is+ * true. A screen that instead branches inside its own content lambda —+ * `if (loading) LoadingState(...)`, or a centred spinner in a full-size box —+ * re-derives that swap per screen, composes its empty state under the spinner+ * on some of them, and drifts from the one shape.+ *+ * Scope — whole-content only, so legitimate local loading is not flagged:+ * a loading call is reported only when ALL of these hold:+ * - it resolves to `LoadingState`, `LoadingIndicator`,+ * `CircularProgressIndicator` or `ContainedLoadingIndicator` in+ * `com.vayunmathur.library.ui` (or the Material 3 originals behind them);+ * - it sits lexically inside the content lambda of a shared-scaffold call+ * (so a standalone spinner composed *before* any scaffold exists — an+ * early return while a photo/video loads — is not flagged, and neither is+ * one inside a raw-`Scaffold` exception file, which owns its own chrome);+ * - it is whole-content: a `LoadingState` (whole-content by definition), or+ * an indicator whose own modifier or an enclosing container between it+ * and the scaffold fills the content area (`fillMaxSize()` /+ * `fillParentMaxSize()`).+ *+ * Exempt by shape (documented in the report message): determinate indicators+ * (`progress = ...`), sized indicators (a `Modifier.size(...)` slot — the+ * button/row-local spinner), indicators inside a button or a pull-to-refresh+ * box, and section-local indicators that do not fill the content area (a+ * `fillMaxWidth()` box above still-visible content). The shared library+ * (`com.vayunmathur.library.*`) is exempt: the scaffolds are built there.+ *+ * Per-file opt-out: `// SCAFFOLD LOADING EXCEPTION: <reason>`.+ */+class ScaffoldLoadingDetector : Detector(), SourceCodeScanner {++ override fun getApplicableMethodNames(): List<String> = LOADING_CALLS.toList()++ override fun visitMethodCall(context: JavaContext, node: UCallExpression, method: PsiMethod) {+ if (!isLoadingCall(method)) return++ val packageName = context.uastFile?.packageName ?: return+ if (!packageName.startsWith(APP_PACKAGE_PREFIX)) return+ if (isLibraryPackage(packageName)) return++ val ktFile = context.uastFile?.sourcePsi as? KtFile+ if (ktFile != null && CommentOnlyMatcher.containsMarkerInComments(ktFile, EXCEPTION_MARKER)) return++ // Determinate progress is a transfer gauge, not a loading state.+ if (method.parameterList.parameters.any { it.name == "progress" }) return++ val ancestors = ancestorsOf(node)++ // Local slots: a button's own spinner, or pull-to-refresh chrome.+ if (ancestors.any { it is UCallExpression && it.methodName in LOCAL_SLOT_CALLS }) return++ // Must be inside a shared scaffold's content lambda.+ val scaffoldIndex = ancestors.indexOfFirst {+ it is UCallExpression && it.methodName in SCAFFOLD_CALLS+ }+ if (scaffoldIndex == -1) return++ val isWholeContent = when (node.methodName) {+ "LoadingState" -> true+ else -> {+ // A sized indicator is a local slot (button/row spinner).+ if (compact(node.asSourceString()).contains(".size(")) return+ val between = ancestors.subList(0, scaffoldIndex)+ val own = compact(node.asSourceString())+ own.contains(FULL_SIZE) ||+ own.contains(FULL_PARENT_SIZE) ||+ // Only container *calls* count: a lambda/if ancestor's source+ // spans sibling branches that may fill the size for other reasons.+ between.any {+ it is UCallExpression &&+ (compact(it.asSourceString()).contains(FULL_SIZE) ||+ compact(it.asSourceString()).contains(FULL_PARENT_SIZE))+ }+ }+ }+ if (!isWholeContent) return++ context.report(+ ISSUE,+ node,+ context.getLocation(node),+ "Whole-content loading must go through the scaffold: pass " ++ "`isLoading = <loading>` (and `loadingMessage` if the wait needs words) to " ++ "AppScaffold / DetailScaffold / DetailLazyColumn / LazyListScaffold / " ++ "SetupScaffold instead of rendering `${node.methodName}` inside its content. " ++ "Local loading is not this and stays inline: a sized indicator, a determinate " ++ "`progress = ...` indicator, an indicator inside a Button/IconButton or a " ++ "pull-to-refresh box, or a section-local indicator that does not fill the " ++ "content area. If this whole-content loading genuinely cannot go through " ++ "the scaffold, add the `$EXCEPTION_MARKER <reason>` marker comment to the file.",+ )+ }++ /** Whitespace-insensitive source match (lint's whitespace test mode re-spaces code). */+ private fun compact(text: String): String = text.replace(WHITESPACE, "")++ private fun ancestorsOf(node: UElement): List<UElement> {+ val result = mutableListOf<UElement>()+ var current = node.uastParent+ while (current != null) {+ result.add(current)+ current = current.uastParent+ }+ return result+ }++ private fun isLoadingCall(method: PsiMethod): Boolean {+ val containing = method.containingClass?.qualifiedName ?: return false+ return containing.startsWith(LIBRARY_UI_PREFIX) ||+ containing.startsWith(MATERIAL3_PREFIX)+ }++ companion object {+ private const val APP_PACKAGE_PREFIX = "com.vayunmathur."+ private const val LIBRARY_PREFIX = "com.vayunmathur.library"+ private const val LIBRARY_UI_PREFIX = "com.vayunmathur.library.ui"+ private const val MATERIAL3_PREFIX = "androidx.compose.material3"++ const val EXCEPTION_MARKER = "// SCAFFOLD LOADING EXCEPTION:"++ private val WHITESPACE = Regex("\\s+")++ private const val FULL_SIZE = "fillMaxSize()"+ private const val FULL_PARENT_SIZE = "fillParentMaxSize()"++ private val LOADING_CALLS = setOf(+ "LoadingState",+ "LoadingIndicator",+ "CircularProgressIndicator",+ "ContainedLoadingIndicator",+ )++ private val SCAFFOLD_CALLS = setOf(+ "AppScaffold",+ "DetailScaffold",+ "DetailLazyColumn",+ "LazyListScaffold",+ "SetupScaffold",+ "ListPage",+ "ListPageContent",+ )++ /** Composables whose own progress affordance is local, never whole-content. */+ private val LOCAL_SLOT_CALLS = setOf(+ "Button",+ "TextButton",+ "OutlinedButton",+ "FilledTonalButton",+ "ElevatedButton",+ "IconButton",+ "AppPullToRefreshBox",+ "PullToRefreshBox",+ )++ private fun isLibraryPackage(packageName: String): Boolean =+ packageName == LIBRARY_PREFIX || packageName.startsWith("$LIBRARY_PREFIX.")++ val ISSUE: Issue = Issue.create(+ id = "ScaffoldLoading",+ briefDescription = "Whole-content loading rendered inside scaffold content",+ explanation = """+ Whole-content loading belongs to the scaffold object. AppScaffold and the \+ shared wrappers built on it (DetailScaffold, DetailLazyColumn, \+ LazyListScaffold, SetupScaffold) accept `isLoading` / `loadingMessage` and \+ render the canonical LoadingState instead of the content while loading is \+ true, with the screen's bars and chrome left in place. Rendering a \+ LoadingState, or a centred LoadingIndicator / CircularProgressIndicator in \+ a container that fills the content area, inside a scaffold's content lambda \+ re-derives that swap per screen and is flagged here.++ Only whole-content loading is flagged. Local loading stays inline and is \+ exempt by shape: a determinate (`progress = ...`) indicator, a sized \+ indicator (the button/row-local spinner slot), an indicator inside a \+ Button/IconButton or a pull-to-refresh box, a section-local indicator that \+ does not fill the content area, and a standalone indicator composed before \+ any scaffold exists (an early return while content loads). The shared \+ library modules (com.vayunmathur.library.*) are exempt because the \+ scaffolds and the canonical indicators are built there.++ If a whole-content loading state genuinely cannot go through the scaffold, \+ add the marker comment `// SCAFFOLD LOADING EXCEPTION: <reason>` to the file.+ """.trimIndent(),+ category = Category.CORRECTNESS,+ priority = 6,+ severity = Severity.ERROR,+ implementation = Implementation(+ ScaffoldLoadingDetector::class.java,+ Scope.JAVA_FILE_SCOPE,+ ),+ )+ }+}
lint-rules/src/test/java/com/vayunmathur/lint/ScaffoldLoadingDetectorTest.kt
diff --git a/lint-rules/src/test/java/com/vayunmathur/lint/ScaffoldLoadingDetectorTest.kt b/lint-rules/src/test/java/com/vayunmathur/lint/ScaffoldLoadingDetectorTest.ktnew file mode 100644index 0000000000..5ff0e8aee6--- /dev/null+++ b/lint-rules/src/test/java/com/vayunmathur/lint/ScaffoldLoadingDetectorTest.kt@@ -0,0 +1,209 @@+package com.vayunmathur.lint++import com.android.tools.lint.checks.infrastructure.LintDetectorTest+import com.android.tools.lint.checks.infrastructure.TestFile+import com.android.tools.lint.checks.infrastructure.TestFiles.kotlin+import com.android.tools.lint.detector.api.Detector+import com.android.tools.lint.detector.api.Issue+import org.junit.Test+import org.junit.runner.RunWith+import org.junit.runners.JUnit4++@RunWith(JUnit4::class)+class ScaffoldLoadingDetectorTest : LintDetectorTest() {++ override fun getDetector(): Detector = ScaffoldLoadingDetector()++ override fun getIssues(): List<Issue> = listOf(ScaffoldLoadingDetector.ISSUE)++ @Test+ fun loadingStateInsideAppScaffoldIsFlagged() {+ lint().files(UI_STUBS, MODIFIER_STUB, LAYOUT_STUBS, COMPOSABLE_STUB, kotlin(+ """+ package com.vayunmathur.example.ui+ import androidx.compose.runtime.Composable+ import com.vayunmathur.library.ui.AppScaffold+ import com.vayunmathur.library.ui.LoadingState+ @Composable fun Screen(loading: Boolean) {+ AppScaffold(title = "T") {+ if (loading) LoadingState()+ }+ }+ """.trimIndent(),+ )).run().expectErrorCount(1)+ }++ @Test+ fun fullSizeIndicatorInsideAppScaffoldIsFlagged() {+ lint().files(UI_STUBS, MODIFIER_STUB, LAYOUT_STUBS, COMPOSABLE_STUB, kotlin(+ """+ package com.vayunmathur.example.ui+ import androidx.compose.foundation.layout.Box+ import androidx.compose.runtime.Composable+ import androidx.compose.ui.Modifier+ import com.vayunmathur.library.ui.AppScaffold+ import com.vayunmathur.library.ui.LoadingIndicator+ @Composable fun Screen(loading: Boolean) {+ AppScaffold(title = "T") {+ if (loading) Box(Modifier.fillMaxSize()) { LoadingIndicator() }+ }+ }+ """.trimIndent(),+ )).run().expectErrorCount(1)+ }++ @Test+ fun scaffoldLoadingParameterIsClean() {+ lint().files(UI_STUBS, MODIFIER_STUB, LAYOUT_STUBS, COMPOSABLE_STUB, kotlin(+ """+ package com.vayunmathur.example.ui+ import androidx.compose.foundation.layout.Box+ import androidx.compose.runtime.Composable+ import androidx.compose.ui.Modifier+ import com.vayunmathur.library.ui.AppScaffold+ @Composable fun Screen(loading: Boolean) {+ AppScaffold(title = "T", isLoading = loading) {+ Box(Modifier.fillMaxSize()) { }+ }+ }+ """.trimIndent(),+ )).run().expectClean()+ }++ @Test+ fun sectionLocalIndicatorIsClean() {+ lint().files(UI_STUBS, MODIFIER_STUB, LAYOUT_STUBS, COMPOSABLE_STUB, kotlin(+ """+ package com.vayunmathur.example.ui+ import androidx.compose.foundation.layout.Box+ import androidx.compose.runtime.Composable+ import androidx.compose.ui.Modifier+ import com.vayunmathur.library.ui.AppScaffold+ import com.vayunmathur.library.ui.LoadingIndicator+ @Composable fun Screen(loading: Boolean) {+ AppScaffold(title = "T") {+ if (loading) Box(Modifier.fillMaxWidth()) { LoadingIndicator() }+ }+ }+ """.trimIndent(),+ )).run().expectClean()+ }++ @Test+ fun sizedDeterminateAndButtonIndicatorsAreClean() {+ lint().files(UI_STUBS, MODIFIER_STUB, LAYOUT_STUBS, COMPOSABLE_STUB, kotlin(+ """+ package com.vayunmathur.example.ui+ import androidx.compose.runtime.Composable+ import androidx.compose.ui.Modifier+ import com.vayunmathur.library.ui.AppScaffold+ import com.vayunmathur.library.ui.Button+ import com.vayunmathur.library.ui.CircularProgressIndicator+ import com.vayunmathur.library.ui.LoadingIndicator+ @Composable fun Screen(saving: Boolean) {+ AppScaffold(title = "T") {+ if (saving) CircularProgressIndicator(Modifier.size(16))+ LoadingIndicator(progress = { 0.5f })+ Button(onClick = {}) { CircularProgressIndicator() }+ }+ }+ """.trimIndent(),+ )).run().expectClean()+ }++ @Test+ fun standaloneIndicatorBeforeScaffoldIsClean() {+ lint().files(UI_STUBS, MODIFIER_STUB, LAYOUT_STUBS, COMPOSABLE_STUB, kotlin(+ """+ package com.vayunmathur.example.ui+ import androidx.compose.foundation.layout.Box+ import androidx.compose.runtime.Composable+ import androidx.compose.ui.Modifier+ import com.vayunmathur.library.ui.AppScaffold+ import com.vayunmathur.library.ui.LoadingIndicator+ @Composable fun Screen(photo: String?) {+ if (photo == null) {+ Box(Modifier.fillMaxSize()) { LoadingIndicator() }+ return+ }+ AppScaffold(title = "T") { Box(Modifier.fillMaxSize()) { } }+ }+ """.trimIndent(),+ )).run().expectClean()+ }++ @Test+ fun exceptionMarkerOptsOut() {+ lint().files(UI_STUBS, MODIFIER_STUB, LAYOUT_STUBS, COMPOSABLE_STUB, kotlin(+ """+ package com.vayunmathur.example.ui+ // SCAFFOLD LOADING EXCEPTION: pager pages own their loading chrome+ import androidx.compose.runtime.Composable+ import com.vayunmathur.library.ui.AppScaffold+ import com.vayunmathur.library.ui.LoadingState+ @Composable fun Screen(loading: Boolean) {+ AppScaffold(title = "T") {+ if (loading) LoadingState()+ }+ }+ """.trimIndent(),+ )).run().expectClean()+ }++ companion object {+ private val COMPOSABLE_STUB: TestFile = kotlin(+ "src/androidx/compose/runtime/Composable.kt",+ """+ package androidx.compose.runtime+ annotation class Composable+ """.trimIndent(),+ )++ private val MODIFIER_STUB: TestFile = kotlin(+ "src/androidx/compose/ui/Modifier.kt",+ """+ package androidx.compose.ui+ open class Modifier {+ fun fillMaxSize(): Modifier = this+ fun fillMaxWidth(): Modifier = this+ fun size(dp: Int): Modifier = this+ fun padding(values: Any): Modifier = this+ companion object : Modifier()+ }+ """.trimIndent(),+ )++ private val LAYOUT_STUBS: TestFile = kotlin(+ "src/androidx/compose/foundation/layout/Layout.kt",+ """+ package androidx.compose.foundation.layout+ import androidx.compose.runtime.Composable+ import androidx.compose.ui.Modifier+ class PaddingValues+ @Composable fun Box(modifier: Modifier = Modifier, content: @Composable () -> Unit) {}+ """.trimIndent(),+ )++ private val UI_STUBS: TestFile = kotlin(+ "src/com/vayunmathur/library/ui/UiStubs.kt",+ """+ package com.vayunmathur.library.ui+ import androidx.compose.foundation.layout.PaddingValues+ import androidx.compose.runtime.Composable+ import androidx.compose.ui.Modifier+ @Composable fun AppScaffold(+ title: String,+ isLoading: Boolean = false,+ loadingMessage: String? = null,+ content: @Composable (PaddingValues) -> Unit,+ ) {}+ @Composable fun LoadingState(modifier: Modifier = Modifier, message: String? = null) {}+ @Composable fun LoadingIndicator(modifier: Modifier = Modifier) {}+ @Composable fun LoadingIndicator(progress: () -> Float, modifier: Modifier = Modifier) {}+ @Composable fun CircularProgressIndicator(modifier: Modifier = Modifier) {}+ @Composable fun CircularProgressIndicator(progress: () -> Float, modifier: Modifier = Modifier) {}+ @Composable fun Button(onClick: () -> Unit, content: @Composable () -> Unit) {}+ """.trimIndent(),+ )+ }+}
screentime/src/main/java/com/vayunmathur/screentime/ui/DashboardScreen.kt
diff --git a/screentime/src/main/java/com/vayunmathur/screentime/ui/DashboardScreen.kt b/screentime/src/main/java/com/vayunmathur/screentime/ui/DashboardScreen.ktindex faf28e2234..fceafb270d 100644--- a/screentime/src/main/java/com/vayunmathur/screentime/ui/DashboardScreen.kt+++ b/screentime/src/main/java/com/vayunmathur/screentime/ui/DashboardScreen.kt@@ -27,7 +27,6 @@ import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp import com.vayunmathur.library.ui.IconArrowForward-import com.vayunmathur.library.ui.LoadingState import com.vayunmathur.library.ui.IconBack import com.vayunmathur.library.ui.LazyListScaffold import com.vayunmathur.library.ui.MaterialTheme@@ -73,6 +72,8 @@ fun DashboardScreen(state: ScreenTimeUiState, actions: DashboardActions) { LazyListScaffold( title = stringResource(R.string.app_name), horizontalPadding = 0.dp,+ isLoading = state.loading,+ loadingMessage = stringResource(R.string.apps_loading), ) { item { PeriodToggle(state.period, actions.onSetPeriod) } @@ -81,7 +82,6 @@ fun DashboardScreen(state: ScreenTimeUiState, actions: DashboardActions) { } when {- state.loading -> item { LoadingState(modifier = Modifier.fillParentMaxSize()) } !state.hasUsageAccess -> item { SettingsSection { SettingsRow(