mirror of
https://github.com/readrops/Readrops.git
synced 2025-02-01 19:26:49 +01:00
Fix pull to refresh not reachable when no item is displayted
This commit is contained in:
parent
1a37401139
commit
d76200e292
@ -1,12 +1,19 @@
|
||||
package com.readrops.app.compose.timelime
|
||||
|
||||
import androidx.compose.foundation.gestures.scrollable
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.items
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import cafe.adriel.voyager.androidx.AndroidScreen
|
||||
import com.google.accompanist.swiperefresh.SwipeRefresh
|
||||
@ -29,15 +36,12 @@ class TimelineScreen : AndroidScreen() {
|
||||
onRefresh = {
|
||||
viewModel.refreshTimeline()
|
||||
},
|
||||
modifier = Modifier.fillMaxSize()
|
||||
) {
|
||||
when (state) {
|
||||
is TimelineState.ErrorState -> {
|
||||
Text(text = "error")
|
||||
}
|
||||
|
||||
TimelineState.InitialState -> {}
|
||||
is TimelineState.LoadedState -> {
|
||||
val items = (state as TimelineState.LoadedState).items
|
||||
|
||||
if (items.isNotEmpty()) {
|
||||
LazyColumn {
|
||||
items(
|
||||
items = (state as TimelineState.LoadedState).items
|
||||
@ -45,8 +49,30 @@ class TimelineScreen : AndroidScreen() {
|
||||
TimelineItem()
|
||||
}
|
||||
}
|
||||
} else {
|
||||
NoItemPlaceholder()
|
||||
}
|
||||
}
|
||||
else -> {
|
||||
NoItemPlaceholder()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@Composable
|
||||
fun NoItemPlaceholder() {
|
||||
val scrollState = rememberScrollState()
|
||||
|
||||
Column(
|
||||
verticalArrangement = Arrangement.Center,
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
modifier = Modifier.fillMaxSize()
|
||||
.verticalScroll(scrollState)
|
||||
) {
|
||||
Text(
|
||||
text = "No item",
|
||||
style = MaterialTheme.typography.displayMedium
|
||||
)
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user