Skip to content

Commit 85b8d82

Browse files
authored
Merge pull request #598 from kiwicom/pull-to-refresh
Rework catalog's demo to M3's PullToRefresh & fix M3 surface color mappings
2 parents de24e7c + c645798 commit 85b8d82

File tree

3 files changed

+22
-24
lines changed

3 files changed

+22
-24
lines changed

catalog/build.gradle.kts

-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@ dependencies {
137137
implementation(libs.compose.animation)
138138
implementation(libs.compose.foundation)
139139
implementation(libs.compose.layout)
140-
implementation(libs.compose.material) // pull-refresh, when available in M3, migrate
141140
implementation(libs.compose.material3)
142141
implementation(libs.compose.materialIconsExtended)
143142
implementation(libs.compose.navigation)

catalog/src/main/java/kiwi/orbit/compose/catalog/screens/TopAppBarScreensLarge.kt

+15-23
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,13 @@ import androidx.compose.foundation.layout.Row
66
import androidx.compose.foundation.layout.padding
77
import androidx.compose.foundation.layout.size
88
import androidx.compose.foundation.shape.CircleShape
9-
import androidx.compose.material.ExperimentalMaterialApi
10-
import androidx.compose.material.pullrefresh.PullRefreshIndicator
11-
import androidx.compose.material.pullrefresh.pullRefresh
12-
import androidx.compose.material.pullrefresh.rememberPullRefreshState
9+
import androidx.compose.material3.ExperimentalMaterial3Api
10+
import androidx.compose.material3.pulltorefresh.PullToRefreshContainer
11+
import androidx.compose.material3.pulltorefresh.rememberPullToRefreshState
1312
import androidx.compose.runtime.Composable
13+
import androidx.compose.runtime.LaunchedEffect
1414
import androidx.compose.runtime.getValue
1515
import androidx.compose.runtime.mutableIntStateOf
16-
import androidx.compose.runtime.mutableStateOf
17-
import androidx.compose.runtime.rememberCoroutineScope
1816
import androidx.compose.runtime.saveable.rememberSaveable
1917
import androidx.compose.runtime.setValue
2018
import androidx.compose.ui.Alignment
@@ -40,7 +38,6 @@ import kiwi.orbit.compose.ui.controls.TopAppBarLarge
4038
import kiwi.orbit.compose.ui.controls.TopAppBarScrollBehavior
4139
import kiwi.orbit.compose.ui.foundation.ContentEmphasis
4240
import kotlinx.coroutines.delay
43-
import kotlinx.coroutines.launch
4441

4542
@Composable
4643
internal fun TopAppBarLargeScreen(
@@ -202,28 +199,26 @@ internal fun TopAppBarLargeCustomContentScreen(
202199
)
203200
}
204201

205-
@OptIn(ExperimentalMaterialApi::class)
202+
@OptIn(ExperimentalMaterial3Api::class)
206203
@Composable
207204
internal fun TopAppBarLargePullRefreshScreen(
208205
onNavigateUp: () -> Unit,
209206
) {
210-
val refreshScope = rememberCoroutineScope()
211-
var refreshing by rememberSaveable { mutableStateOf(false) }
212207
var i by rememberSaveable { mutableIntStateOf(0) }
213208

214-
fun refresh() = refreshScope.launch {
215-
refreshing = true
216-
delay(1500)
217-
i += 1
218-
refreshing = false
209+
val pullRefreshState = rememberPullToRefreshState()
210+
if (pullRefreshState.isRefreshing) {
211+
LaunchedEffect(Unit) {
212+
delay(1500)
213+
i += 1
214+
pullRefreshState.endRefresh()
215+
}
219216
}
220-
221217
val scrollBehavior = TopAppBarScrollBehavior.exitUntilCollapsed()
222-
val pullRefreshState = rememberPullRefreshState(refreshing, ::refresh)
223218

224219
Scaffold(
225220
modifier = Modifier
226-
.pullRefresh(pullRefreshState)
221+
.nestedScroll(pullRefreshState.nestedScrollConnection)
227222
.nestedScroll(scrollBehavior.nestedScrollConnection),
228223
topBar = {
229224
TopAppBarLarge(
@@ -236,13 +231,10 @@ internal fun TopAppBarLargePullRefreshScreen(
236231
content = {
237232
Box {
238233
CustomContentPlaceholder(it, "Custom content $i")
239-
PullRefreshIndicator(
240-
refreshing = refreshing,
234+
PullToRefreshContainer(
241235
state = pullRefreshState,
242236
contentColor = OrbitTheme.colors.primary.normal,
243-
modifier = Modifier
244-
.padding(it)
245-
.align(Alignment.TopCenter),
237+
modifier = Modifier.align(Alignment.TopCenter),
246238
)
247239
}
248240
},

ui/src/androidMain/kotlin/kiwi/orbit/compose/ui/foundation/Colors.kt

+7
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,13 @@ public class Colors(
339339
outline = surface.strong,
340340
outlineVariant = surface.normal,
341341
scrim = surface.strong,
342+
surfaceBright = Color.Unspecified,
343+
surfaceDim = Color.Unspecified,
344+
surfaceContainerHighest = surface.main,
345+
surfaceContainerHigh = surface.main,
346+
surfaceContainer = surface.main,
347+
surfaceContainerLow = surface.main,
348+
surfaceContainerLowest = surface.main,
342349
)
343350
}
344351

0 commit comments

Comments
 (0)