Skip to content

Commit

Permalink
Merge pull request #144 from arkivanov/merge-master-into-compose-darwin
Browse files Browse the repository at this point in the history
Merge master into compose-darwin
  • Loading branch information
arkivanov authored Jul 16, 2022
2 parents 76e2118 + 5c7c861 commit 061f4e3
Show file tree
Hide file tree
Showing 125 changed files with 4,355 additions and 388 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
[![Maven Central](https://img.shields.io/maven-central/v/com.arkivanov.decompose/decompose?color=blue)](https://search.maven.org/artifact/com.arkivanov.decompose/decompose)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](http://www.apache.org/licenses/LICENSE-2.0)
[![Twitter URL](https://img.shields.io/badge/Twitter-@arkann1985-blue.svg?style=social&logo=twitter)](https://twitter.com/arkann1985)

Expand Down
78 changes: 78 additions & 0 deletions decompose/api/android/decompose.api
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,84 @@ public final class com/arkivanov/decompose/router/StackSaverImpl$SavedState$Crea
public synthetic fun newArray (I)[Ljava/lang/Object;
}

public final class com/arkivanov/decompose/router/stack/ChildStack {
public fun <init> (Lcom/arkivanov/decompose/Child$Created;Ljava/util/List;)V
public synthetic fun <init> (Lcom/arkivanov/decompose/Child$Created;Ljava/util/List;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun <init> (Ljava/lang/Object;Ljava/lang/Object;)V
public final fun component1 ()Lcom/arkivanov/decompose/Child$Created;
public final fun component2 ()Ljava/util/List;
public final fun copy (Lcom/arkivanov/decompose/Child$Created;Ljava/util/List;)Lcom/arkivanov/decompose/router/stack/ChildStack;
public static synthetic fun copy$default (Lcom/arkivanov/decompose/router/stack/ChildStack;Lcom/arkivanov/decompose/Child$Created;Ljava/util/List;ILjava/lang/Object;)Lcom/arkivanov/decompose/router/stack/ChildStack;
public fun equals (Ljava/lang/Object;)Z
public final fun getActive ()Lcom/arkivanov/decompose/Child$Created;
public final fun getBackStack ()Ljava/util/List;
public final fun getItems ()Ljava/util/List;
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
}

public final class com/arkivanov/decompose/router/stack/ChildStackFactoryKt {
public static final fun childStack (Lcom/arkivanov/decompose/ComponentContext;Lcom/arkivanov/decompose/router/stack/StackNavigationSource;Lkotlin/jvm/functions/Function0;Lkotlin/reflect/KClass;Ljava/lang/String;ZLkotlin/jvm/functions/Function2;)Lcom/arkivanov/decompose/value/Value;
public static synthetic fun childStack$default (Lcom/arkivanov/decompose/ComponentContext;Lcom/arkivanov/decompose/router/stack/StackNavigationSource;Lkotlin/jvm/functions/Function0;Lkotlin/reflect/KClass;Ljava/lang/String;ZLkotlin/jvm/functions/Function2;ILjava/lang/Object;)Lcom/arkivanov/decompose/value/Value;
}

public abstract interface class com/arkivanov/decompose/router/stack/StackNavigation : com/arkivanov/decompose/router/stack/StackNavigationSource, com/arkivanov/decompose/router/stack/StackNavigator {
}

public final class com/arkivanov/decompose/router/stack/StackNavigationFactoryKt {
public static final fun StackNavigation ()Lcom/arkivanov/decompose/router/stack/StackNavigation;
}

public abstract interface class com/arkivanov/decompose/router/stack/StackNavigationSource {
public abstract fun subscribe (Lkotlin/jvm/functions/Function1;)V
public abstract fun unsubscribe (Lkotlin/jvm/functions/Function1;)V
}

public final class com/arkivanov/decompose/router/stack/StackNavigationSource$Event {
public fun <init> (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)V
public synthetic fun <init> (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun getOnComplete ()Lkotlin/jvm/functions/Function2;
public final fun getTransformer ()Lkotlin/jvm/functions/Function1;
}

public abstract interface class com/arkivanov/decompose/router/stack/StackNavigator {
public abstract fun navigate (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)V
}

public final class com/arkivanov/decompose/router/stack/StackNavigatorExtKt {
public static final fun bringToFront (Lcom/arkivanov/decompose/router/stack/StackNavigator;Ljava/lang/Object;Lkotlin/jvm/functions/Function0;)V
public static synthetic fun bringToFront$default (Lcom/arkivanov/decompose/router/stack/StackNavigator;Ljava/lang/Object;Lkotlin/jvm/functions/Function0;ILjava/lang/Object;)V
public static final fun navigate (Lcom/arkivanov/decompose/router/stack/StackNavigator;Lkotlin/jvm/functions/Function1;)V
public static final fun pop (Lcom/arkivanov/decompose/router/stack/StackNavigator;Lkotlin/jvm/functions/Function1;)V
public static synthetic fun pop$default (Lcom/arkivanov/decompose/router/stack/StackNavigator;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)V
public static final fun popWhile (Lcom/arkivanov/decompose/router/stack/StackNavigator;Lkotlin/jvm/functions/Function1;)V
public static final fun popWhile (Lcom/arkivanov/decompose/router/stack/StackNavigator;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)V
public static final fun push (Lcom/arkivanov/decompose/router/stack/StackNavigator;Ljava/lang/Object;Lkotlin/jvm/functions/Function0;)V
public static synthetic fun push$default (Lcom/arkivanov/decompose/router/stack/StackNavigator;Ljava/lang/Object;Lkotlin/jvm/functions/Function0;ILjava/lang/Object;)V
public static final fun replaceCurrent (Lcom/arkivanov/decompose/router/stack/StackNavigator;Ljava/lang/Object;Lkotlin/jvm/functions/Function0;)V
public static synthetic fun replaceCurrent$default (Lcom/arkivanov/decompose/router/stack/StackNavigator;Ljava/lang/Object;Lkotlin/jvm/functions/Function0;ILjava/lang/Object;)V
}

public final class com/arkivanov/decompose/router/stack/StackSaverImpl$SavedEntry$Creator : android/os/Parcelable$Creator {
public fun <init> ()V
public final fun createFromParcel (Landroid/os/Parcel;)Lcom/arkivanov/decompose/router/stack/StackSaverImpl$SavedEntry;
public synthetic fun createFromParcel (Landroid/os/Parcel;)Ljava/lang/Object;
public final fun newArray (I)[Lcom/arkivanov/decompose/router/stack/StackSaverImpl$SavedEntry;
public synthetic fun newArray (I)[Ljava/lang/Object;
}

public final class com/arkivanov/decompose/router/stack/StackSaverImpl$SavedState$Creator : android/os/Parcelable$Creator {
public fun <init> ()V
public final fun createFromParcel (Landroid/os/Parcel;)Lcom/arkivanov/decompose/router/stack/StackSaverImpl$SavedState;
public synthetic fun createFromParcel (Landroid/os/Parcel;)Ljava/lang/Object;
public final fun newArray (I)[Lcom/arkivanov/decompose/router/stack/StackSaverImpl$SavedState;
public synthetic fun newArray (I)[Ljava/lang/Object;
}

public abstract interface class com/arkivanov/decompose/router/stack/webhistory/WebHistoryController {
public abstract fun attach (Lcom/arkivanov/decompose/router/stack/StackNavigator;Lcom/arkivanov/decompose/value/Value;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)V
}

public abstract interface class com/arkivanov/decompose/router/webhistory/WebHistoryController {
public abstract fun attach (Lcom/arkivanov/decompose/router/Router;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)V
}
Expand Down
62 changes: 62 additions & 0 deletions decompose/api/jvm/decompose.api
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,68 @@ public final class com/arkivanov/decompose/router/RouterState {
public fun toString ()Ljava/lang/String;
}

public final class com/arkivanov/decompose/router/stack/ChildStack {
public fun <init> (Lcom/arkivanov/decompose/Child$Created;Ljava/util/List;)V
public synthetic fun <init> (Lcom/arkivanov/decompose/Child$Created;Ljava/util/List;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun <init> (Ljava/lang/Object;Ljava/lang/Object;)V
public final fun component1 ()Lcom/arkivanov/decompose/Child$Created;
public final fun component2 ()Ljava/util/List;
public final fun copy (Lcom/arkivanov/decompose/Child$Created;Ljava/util/List;)Lcom/arkivanov/decompose/router/stack/ChildStack;
public static synthetic fun copy$default (Lcom/arkivanov/decompose/router/stack/ChildStack;Lcom/arkivanov/decompose/Child$Created;Ljava/util/List;ILjava/lang/Object;)Lcom/arkivanov/decompose/router/stack/ChildStack;
public fun equals (Ljava/lang/Object;)Z
public final fun getActive ()Lcom/arkivanov/decompose/Child$Created;
public final fun getBackStack ()Ljava/util/List;
public final fun getItems ()Ljava/util/List;
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
}

public final class com/arkivanov/decompose/router/stack/ChildStackFactoryKt {
public static final fun childStack (Lcom/arkivanov/decompose/ComponentContext;Lcom/arkivanov/decompose/router/stack/StackNavigationSource;Lkotlin/jvm/functions/Function0;Lkotlin/reflect/KClass;Ljava/lang/String;ZLkotlin/jvm/functions/Function2;)Lcom/arkivanov/decompose/value/Value;
public static synthetic fun childStack$default (Lcom/arkivanov/decompose/ComponentContext;Lcom/arkivanov/decompose/router/stack/StackNavigationSource;Lkotlin/jvm/functions/Function0;Lkotlin/reflect/KClass;Ljava/lang/String;ZLkotlin/jvm/functions/Function2;ILjava/lang/Object;)Lcom/arkivanov/decompose/value/Value;
}

public abstract interface class com/arkivanov/decompose/router/stack/StackNavigation : com/arkivanov/decompose/router/stack/StackNavigationSource, com/arkivanov/decompose/router/stack/StackNavigator {
}

public final class com/arkivanov/decompose/router/stack/StackNavigationFactoryKt {
public static final fun StackNavigation ()Lcom/arkivanov/decompose/router/stack/StackNavigation;
}

public abstract interface class com/arkivanov/decompose/router/stack/StackNavigationSource {
public abstract fun subscribe (Lkotlin/jvm/functions/Function1;)V
public abstract fun unsubscribe (Lkotlin/jvm/functions/Function1;)V
}

public final class com/arkivanov/decompose/router/stack/StackNavigationSource$Event {
public fun <init> (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)V
public synthetic fun <init> (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun getOnComplete ()Lkotlin/jvm/functions/Function2;
public final fun getTransformer ()Lkotlin/jvm/functions/Function1;
}

public abstract interface class com/arkivanov/decompose/router/stack/StackNavigator {
public abstract fun navigate (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)V
}

public final class com/arkivanov/decompose/router/stack/StackNavigatorExtKt {
public static final fun bringToFront (Lcom/arkivanov/decompose/router/stack/StackNavigator;Ljava/lang/Object;Lkotlin/jvm/functions/Function0;)V
public static synthetic fun bringToFront$default (Lcom/arkivanov/decompose/router/stack/StackNavigator;Ljava/lang/Object;Lkotlin/jvm/functions/Function0;ILjava/lang/Object;)V
public static final fun navigate (Lcom/arkivanov/decompose/router/stack/StackNavigator;Lkotlin/jvm/functions/Function1;)V
public static final fun pop (Lcom/arkivanov/decompose/router/stack/StackNavigator;Lkotlin/jvm/functions/Function1;)V
public static synthetic fun pop$default (Lcom/arkivanov/decompose/router/stack/StackNavigator;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)V
public static final fun popWhile (Lcom/arkivanov/decompose/router/stack/StackNavigator;Lkotlin/jvm/functions/Function1;)V
public static final fun popWhile (Lcom/arkivanov/decompose/router/stack/StackNavigator;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)V
public static final fun push (Lcom/arkivanov/decompose/router/stack/StackNavigator;Ljava/lang/Object;Lkotlin/jvm/functions/Function0;)V
public static synthetic fun push$default (Lcom/arkivanov/decompose/router/stack/StackNavigator;Ljava/lang/Object;Lkotlin/jvm/functions/Function0;ILjava/lang/Object;)V
public static final fun replaceCurrent (Lcom/arkivanov/decompose/router/stack/StackNavigator;Ljava/lang/Object;Lkotlin/jvm/functions/Function0;)V
public static synthetic fun replaceCurrent$default (Lcom/arkivanov/decompose/router/stack/StackNavigator;Ljava/lang/Object;Lkotlin/jvm/functions/Function0;ILjava/lang/Object;)V
}

public abstract interface class com/arkivanov/decompose/router/stack/webhistory/WebHistoryController {
public abstract fun attach (Lcom/arkivanov/decompose/router/stack/StackNavigator;Lcom/arkivanov/decompose/value/Value;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)V
}

public abstract interface class com/arkivanov/decompose/router/webhistory/WebHistoryController {
public abstract fun attach (Lcom/arkivanov/decompose/router/Router;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)V
}
Expand Down
27 changes: 27 additions & 0 deletions decompose/src/commonMain/kotlin/com/arkivanov/decompose/Relay.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.arkivanov.decompose

internal class Relay<T> {

init {
ensureNeverFrozen()
}

private var observers = emptySet<(T) -> Unit>()

private val queue =
SerializedQueue<T> { value ->
observers.forEach { it(value) }
}

fun subscribe(observer: (T) -> Unit) {
this.observers += observer
}

fun unsubscribe(observer: (T) -> Unit) {
this.observers -= observer
}

fun accept(value: T) {
queue.offer(value)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ package com.arkivanov.decompose.router

import com.arkivanov.decompose.value.Value

/**
* Deprecated. Please use Child Stack instead. See the [documentation](https://arkivanov.github.io/Decompose/child-stack/overview/).
*/
@Deprecated(message = "Use Child Stack instead")
interface Router<C : Any, out T : Any> {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import com.arkivanov.decompose.Child

/**
* A convenience method for [Router.navigate].
*
* Deprecated. Please use `Child Stack` instead. See the [documentation](https://arkivanov.github.io/Decompose/child-stack/overview/).
*/
@Deprecated("Use Child Stack instead")
fun <C : Any> Router<C, *>.navigate(transformer: (stack: List<C>) -> List<C>) {
navigate(transformer = transformer, onComplete = { _, _ -> })
}
Expand All @@ -17,8 +20,11 @@ fun <C : Any> Router<C, *>.push(configuration: C) {
/**
* Pushes the provided [configuration] at the top of the stack.
*
* Deprecated. Please use `Child Stack` instead. See the [documentation](https://arkivanov.github.io/Decompose/child-stack/overview/).
*
* @param onComplete called when the navigation is finished (either synchronously or asynchronously).
*/
@Deprecated("Use Child Stack instead")
fun <C : Any> Router<C, *>.push(configuration: C, onComplete: () -> Unit = {}) {
navigate(transformer = { it + configuration }, onComplete = { _, _ -> onComplete() })
}
Expand All @@ -29,7 +35,10 @@ fun <C : Any> Router<C, *>.push(configuration: C, onComplete: () -> Unit = {}) {
* @param onComplete called when the navigation is finished (either synchronously or asynchronously).
* The `isSuccess` argument is `true` if the stack size was greater than 1 and a component was popped,
* `false` otherwise.
*
* Deprecated. Please use `Child Stack` instead. See the [documentation](https://arkivanov.github.io/Decompose/child-stack/overview/).
*/
@Deprecated("Use Child Stack instead")
fun <C : Any> Router<C, *>.pop(onComplete: (isSuccess: Boolean) -> Unit = {}) {
navigate(
transformer = { stack -> stack.takeIf { it.size > 1 }?.dropLast(1) ?: stack },
Expand All @@ -39,17 +48,24 @@ fun <C : Any> Router<C, *>.pop(onComplete: (isSuccess: Boolean) -> Unit = {}) {

/**
* Drops the configurations at the top of the stack while the [predicate] returns `true`.
*
* Deprecated. Please use `Child Stack` instead. See the [documentation](https://arkivanov.github.io/Decompose/child-stack/overview/).
*/
@Suppress("DeprecatedCallableAddReplaceWith")
@Deprecated("Use Child Stack instead")
inline fun <C : Any> Router<C, *>.popWhile(crossinline predicate: (C) -> Boolean) {
popWhile(predicate = predicate, onComplete = {})
}

/**
* Drops the configurations at the top of the stack while the [predicate] returns true
*
* Deprecated. Please use `Child Stack` instead. See the [documentation](https://arkivanov.github.io/Decompose/child-stack/overview/).
*
* @param onComplete called when the navigation is finished (either synchronously or asynchronously).
* The `isSuccess` argument is `true` if at least one component has been popped.
*/
@Deprecated("Use Child Stack instead")
inline fun <C : Any> Router<C, *>.popWhile(
crossinline predicate: (C) -> Boolean,
crossinline onComplete: (isSuccess: Boolean) -> Unit,
Expand All @@ -68,8 +84,11 @@ fun <C : Any> Router<C, *>.replaceCurrent(configuration: C) {
/**
* Replaces the current configuration at the top of the stack with the provided [configuration].
*
* Deprecated. Please use `Child Stack` instead. See the [documentation](https://arkivanov.github.io/Decompose/child-stack/overview/).
*
* @param onComplete called when the navigation is finished (either synchronously or asynchronously).
*/
@Deprecated("Use Child Stack instead")
fun <C : Any> Router<C, *>.replaceCurrent(configuration: C, onComplete: () -> Unit = {}) {
navigate(
transformer = { it.dropLast(1) + configuration },
Expand All @@ -85,12 +104,21 @@ fun <C : Any> Router<C, *>.bringToFront(configuration: C) {
/**
* Removes all components with configurations of [configuration]'s class, and adds the provided [configuration] to the top of the stack.
* The operation is performed as one transaction. If there is already a component with the same configuration, it will not be recreated.
*
* Deprecated. Please use `Child Stack` instead. See the [documentation](https://arkivanov.github.io/Decompose/child-stack/overview/).
*/
@Deprecated("Use Child Stack instead")
fun <C : Any> Router<C, *>.bringToFront(configuration: C, onComplete: () -> Unit = {}) {
navigate(
transformer = { stack -> stack.filterNot { it::class == configuration::class } + configuration },
onComplete = { _, _ -> onComplete() },
)
}

val <C : Any, T : Any> Router<C, T>.activeChild: Child.Created<C, T> get() = state.value.activeChild
/**
* Deprecated. Please use `Child Stack` instead. See the [documentation](https://arkivanov.github.io/Decompose/child-stack/overview/).
*/
@Suppress("DeprecatedCallableAddReplaceWith")
@Deprecated("Use Child Stack instead")
val <C : Any, T : Any> Router<C, T>.activeChild: Child.Created<C, T>
get() = state.value.activeChild
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import kotlin.reflect.KClass
/**
* Creates a new [Router].
*
* Deprecated. Please use `Child Stack` instead. See the [documentation](https://arkivanov.github.io/Decompose/child-stack/overview/).
*
* @param initialStack a stack of component configurations (from tail to head) that should be set if there is
* no saved state, must be not empty and unique
* @param configurationClass a [KClass] of the component configurations
Expand All @@ -16,6 +18,7 @@ import kotlin.reflect.KClass
* @param childFactory a factory function that creates new child instances
* @return a new instance of [Router]
*/
@Deprecated(message = "Use Child Stack instead")
fun <C : Parcelable, T : Any> ComponentContext.router(
initialStack: () -> List<C>,
configurationClass: KClass<out C>,
Expand Down Expand Up @@ -47,7 +50,11 @@ fun <C : Parcelable, T : Any> ComponentContext.router(

/**
* A convenience extension function for [ComponentContext.router].
*
* Deprecated. Please use `Child Stack` instead. See the [documentation](https://arkivanov.github.io/Decompose/child-stack/overview/).
*/
@Suppress("DeprecatedCallableAddReplaceWith")
@Deprecated(message = "Use Child Stack instead")
inline fun <reified C : Parcelable, T : Any> ComponentContext.router(
noinline initialStack: () -> List<C>,
key: String = "DefaultRouter",
Expand All @@ -64,7 +71,11 @@ inline fun <reified C : Parcelable, T : Any> ComponentContext.router(

/**
* A convenience extension function for [ComponentContext.router].
*
* Deprecated. Please use `Child Stack` instead. See the [documentation](https://arkivanov.github.io/Decompose/child-stack/overview/).
*/
@Suppress("DeprecatedCallableAddReplaceWith")
@Deprecated(message = "Use Child Stack instead")
inline fun <reified C : Parcelable, T : Any> ComponentContext.router(
initialConfiguration: C,
key: String = "DefaultRouter",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.arkivanov.decompose.router

import com.arkivanov.decompose.Child

@Deprecated("Use com.arkivanov.decompose.router.stack.RouterState instead")
data class RouterState<out C : Any, out T : Any>(
val activeChild: Child.Created<C, T>,
val backStack: List<Child<C, T>> = emptyList()
Expand Down
Loading

0 comments on commit 061f4e3

Please sign in to comment.