Skip to content

Commit

Permalink
Added BackHandler implementation to the Android InternalNavContainer …
Browse files Browse the repository at this point in the history
…functions and made ComposeStackNavigatorByContent.goBack() function not Composable
  • Loading branch information
chRyNaN committed Jan 1, 2022
1 parent 288254d commit 04cb5cb
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions navigation-compose/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ kotlin {
dependencies {
implementation(compose.ui)
implementation(compose.material)
implementation("androidx.activity:activity-compose:1.4.0")
}
}
val jsMain by getting {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.chrynan.navigation.compose

import androidx.activity.compose.BackHandler
import androidx.compose.foundation.layout.Box
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
Expand All @@ -22,6 +23,8 @@ internal actual fun <Scope, Key> InternalNavContainer(
scope.content(contentKey)
}
}

BackHandler { navigator.goBack() }
}

@Composable
Expand All @@ -37,4 +40,6 @@ internal actual fun <Scope, Key, NavigationScope : ComposeNavigationKeyScope<Key
scope.content(contentKey)
}
}

BackHandler { navigator.goBack() }
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ interface ComposeStackNavigator<T> : ComposeNavigator<T> {
interface ComposeStackNavigatorByContent<T> : ComposeStackNavigator<T>,
ComposeNavigatorByContent<T> {

@Composable
fun goBack(): Boolean

companion object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ class ComposeNavigatorByContentViewModel<Scope, Key> internal constructor(
}
}

@Composable
override fun goBack(): Boolean {
val wentBack = canGoBack()

Expand Down

0 comments on commit 04cb5cb

Please sign in to comment.