generated from InsanusMokrassar/KotlinMultiplatformProjectTemplate
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improve Empty default things and add realization for NavigationNodeFa…
…ctory
- Loading branch information
1 parent
7dec737
commit d768946
Showing
3 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,8 +1,37 @@ | ||
package dev.inmo.navigation.core | ||
|
||
import kotlin.reflect.KClass | ||
|
||
fun interface NavigationNodeFactory<Base> { | ||
fun createNode( | ||
navigationChain: NavigationChain<Base>, | ||
config: Base | ||
): NavigationNode<out Base, Base>? | ||
|
||
companion object { | ||
open class Typed<Base : Any, T : Base>( | ||
private val kClass: KClass<T>, | ||
private val block: (navigationChain: NavigationChain<Base>, config: T) -> NavigationNode<T, Base> | ||
) : NavigationNodeFactory<Base> { | ||
override fun createNode( | ||
navigationChain: NavigationChain<Base>, | ||
config: Base | ||
): NavigationNode<out Base, Base>? { | ||
return if (kClass.isInstance(config)) { | ||
block(navigationChain, config as T) | ||
} else { | ||
null | ||
} | ||
} | ||
|
||
companion object { | ||
inline operator fun <Base : Any, reified T : Base> invoke( | ||
noinline block: (navigationChain: NavigationChain<Base>, config: T) -> NavigationNode<T, Base> | ||
) = Typed<Base, T>( | ||
kClass = T::class, | ||
block | ||
) | ||
} | ||
} | ||
} | ||
} |