Skip to content

Commit

Permalink
Merge pull request #13 from alphicc/bug_pass_argument
Browse files Browse the repository at this point in the history
bug_pass_argument : fix duplicate pass argument
  • Loading branch information
alphicc committed Apr 16, 2023
2 parents 52d71b6 + 988e9d8 commit c862f6a
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
![MAVEN](https://img.shields.io/badge/Maven-v2.1.1-blue) ![Platform](https://img.shields.io/badge/platform-android-green?color=lightgray) ![API](https://img.shields.io/badge/API-21-brightgreen?color=brightgreen) ![Platform](https://img.shields.io/badge/platform-desktop-green?color=lightgray)
![MAVEN](https://img.shields.io/badge/Maven-v2.1.2-blue) ![Platform](https://img.shields.io/badge/platform-android-green?color=lightgray) ![API](https://img.shields.io/badge/API-21-brightgreen?color=brightgreen) ![Platform](https://img.shields.io/badge/platform-desktop-green?color=lightgray)
<h1 align="center">
<img height="300" src="https://raw.githubusercontent.com/alphicc/Brick/main/media/logo.png"/>
<br>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package com.alphicc.brick

interface ArgumentTranslator {
suspend fun <A> redirectArgument(from: ArgumentTranslator, componentKey: String, argument: A)
suspend fun <A> redirectArgument(from: ArgumentTranslator, componentKey: String, argument: A): Boolean
}
25 changes: 19 additions & 6 deletions brick/src/commonMain/kotlin/com/alphicc/brick/TreeRouterImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package com.alphicc.brick

import kotlinx.atomicfu.AtomicRef
import kotlinx.atomicfu.atomic
import kotlinx.coroutines.flow.*
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow

internal class TreeRouterImpl(
override val initialComponent: Component<*>? = null,
Expand Down Expand Up @@ -208,19 +210,26 @@ internal class TreeRouterImpl(
from: ArgumentTranslator,
componentKey: String,
argument: A
) {
): Boolean {
val isEmitted = emitArguments(componentKey, argument)
if (isEmitted) return true
childRouters.value.forEach {
val isEmittedChildRouter = it.second.redirectArgument(this, componentKey, argument)
if (isEmittedChildRouter) return true
}
if (parentRouter !== from) {
parentRouter?.redirectArgument(this, componentKey, argument)
val isEmittedParentRouter = parentRouter?.redirectArgument(this, componentKey, argument)
if (isEmittedParentRouter == true) return true
}
childRouters.value.forEach { it.second.redirectArgument(this, componentKey, argument) }
emitArguments(componentKey, argument)
return false
}

private suspend fun <A> emitArguments(componentKey: String, argument: A) {
private suspend fun <A> emitArguments(componentKey: String, argument: A): Boolean {
_currentOverlayFlow.value?.let { overlayComponent ->
if (overlayComponent.key == componentKey) {
val dataContainer = DataContainer(argument)
overlayComponent.channel.emit(dataContainer)
return true
}
}

Expand All @@ -229,21 +238,25 @@ internal class TreeRouterImpl(
if (it.key == componentKey) {
val dataContainer = DataContainer(argument)
it.channel.emit(dataContainer)
return true
}
}

node.compositions().forEach { entry ->
if (entry.key == componentKey) {
val dataContainer = DataContainer(argument)
entry.value.channel.emit(dataContainer)
return true
}
}

if (node.rootComponent.key == componentKey) {
val dataContainer = DataContainer(argument)
node.rootComponent.channel.emit(dataContainer)
return true
}
}
return false
}

private fun <A> addChildNode(component: Component<*>, argument: A?) {
Expand Down
2 changes: 1 addition & 1 deletion desktop/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
}

group = "io.github.alphicc"
version = "1.0.0"
version = "2.1.2"

kotlin {
jvm {
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ gradle_tools_version=7.0.4
publish_plugin_version=0.18.0

GROUP=io.github.alphicc
VERSION_NAME=2.1.1
VERSION_NAME=2.1.2

POM_NAME=Brick
POM_DESCRIPTION=Brick - Navigation library for Jetpack Compose.
POM_INCEPTION_YEAR=2022
POM_INCEPTION_YEAR=2023
POM_URL=https://github.com/alphicc/Brick

POM_LICENCE_NAME=The MIT License
Expand Down

0 comments on commit c862f6a

Please sign in to comment.