From 805c221d796f1772a302700ac206e66c6120bb6e Mon Sep 17 00:00:00 2001 From: Adetunji Dahunsi Date: Sun, 27 Oct 2024 00:32:55 -0400 Subject: [PATCH] Format code --- build-logic/wrapper/gradle-wrapper.properties | 1 - gradle/libs.versions.toml | 2 +- gradle/wrapper/gradle-wrapper.properties | 1 - .../AnimatePaneBoundsConfiguration.kt | 39 ++++++------ .../PaneModifierConfiguration.kt | 23 +++---- .../MovableSharedElements.kt | 6 +- .../com/tunjid/treenav/strings/TrieNode.kt | 2 +- .../com/tunjid/treenav/MultiStackNav.kt | 1 + .../kotlin/com/tunjid/treenav/Node.kt | 1 + .../commonTest/kotlin/MultiStackNavTest.kt | 11 +++- .../src/commonTest/kotlin/StackNavTest.kt | 10 ++- libraryVersion.properties | 1 - readme.md | 63 +++++++++++++------ sample/android/src/main/AndroidManifest.xml | 3 +- .../res/drawable/ic_launcher_background.xml | 3 +- .../res/mipmap-anydpi-v26/ic_launcher.xml | 3 +- .../mipmap-anydpi-v26/ic_launcher_round.xml | 3 +- sample/android/src/main/res/values/colors.xml | 3 +- .../src/androidMain/AndroidManifest.xml | 5 +- .../res/drawable/ic_launcher_background.xml | 3 +- .../res/mipmap-anydpi-v26/ic_launcher.xml | 3 +- .../mipmap-anydpi-v26/ic_launcher_round.xml | 3 +- .../src/androidMain/res/values/strings.xml | 3 +- .../com/tunjid/demo/common/ui/ProfilePhoto.kt | 1 - .../demo/common/ui/chatrooms/Strategy.kt | 2 +- .../com/tunjid/demo/common/ui/data/AppData.kt | 1 + .../common/ui/data/NavigationRepository.kt | 1 - 27 files changed, 114 insertions(+), 84 deletions(-) diff --git a/build-logic/wrapper/gradle-wrapper.properties b/build-logic/wrapper/gradle-wrapper.properties index 1a48bad..49e8bb8 100644 --- a/build-logic/wrapper/gradle-wrapper.properties +++ b/build-logic/wrapper/gradle-wrapper.properties @@ -13,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - #Mon Jul 05 07:23:39 EDT 2021 distributionBase=GRADLE_USER_HOME distributionUrl=https\://services.gradle.org/distributions/gradle-8.1-bin.zip diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 106f139..d618902 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -35,7 +35,7 @@ androidx-appcompat = { group = "androidx.appcompat", name = "appcompat", version androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "androidxCore" } androidx-activity-compose = { group = "androidx.activity", name = "activity-compose", version.ref = "activity-compose" } androidx-compose-animation = { group = "androidx.compose.animation", name = "animation" } -androidx-compose-foundation-foundation = { group = "androidx.compose.foundation", name = "foundation"} +androidx-compose-foundation-foundation = { group = "androidx.compose.foundation", name = "foundation" } androidx-compose-foundation-layout = { group = "androidx.compose.foundation", name = "foundation-layout" } androidx-compose-material-core = { group = "androidx.compose.material", name = "material" } androidx-compose-material-iconsExtended = { group = "androidx.compose.material", name = "material-icons-extended" } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index d990e30..0200bf9 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -13,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - #Mon Jul 05 07:23:39 EDT 2021 distributionBase=GRADLE_USER_HOME distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip diff --git a/library/compose/src/commonMain/kotlin/com/tunjid/treenav/compose/configurations/AnimatePaneBoundsConfiguration.kt b/library/compose/src/commonMain/kotlin/com/tunjid/treenav/compose/configurations/AnimatePaneBoundsConfiguration.kt index 892c080..29fdc28 100644 --- a/library/compose/src/commonMain/kotlin/com/tunjid/treenav/compose/configurations/AnimatePaneBoundsConfiguration.kt +++ b/library/compose/src/commonMain/kotlin/com/tunjid/treenav/compose/configurations/AnimatePaneBoundsConfiguration.kt @@ -49,23 +49,24 @@ fun PanedNavHostConfiguration lookaheadScope: LookaheadScope, paneBoundsTransform: PaneScope.() -> BoundsTransform = { DefaultBoundsTransform }, shouldAnimatePane: PaneScope.() -> Boolean = { true }, -): PanedNavHostConfiguration = delegated { navigationDestination -> - val originalStrategy = strategyTransform(navigationDestination) - originalStrategy.delegated( - render = render@{ paneDestination -> - Box( - modifier = Modifier.animateBounds( - state = remember { - AnimatedBoundsState( - lookaheadScope = lookaheadScope, - boundsTransform = paneBoundsTransform(), - inProgress = { shouldAnimatePane() } - ) - } - ) - ) { - originalStrategy.render(this@render, paneDestination) +): PanedNavHostConfiguration = + delegated { navigationDestination -> + val originalStrategy = strategyTransform(navigationDestination) + originalStrategy.delegated( + render = render@{ paneDestination -> + Box( + modifier = Modifier.animateBounds( + state = remember { + AnimatedBoundsState( + lookaheadScope = lookaheadScope, + boundsTransform = paneBoundsTransform(), + inProgress = { shouldAnimatePane() } + ) + } + ) + ) { + originalStrategy.render(this@render, paneDestination) + } } - } - ) -} \ No newline at end of file + ) + } \ No newline at end of file diff --git a/library/compose/src/commonMain/kotlin/com/tunjid/treenav/compose/configurations/PaneModifierConfiguration.kt b/library/compose/src/commonMain/kotlin/com/tunjid/treenav/compose/configurations/PaneModifierConfiguration.kt index 42f5ad1..31d328d 100644 --- a/library/compose/src/commonMain/kotlin/com/tunjid/treenav/compose/configurations/PaneModifierConfiguration.kt +++ b/library/compose/src/commonMain/kotlin/com/tunjid/treenav/compose/configurations/PaneModifierConfiguration.kt @@ -35,15 +35,16 @@ fun PanedNavHostConfiguration Destination >.paneModifierConfiguration( paneModifier: PaneScope.() -> Modifier = { Modifier }, -): PanedNavHostConfiguration = delegated { navigationDestination -> - val originalStrategy = strategyTransform(navigationDestination) - originalStrategy.delegated( - render = render@{ paneDestination -> - Box( - modifier = paneModifier() - ) { - originalStrategy.render(this@render, paneDestination) +): PanedNavHostConfiguration = + delegated { navigationDestination -> + val originalStrategy = strategyTransform(navigationDestination) + originalStrategy.delegated( + render = render@{ paneDestination -> + Box( + modifier = paneModifier() + ) { + originalStrategy.render(this@render, paneDestination) + } } - } - ) -} \ No newline at end of file + ) + } \ No newline at end of file diff --git a/library/compose/src/commonMain/kotlin/com/tunjid/treenav/compose/moveablesharedelement/MovableSharedElements.kt b/library/compose/src/commonMain/kotlin/com/tunjid/treenav/compose/moveablesharedelement/MovableSharedElements.kt index d067719..080dc78 100644 --- a/library/compose/src/commonMain/kotlin/com/tunjid/treenav/compose/moveablesharedelement/MovableSharedElements.kt +++ b/library/compose/src/commonMain/kotlin/com/tunjid/treenav/compose/moveablesharedelement/MovableSharedElements.kt @@ -3,9 +3,6 @@ package com.tunjid.treenav.compose.moveablesharedelement import androidx.compose.animation.BoundsTransform import androidx.compose.animation.ExperimentalSharedTransitionApi import androidx.compose.animation.SharedTransitionScope -import androidx.compose.animation.core.Spring -import androidx.compose.animation.core.VisibilityThreshold -import androidx.compose.animation.core.spring import androidx.compose.runtime.Composable import androidx.compose.runtime.Stable import androidx.compose.runtime.getValue @@ -14,12 +11,11 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.compose.ui.draw.drawWithContent -import androidx.compose.ui.geometry.Rect import androidx.compose.ui.graphics.drawscope.ContentDrawScope import com.tunjid.treenav.Node -import com.tunjid.treenav.compose.PanedNavHost import com.tunjid.treenav.compose.PaneScope import com.tunjid.treenav.compose.PaneState +import com.tunjid.treenav.compose.PanedNavHost import com.tunjid.treenav.compose.utilities.DefaultBoundsTransform internal interface SharedElementOverlay { diff --git a/library/strings/src/commonMain/kotlin/com/tunjid/treenav/strings/TrieNode.kt b/library/strings/src/commonMain/kotlin/com/tunjid/treenav/strings/TrieNode.kt index 031ecbf..d5a3a29 100644 --- a/library/strings/src/commonMain/kotlin/com/tunjid/treenav/strings/TrieNode.kt +++ b/library/strings/src/commonMain/kotlin/com/tunjid/treenav/strings/TrieNode.kt @@ -55,7 +55,7 @@ private fun TrieNode.find(segments: List, index: Int): T? { val segment = segments[index] val child = children[segment] - // Try matching against a parameter + // Try matching against a parameter ?: children[PARAMETER_MATCHER] ?: return null diff --git a/library/treenav/src/commonMain/kotlin/com/tunjid/treenav/MultiStackNav.kt b/library/treenav/src/commonMain/kotlin/com/tunjid/treenav/MultiStackNav.kt index 141ff2d..8bdc6ec 100644 --- a/library/treenav/src/commonMain/kotlin/com/tunjid/treenav/MultiStackNav.kt +++ b/library/treenav/src/commonMain/kotlin/com/tunjid/treenav/MultiStackNav.kt @@ -55,6 +55,7 @@ fun MultiStackNav.pop(): MultiStackNav = when (val changed = atCurrentIndex(Stac ) } } + else -> changed } diff --git a/library/treenav/src/commonMain/kotlin/com/tunjid/treenav/Node.kt b/library/treenav/src/commonMain/kotlin/com/tunjid/treenav/Node.kt index 732e26d..0979b06 100644 --- a/library/treenav/src/commonMain/kotlin/com/tunjid/treenav/Node.kt +++ b/library/treenav/src/commonMain/kotlin/com/tunjid/treenav/Node.kt @@ -46,6 +46,7 @@ inline fun Node.traverse(order: Order, crossinline onNodeVisited: (Node) -> Unit for (element in node.children) queue.add(element) } } + Order.DepthFirst -> { val stack = mutableListOf(this) while (stack.isNotEmpty()) { diff --git a/library/treenav/src/commonTest/kotlin/MultiStackNavTest.kt b/library/treenav/src/commonTest/kotlin/MultiStackNavTest.kt index f330303..a3a24d8 100644 --- a/library/treenav/src/commonTest/kotlin/MultiStackNavTest.kt +++ b/library/treenav/src/commonTest/kotlin/MultiStackNavTest.kt @@ -14,7 +14,16 @@ * limitations under the License. */ -import com.tunjid.treenav.* +import com.tunjid.treenav.MultiStackNav +import com.tunjid.treenav.Order +import com.tunjid.treenav.StackNav +import com.tunjid.treenav.flatten +import com.tunjid.treenav.minus +import com.tunjid.treenav.pop +import com.tunjid.treenav.popToRoot +import com.tunjid.treenav.push +import com.tunjid.treenav.swap +import com.tunjid.treenav.switch import kotlin.test.BeforeTest import kotlin.test.Test import kotlin.test.assertEquals diff --git a/library/treenav/src/commonTest/kotlin/StackNavTest.kt b/library/treenav/src/commonTest/kotlin/StackNavTest.kt index 78b8af3..a3113ff 100644 --- a/library/treenav/src/commonTest/kotlin/StackNavTest.kt +++ b/library/treenav/src/commonTest/kotlin/StackNavTest.kt @@ -14,7 +14,15 @@ * limitations under the License. */ -import com.tunjid.treenav.* +import com.tunjid.treenav.Node +import com.tunjid.treenav.Order +import com.tunjid.treenav.StackNav +import com.tunjid.treenav.current +import com.tunjid.treenav.flatten +import com.tunjid.treenav.minus +import com.tunjid.treenav.pop +import com.tunjid.treenav.popToRoot +import com.tunjid.treenav.push import kotlin.test.BeforeTest import kotlin.test.Test import kotlin.test.assertEquals diff --git a/libraryVersion.properties b/libraryVersion.properties index f499a74..d2b2934 100644 --- a/libraryVersion.properties +++ b/libraryVersion.properties @@ -13,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - groupId=com.tunjid.treenav treenav_version=0.0.7 strings_version=0.0.7 diff --git a/readme.md b/readme.md index f7855c9..efbc14a 100644 --- a/readme.md +++ b/readme.md @@ -12,13 +12,16 @@ ![badge][badge-tvos] ![badge][badge-watchos] -Please note, this is not an official Google repository. It is a Kotlin multiplatform experiment that makes no guarantees -about API stability or long term support. None of the works presented here are production tested, and should not be +Please note, this is not an official Google repository. It is a Kotlin multiplatform experiment that +makes no guarantees +about API stability or long term support. None of the works presented here are production tested, +and should not be taken as anything more than its face value. ## Get it -`treenav` is available on mavenCentral with the latest version indicated by the badge at the top of this readme file. +`treenav` is available on mavenCentral with the latest version indicated by the badge at the top of +this readme file. `implementation com.tunjid.treenav:treenav:version` @@ -26,8 +29,10 @@ taken as anything more than its face value. ## Introduction -TreeNav is a kotlin multiplatform experiment for representing app navigation with tree like data structures. This -library is merely a declaration of interfaces and well tested types. Integration is open ended and left to the consuming +TreeNav is a kotlin multiplatform experiment for representing app navigation with tree like data +structures. This +library is merely a declaration of interfaces and well tested types. Integration is open ended and +left to the consuming application. An example of such an implementation can be found [here](https://github.com/tunjid/me). The basic type defined is the `Node` interface. @@ -48,13 +53,17 @@ interface Node { * `push`: Adds a `Route` to the `Node` by pushing a `Route` unto the stack. * `pop`: Removes a `Route` from the `Node` by popping it off the stack. * `swap`: Replaces a `Route` in the `Node` by switching out the top of the stack with it. - * `MultiStackNav`: A compound `Node` comprising of multiple `StackNav` instances with the added convenience of being + * `MultiStackNav`: A compound `Node` comprising of multiple `StackNav` instances with the added + convenience of being able to switch stacks as well as the behaviors from `StackNav` via proxy. - * `switch`: Replaces the active index in `Node` by switching out the context of the aforementioned operations to + * `switch`: Replaces the active index in `Node` by switching out the context of the + aforementioned operations to the stack indicated by the index. -The above mentioned types are immutable, each action generates a new `Node` with the effects of the action applied. -Consuming applications typically observe the effects of the actions applied and react to the current `Node` of the +The above mentioned types are immutable, each action generates a new `Node` with the effects of the +action applied. +Consuming applications typically observe the effects of the actions applied and react to the +current `Node` of the lowest branch of the tree. The above makes it easy to represent the following navigation structure: @@ -74,11 +83,14 @@ root_multi_stack_nav ## Strings module -In multi-module applications, navigating between routes in other modules with strongly typed `Route` instances becomes a -challenge as one needs an instance of a `Route` from the other module in order to navigate to it. This cyclic dependency +In multi-module applications, navigating between routes in other modules with strongly typed `Route` +instances becomes a +challenge as one needs an instance of a `Route` from the other module in order to navigate to it. +This cyclic dependency issue can be avoided if `Route`s had canonical string representations. -To facilitate this, the `strings` module provides the `RouteParser` type, a functional interface declared as: +To facilitate this, the `strings` module provides the `RouteParser` type, a functional interface +declared as: ```kotlin fun interface RouteParser { @@ -86,7 +98,8 @@ fun interface RouteParser { } ``` -Which allows for the dynamic resolution of strings as `Route`s. A basic factory function for a `RouteParser` is provided +Which allows for the dynamic resolution of strings as `Route`s. A basic factory function for +a `RouteParser` is provided with the following: ```kotlin @@ -95,7 +108,8 @@ fun routeParserFrom( ): RouteParser ``` -Where a `UrlRouteMatcher` extracts path and query parameters from url like strings. An example of its use is: +Where a `UrlRouteMatcher` extracts path and query parameters from url like strings. An example of +its use is: ```kotlin val routeParser = routeParserFrom( @@ -114,12 +128,13 @@ val routeParser = routeParserFrom( ) ``` -Note that the order of declaration of `UrlRouteMatcher` instances matter. For `UserSearchRoute`to be matched, it has to +Note that the order of declaration of `UrlRouteMatcher` instances matter. For `UserSearchRoute`to be +matched, it has to be declared before the `UserRoute` as the `UserRoute` pattern also matches `UserSearchRoute` pattern. - -An example of this pattern being used to anchor the navigation for a multi-module KMP app, checkout the +An example of this pattern being used to anchor the navigation for a multi-module KMP app, checkout +the [Me](https://github.com/tunjid/me/blob/main/common/feature-archive-edit/src/commonMain/kotlin/com/tunjid/me/archiveedit/FeatureDef.kt) Kotlin multiplatform sample app. @@ -140,15 +155,27 @@ Kotlin multiplatform sample app. limitations under the License. [badge-android]: http://img.shields.io/badge/-android-6EDB8D.svg?style=flat + [badge-jvm]: http://img.shields.io/badge/-jvm-DB413D.svg?style=flat + [badge-js]: http://img.shields.io/badge/-js-F8DB5D.svg?style=flat + [badge-js-ir]: https://img.shields.io/badge/support-[IR]-AAC4E0.svg?style=flat + [badge-nodejs]: https://img.shields.io/badge/-nodejs-68a063.svg?style=flat -[badge-linux]: http://img.shields.io/badge/-linux-2D3F6C.svg?style=flat + +[badge-linux]: http://img.shields.io/badge/-linux-2D3F6C.svg?style=flat + [badge-windows]: http://img.shields.io/badge/-windows-4D76CD.svg?style=flat + [badge-wasm]: https://img.shields.io/badge/-wasm-624FE8.svg?style=flat + [badge-apple-silicon]: http://img.shields.io/badge/support-[AppleSilicon]-43BBFF.svg?style=flat + [badge-ios]: http://img.shields.io/badge/-ios-CDCDCD.svg?style=flat + [badge-mac]: http://img.shields.io/badge/-macos-111111.svg?style=flat + [badge-watchos]: http://img.shields.io/badge/-watchos-C0C0C0.svg?style=flat + [badge-tvos]: http://img.shields.io/badge/-tvos-808080.svg?style=flat diff --git a/sample/android/src/main/AndroidManifest.xml b/sample/android/src/main/AndroidManifest.xml index afeeffe..c3fbb5e 100644 --- a/sample/android/src/main/AndroidManifest.xml +++ b/sample/android/src/main/AndroidManifest.xml @@ -1,5 +1,4 @@ - - - + diff --git a/sample/common/src/androidMain/res/drawable/ic_launcher_background.xml b/sample/common/src/androidMain/res/drawable/ic_launcher_background.xml index 6013ddc..816dc57 100644 --- a/sample/common/src/androidMain/res/drawable/ic_launcher_background.xml +++ b/sample/common/src/androidMain/res/drawable/ic_launcher_background.xml @@ -1,5 +1,4 @@ - -