这是indexloc提供的服务,不要输入任何密码
Skip to content

Format code #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion build-logic/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
1 change: 0 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,23 +49,24 @@ fun <Pane, NavigationState : Node, Destination : Node> PanedNavHostConfiguration
lookaheadScope: LookaheadScope,
paneBoundsTransform: PaneScope<Pane, Destination>.() -> BoundsTransform = { DefaultBoundsTransform },
shouldAnimatePane: PaneScope<Pane, Destination>.() -> Boolean = { true },
): PanedNavHostConfiguration<Pane, NavigationState, Destination> = 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<Pane, NavigationState, Destination> =
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)
}
}
}
)
}
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,16 @@ fun <Pane, NavigationState : Node, Destination : Node> PanedNavHostConfiguration
Destination
>.paneModifierConfiguration(
paneModifier: PaneScope<Pane, Destination>.() -> Modifier = { Modifier },
): PanedNavHostConfiguration<Pane, NavigationState, Destination> = delegated { navigationDestination ->
val originalStrategy = strategyTransform(navigationDestination)
originalStrategy.delegated(
render = render@{ paneDestination ->
Box(
modifier = paneModifier()
) {
originalStrategy.render(this@render, paneDestination)
): PanedNavHostConfiguration<Pane, NavigationState, Destination> =
delegated { navigationDestination ->
val originalStrategy = strategyTransform(navigationDestination)
originalStrategy.delegated(
render = render@{ paneDestination ->
Box(
modifier = paneModifier()
) {
originalStrategy.render(this@render, paneDestination)
}
}
}
)
}
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ private fun <T> TrieNode<T>.find(segments: List<String>, 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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ fun MultiStackNav.pop(): MultiStackNav = when (val changed = atCurrentIndex(Stac
)
}
}

else -> changed
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
11 changes: 10 additions & 1 deletion library/treenav/src/commonTest/kotlin/MultiStackNavTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion library/treenav/src/commonTest/kotlin/StackNavTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion libraryVersion.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
63 changes: 45 additions & 18 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,27 @@
![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`

`implementation com.tunjid.treenav:strings:version`

## 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.
Expand All @@ -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:
Expand All @@ -74,19 +83,23 @@ 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<T : Route> {
fun parse(routeString: String): T?
}
```

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
Expand All @@ -95,7 +108,8 @@ fun <T : Route> routeParserFrom(
): RouteParser<T>
```

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(
Expand All @@ -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.

Expand All @@ -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
3 changes: 1 addition & 2 deletions sample/android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
<?xml version="1.0" encoding="utf-8"?><!--
~ Copyright 2021 Google LLC
~
~ Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
<?xml version="1.0" encoding="utf-8"?><!--
~ Copyright 2021 Google LLC
~
~ Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
<?xml version="1.0" encoding="utf-8"?><!--
~ Copyright 2021 Google LLC
~
~ Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
<?xml version="1.0" encoding="utf-8"?><!--
~ Copyright 2021 Google LLC
~
~ Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
3 changes: 1 addition & 2 deletions sample/android/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
<?xml version="1.0" encoding="utf-8"?><!--
~ Copyright 2021 Google LLC
~
~ Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
5 changes: 2 additions & 3 deletions sample/common/src/androidMain/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
<?xml version="1.0" encoding="utf-8"?><!--
~ Copyright 2021 Google LLC
~
~ Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -15,4 +14,4 @@
~ limitations under the License.
-->

<manifest/>
<manifest />
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
<?xml version="1.0" encoding="utf-8"?><!--
~ Copyright 2021 Google LLC
~
~ Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
<?xml version="1.0" encoding="utf-8"?><!--
~ Copyright 2021 Google LLC
~
~ Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
Loading
Loading