-
-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'compose-1.1' into compose-1.2
- Loading branch information
Showing
68 changed files
with
1,752 additions
and
13 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
plugins { | ||
id("com.android.library") | ||
kotlin("android") | ||
} | ||
|
||
apply(from = "${rootProject.projectDir}/publish.gradle") | ||
|
||
android { | ||
|
||
compileSdk = libs.versions.compileSdk.get().toIntOrNull() | ||
|
||
defaultConfig { | ||
minSdk = libs.versions.minSdk.get().toIntOrNull() | ||
targetSdk = libs.versions.targetSdk.get().toIntOrNull() | ||
|
||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" | ||
consumerProguardFiles.add(File("consumer-rules.pro")) | ||
} | ||
|
||
buildTypes { | ||
release { | ||
isMinifyEnabled = false | ||
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro") | ||
} | ||
} | ||
|
||
compileOptions { | ||
sourceCompatibility = JavaVersion.VERSION_1_8 | ||
targetCompatibility = JavaVersion.VERSION_1_8 | ||
} | ||
|
||
kotlinOptions { | ||
jvmTarget = "1.8" | ||
} | ||
|
||
buildFeatures { | ||
compose = true | ||
} | ||
|
||
composeOptions { | ||
kotlinCompilerExtensionVersion = libs.versions.composeCompiler.get() | ||
} | ||
} | ||
|
||
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach { | ||
kotlinOptions.freeCompilerArgs += "-opt-in=kotlin.RequiresOptIn" | ||
} | ||
|
||
dependencies { | ||
api(project(mapOf("path" to ":compose-destinations"))) | ||
|
||
api(libs.wear.compose.navigation) | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
POM_ARTIFACT_ID=wear-core | ||
POM_NAME=wear-core |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle.kts. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.ramcosta.composedestinations.wear"> | ||
|
||
</manifest> |
160 changes: 160 additions & 0 deletions
160
...estinations-wear/src/main/java/com/ramcosta/composedestinations/wear/WearNavHostEngine.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
package com.ramcosta.composedestinations.wear | ||
|
||
import android.annotation.SuppressLint | ||
import androidx.compose.animation.ExperimentalAnimationApi | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.ui.Modifier | ||
import androidx.navigation.* | ||
import androidx.wear.compose.navigation.* | ||
import com.ramcosta.composedestinations.annotation.InternalDestinationsApi | ||
import com.ramcosta.composedestinations.manualcomposablecalls.DestinationLambda | ||
import com.ramcosta.composedestinations.manualcomposablecalls.ManualComposableCalls | ||
import com.ramcosta.composedestinations.navigation.DependenciesContainerBuilder | ||
import com.ramcosta.composedestinations.rememberNavHostEngine | ||
import com.ramcosta.composedestinations.scope.DestinationScopeImpl | ||
import com.ramcosta.composedestinations.spec.* | ||
|
||
/** | ||
* Returns the [WearNavHostEngine] to be used with Wear OS apps. | ||
*/ | ||
@Composable | ||
fun rememberWearNavHostEngine( | ||
state: SwipeDismissableNavHostState = rememberSwipeDismissableNavHostState(), | ||
): NavHostEngine { | ||
val defaultNavHostEngine = rememberNavHostEngine() | ||
|
||
return remember { | ||
WearNavHostEngine(defaultNavHostEngine, state) | ||
} | ||
} | ||
|
||
internal class WearNavHostEngine( | ||
private val defaultNavHostEngine: NavHostEngine, | ||
private val state: SwipeDismissableNavHostState, | ||
) : NavHostEngine { | ||
|
||
override val type = NavHostEngine.Type.WEAR | ||
|
||
@Composable | ||
override fun rememberNavController( | ||
vararg navigators: Navigator<out NavDestination> | ||
) = | ||
androidx.navigation.compose.rememberNavController(remember { WearNavigator() }, *navigators) | ||
|
||
@Composable | ||
override fun NavHost( | ||
modifier: Modifier, | ||
route: String, | ||
startRoute: Route, | ||
navController: NavHostController, | ||
builder: NavGraphBuilder.() -> Unit | ||
) { | ||
SwipeDismissableNavHost( | ||
navController = navController, | ||
startDestination = startRoute.route, | ||
modifier = modifier, | ||
route = route, | ||
state = state, | ||
builder = builder | ||
) | ||
} | ||
|
||
override fun NavGraphBuilder.navigation( | ||
navGraph: NavGraphSpec, | ||
builder: NavGraphBuilder.() -> Unit | ||
) { | ||
with(defaultNavHostEngine) { navigation(navGraph, builder) } | ||
} | ||
|
||
@OptIn(ExperimentalAnimationApi::class, InternalDestinationsApi::class) | ||
override fun <T> NavGraphBuilder.composable( | ||
destination: DestinationSpec<T>, | ||
navController: NavHostController, | ||
dependenciesContainerBuilder: @Composable DependenciesContainerBuilder<*>.() -> Unit, | ||
manualComposableCalls: ManualComposableCalls, | ||
) { | ||
when (destination.style) { | ||
is DestinationStyle.Runtime, | ||
is DestinationStyle.Default -> { | ||
addComposable( | ||
destination, | ||
navController, | ||
dependenciesContainerBuilder, | ||
manualComposableCalls | ||
) | ||
} | ||
|
||
is DestinationStyle.Activity -> { | ||
with(defaultNavHostEngine) { | ||
composable(destination, navController, dependenciesContainerBuilder, manualComposableCalls) | ||
} | ||
} | ||
|
||
is DestinationStyle.Dialog, | ||
is DestinationStyle.Animated, | ||
is DestinationStyle.BottomSheet -> { | ||
throw IllegalStateException("${destination.style.javaClass.name} cannot be used on Wear OS version of the core library!") | ||
} | ||
} | ||
} | ||
|
||
private fun <T> NavGraphBuilder.addComposable( | ||
destination: DestinationSpec<T>, | ||
navController: NavHostController, | ||
dependenciesContainerBuilder: @Composable DependenciesContainerBuilder<*>.() -> Unit, | ||
manualComposableCalls: ManualComposableCalls, | ||
) { | ||
@SuppressLint("RestrictedApi") | ||
val contentLambda = manualComposableCalls[destination.baseRoute] | ||
|
||
composable( | ||
route = destination.route, | ||
arguments = destination.arguments, | ||
deepLinks = destination.deepLinks | ||
) { navBackStackEntry -> | ||
CallComposable( | ||
destination, | ||
navController, | ||
navBackStackEntry, | ||
dependenciesContainerBuilder, | ||
contentLambda | ||
) | ||
} | ||
} | ||
|
||
internal class WearDestinationScope<T>( | ||
destination: DestinationSpec<T>, | ||
navBackStackEntry: NavBackStackEntry, | ||
navController: NavController, | ||
) : DestinationScopeImpl<T>( | ||
destination, | ||
navBackStackEntry, | ||
navController, | ||
) | ||
|
||
@Suppress("UNCHECKED_CAST") | ||
@Composable | ||
private fun <T> CallComposable( | ||
destination: DestinationSpec<T>, | ||
navController: NavHostController, | ||
navBackStackEntry: NavBackStackEntry, | ||
dependenciesContainerBuilder: @Composable DependenciesContainerBuilder<*>.() -> Unit, | ||
contentLambda: DestinationLambda<*>? | ||
) { | ||
val scope = remember { | ||
WearDestinationScope( | ||
destination, | ||
navBackStackEntry, | ||
navController | ||
) | ||
} | ||
|
||
if (contentLambda == null) { | ||
with(destination) { scope.Content(dependenciesContainerBuilder) } | ||
} else { | ||
contentLambda as DestinationLambda<T> | ||
contentLambda(scope) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
5 changes: 2 additions & 3 deletions
5
playground-shared/build.gradle.kts → playground-core/build.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,9 @@ | ||
plugins { | ||
id("java-library") | ||
id("kotlin") | ||
kotlin("plugin.serialization") | ||
id("org.jetbrains.kotlin.jvm") | ||
} | ||
|
||
java { | ||
sourceCompatibility = JavaVersion.VERSION_1_8 | ||
targetCompatibility = JavaVersion.VERSION_1_8 | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
.../samples/playgroundshared/BlogPostArgs.kt → .../ramcosta/playground/core/BlogPostArgs.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../playgroundshared/WithDefaultValueArgs.kt → ...a/playground/core/WithDefaultValueArgs.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
Oops, something went wrong.