Skip to content

Commit

Permalink
Merge pull request #517 from arkivanov/fix-page-swipe-with-two-fingers
Browse files Browse the repository at this point in the history
Fixed current page not displayed when swiped through with two fingers
  • Loading branch information
arkivanov authored Nov 5, 2023
2 parents f03d0b2 + fd867c0 commit e43953a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.arkivanov.decompose

@InternalDecomposeApi
class Ref<T>(var value: T)
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import com.arkivanov.decompose.ExperimentalDecomposeApi
import com.arkivanov.decompose.Ref
import com.arkivanov.decompose.extensions.compose.jetbrains.subscribeAsState
import com.arkivanov.decompose.hashString
import com.arkivanov.decompose.router.pages.ChildPages
Expand Down Expand Up @@ -90,7 +91,13 @@ fun <T : Any> Pages(
{ childPages.items[it].configuration.hashString() },
) { pageIndex ->
val item = childPages.items[pageIndex]
val page = remember(item.configuration) { item.instance }

val pageRef = remember(item.configuration) { Ref(item.instance) }
if (item.instance != null) {
pageRef.value = item.instance
}

val page = pageRef.value
if (page != null) {
pageContent(pageIndex, page)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import com.arkivanov.decompose.ExperimentalDecomposeApi
import com.arkivanov.decompose.InternalDecomposeApi
import com.arkivanov.decompose.Ref
import com.arkivanov.decompose.extensions.compose.jetpack.subscribeAsState
import com.arkivanov.decompose.hashString
import com.arkivanov.decompose.router.pages.ChildPages
Expand Down Expand Up @@ -92,7 +93,13 @@ fun <T : Any> Pages(
{ childPages.items[it].configuration.hashString() },
) { pageIndex ->
val item = childPages.items[pageIndex]
val page = remember(item.configuration) { item.instance }

val pageRef = remember(item.configuration) { Ref(item.instance) }
if (item.instance != null) {
pageRef.value = item.instance
}

val page = pageRef.value
if (page != null) {
pageContent(pageIndex, page)
}
Expand Down

0 comments on commit e43953a

Please sign in to comment.