@@ -41,6 +41,7 @@ import androidx.compose.material3.pulltorefresh.PullToRefreshBox
4141import androidx.compose.runtime.Composable
4242import androidx.compose.runtime.LaunchedEffect
4343import androidx.compose.runtime.getValue
44+ import androidx.compose.runtime.key
4445import androidx.compose.runtime.mutableStateOf
4546import androidx.compose.runtime.remember
4647import androidx.compose.runtime.rememberCoroutineScope
@@ -210,23 +211,25 @@ private fun NotesNavigation(
210211 if (loadedAccounts == null ) {
211212 LoadingScreen ()
212213 } else if (noteId != null ) {
213- NoteDetailScreen (
214- component = component,
215- localId = noteId,
216- heading = selectedHeading,
217- navigationRequest = navigationRequest,
218- onBackToList = {
219- selectedNoteId = null
220- selectedHeading = null
221- noteHistory = emptyList()
222- },
223- onOpen = { destination ->
224- if (noteId != destination.localId) noteHistory = noteHistory + noteId
225- selectedNoteId = destination.localId
226- selectedHeading = destination.heading
227- navigationRequest++
228- }
229- )
214+ key(noteId) {
215+ NoteDetailScreen (
216+ component = component,
217+ localId = noteId,
218+ heading = selectedHeading,
219+ navigationRequest = navigationRequest,
220+ onBackToList = {
221+ selectedNoteId = null
222+ selectedHeading = null
223+ noteHistory = emptyList()
224+ },
225+ onOpen = { destination ->
226+ if (noteId != destination.localId) noteHistory = noteHistory + noteId
227+ selectedNoteId = destination.localId
228+ selectedHeading = destination.heading
229+ navigationRequest++
230+ }
231+ )
232+ }
230233 } else if (loadedAccounts.isEmpty()) {
231234 AccountOnboarding (importState, onImportAccount)
232235 } else {
@@ -858,8 +861,9 @@ private fun NoteDetailScreen(
858861 if (top != null ) {
859862 scope.launch {
860863 // The Android view is laid out before Compose
861- // updates the containing scroll range.
862- withFrameNanos { }
864+ // updates the containing scroll range. Wait
865+ // through its follow-up measurement frame.
866+ repeat(2 ) { withFrameNanos { } }
863867 scrollState.scrollTo(top)
864868 pendingHeading = null
865869 }
0 commit comments