Skip to content

Commit 6cab035

Browse files
committed
Connect drawer: the content is back at the top whenever the drawer closes
The reset watched the sheet's current value and fired one animateScrollTo when it flipped to the peek. On the device it never took: reopening the drawer after closing it by the handle, by the Connect tab or by a fling showed the content where it had been left, so the collapsed peek showed the wrong rows. Watch the sheet's target instead, which flips as soon as the collapse is under way, and keep asking, one attempt per frame, until the content is at the top; an attempt lost to a drag or fling still holding the content's scroll is simply retried. Verified on the S21 for all three ways of closing.
1 parent d036368 commit 6cab035

1 file changed

Lines changed: 21 additions & 6 deletions

File tree

app/app/src/main/java/com/bringyour/network/ui/connect/ConnectScreen.kt

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import androidx.compose.runtime.remember
4040
import androidx.compose.runtime.rememberCoroutineScope
4141
import androidx.compose.runtime.setValue
4242
import androidx.compose.runtime.snapshotFlow
43+
import androidx.compose.runtime.withFrameNanos
4344
import androidx.compose.ui.Alignment
4445
import androidx.compose.ui.Modifier
4546
import androidx.compose.ui.graphics.Color
@@ -74,6 +75,8 @@ import com.bringyour.network.ui.theme.SheetBlack
7475
import com.bringyour.sdk.ContractStatus
7576
import com.bringyour.sdk.DeviceLocal
7677
import kotlinx.coroutines.delay
78+
import kotlinx.coroutines.CancellationException
79+
import kotlinx.coroutines.isActive
7780
import kotlinx.coroutines.launch
7881

7982
@OptIn(ExperimentalMaterial3Api::class)
@@ -325,13 +328,25 @@ fun ConnectActionsSheetScaffold(
325328
// drawer, and at 24dp on phones it matches the iOS expanded spacing
326329
val belowFoldGap = 24.dp + unconsumedBottomInset
327330

328-
// when the sheet settles back to the peek, reset the content to the top so
329-
// the peek always shows the top of the actions (matches the iOS drawer)
331+
// When the sheet heads back to the peek, reset the content to the top so
332+
// the peek always shows the top of the actions (matches the iOS drawer).
333+
// The target flips as soon as the collapse is under way. A one-shot
334+
// animateScrollTo was lost whenever something held the content's scroll
335+
// at that moment (a drag still in flight, a fling running out), so this
336+
// keeps asking, one attempt per frame, until the content is at the top.
330337
LaunchedEffect(scaffoldState.bottomSheetState) {
331-
snapshotFlow { scaffoldState.bottomSheetState.currentValue }
332-
.collect { value ->
333-
if (value == SheetValue.PartiallyExpanded) {
334-
scrollState.animateScrollTo(0)
338+
snapshotFlow { scaffoldState.bottomSheetState.targetValue }
339+
.collect { target ->
340+
if (target != SheetValue.PartiallyExpanded) {
341+
return@collect
342+
}
343+
while (scrollState.value > 0 && isActive) {
344+
try {
345+
scrollState.animateScrollTo(0)
346+
} catch (e: CancellationException) {
347+
if (!isActive) throw e
348+
withFrameNanos { }
349+
}
335350
}
336351
}
337352
}

0 commit comments

Comments
 (0)