Skip to content

Commit

Permalink
fix: changed ComposeWrapper api
Browse files Browse the repository at this point in the history
  • Loading branch information
y9san9 committed May 4, 2024
1 parent ec93759 commit 5751921
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 19 deletions.
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ androidx-lifecycle = "2.7.0"
ktgbotapi = "11.0.0"
mdi = "0.0.38"

ksm = "0.0.29"
ksm = "0.0.30"

[libraries]

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package ksm.navigation.compose.interceptor

import ksm.context.StateContext
import ksm.navigation.compose.plugin.ComposeContent

internal class CombinedComposeInterceptor(
private val first: ComposeInterceptor?,
private val second: ComposeInterceptor
) : ComposeInterceptor {
override fun intercept(context: StateContext, base: ComposeContent): ComposeContent {
override fun intercept(base: ComposeContent): ComposeContent {
var applied = base
applied = first?.intercept(context, applied) ?: applied
applied = second.intercept(context, applied)
applied = first?.intercept(applied) ?: applied
applied = second.intercept(applied)
return applied
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
package ksm.navigation.compose.interceptor

import ksm.context.StateContext
import ksm.navigation.compose.plugin.ComposeContent

public fun interface ComposeInterceptor {
public fun intercept(
context: StateContext,
base: ComposeContent
): ComposeContent
public fun intercept(base: ComposeContent): ComposeContent
}

public operator fun ComposeInterceptor?.plus(other: ComposeInterceptor): ComposeInterceptor {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ import ksm.StateController

public fun interface ComposeContent {
@Composable
public fun Content(controller: StateController)
public fun StateController.Content()
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public class ComposePlugin(
val entry = context.require(ComposeEntry)
val interceptor = entry.interceptor
val base = ComposeContent(content)
entry.content = interceptor?.intercept(context, base) ?: base
entry.content = interceptor?.intercept(base) ?: base
}

public fun content(context: StateContext): ComposeContent? {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
package ksm.navigation.compose.wrapper

import ksm.StateController
import ksm.asStateController
import ksm.navigation.compose.interceptor.ComposeInterceptor
import ksm.navigation.compose.plugin.ComposeContent

public fun interface ComposeWrapper {
public fun StateController.wrap(content: ComposeContent): ComposeContent
public fun wrap(content: ComposeContent): ComposeContent
}

public fun ComposeWrapper.toInterceptor(): ComposeInterceptor {
return ComposeInterceptor { context, base ->
val controller = context.asStateController()
controller.wrap(base)
}
return ComposeInterceptor(::wrap)
}

0 comments on commit 5751921

Please sign in to comment.