Skip to content

Commit

Permalink
Added NavContainer with Modifier parameter to the common source set
Browse files Browse the repository at this point in the history
  • Loading branch information
chRyNaN committed Oct 8, 2022
1 parent c20d672 commit 3b58fa3
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 68 deletions.
18 changes: 1 addition & 17 deletions navigation-compose/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,8 @@ kotlin {
api(project(":navigation-core"))

implementation(compose.runtime)
}
}
val jvmMain by getting {
dependencies {
implementation(compose.ui)
implementation(compose.material)
}
}
val androidMain by getting {
dependencies {
implementation(compose.ui)
implementation(compose.material)
implementation("androidx.activity:activity-compose:1.6.0")
}
}
val jsMain by getting {
dependencies {
implementation(compose.web.core)
implementation(compose.foundation)
}
}
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.chrynan.navigation.compose

import androidx.compose.foundation.layout.Box
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import com.chrynan.navigation.ExperimentalNavigationApi
import com.chrynan.navigation.NavigationContext
import com.chrynan.navigation.NavigationDestination
Expand Down Expand Up @@ -28,3 +30,32 @@ fun <Destination : NavigationDestination, Context : NavigationContext<Destinatio

content(ComposeNavigationScope, context.value, destination.value)
}

/**
* A [Composable] that listens to navigation context and destination changes from the provided [navigator] and calls
* the provided [content] [Composable] function with the latest values.
*
* Example usage:
* ```kotlin
* NavContainer(
* navigator = navigator,
* modifier = modifier
* ) { context, destination ->
* Text("context = $context; destination = $destination")
* }
* ```
*/
@Composable
@ExperimentalNavigationApi
fun <Destination : NavigationDestination, Context : NavigationContext<Destination>> NavContainer(
navigator: Navigator<Destination, Context>,
modifier: Modifier,
content: @Composable ComposeNavigationScope.(context: Context, destination: Destination) -> Unit
) {
val context = navigator.state.currentContextAsState()
val destination = navigator.state.currentDestinationAsState()

Box(modifier = modifier) {
content(ComposeNavigationScope, context.value, destination.value)
}
}

This file was deleted.

0 comments on commit 3b58fa3

Please sign in to comment.