Skip to content

Commit

Permalink
Merge branch 'master' into compose-experimental
Browse files Browse the repository at this point in the history
  • Loading branch information
arkivanov committed Jul 26, 2023
2 parents de9e077 + 83023d7 commit 628d90b
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 40 deletions.
3 changes: 3 additions & 0 deletions decompose/api/android/decompose.api
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ public final class com/arkivanov/decompose/DefaultComponentContextBuilderKt {
public abstract interface annotation class com/arkivanov/decompose/ExperimentalDecomposeApi : java/lang/annotation/Annotation {
}

public abstract interface annotation class com/arkivanov/decompose/FaultyDecomposeApi : java/lang/annotation/Annotation {
}

public abstract interface annotation class com/arkivanov/decompose/InternalDecomposeApi : java/lang/annotation/Annotation {
}

Expand Down
3 changes: 3 additions & 0 deletions decompose/api/jvm/decompose.api
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ public final class com/arkivanov/decompose/DefaultComponentContext : com/arkivan
public abstract interface annotation class com/arkivanov/decompose/ExperimentalDecomposeApi : java/lang/annotation/Annotation {
}

public abstract interface annotation class com/arkivanov/decompose/FaultyDecomposeApi : java/lang/annotation/Annotation {
}

public abstract interface annotation class com/arkivanov/decompose/InternalDecomposeApi : java/lang/annotation/Annotation {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,11 @@ annotation class InternalDecomposeApi
@RequiresOptIn(level = RequiresOptIn.Level.WARNING)
@Retention(AnnotationRetention.BINARY)
annotation class ExperimentalDecomposeApi

/**
* Marks Decompose API, the implementation of which may contain bugs or known to contain bugs.
* See the docs of the annotated API for more information.
*/
@RequiresOptIn(level = RequiresOptIn.Level.WARNING)
@Retention(AnnotationRetention.BINARY)
annotation class FaultyDecomposeApi
2 changes: 1 addition & 1 deletion deps.versions.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[versions]

decompose = "2.0.0-compose-experimental"
decompose = "2.0.1-compose-experimental"
kotlin = "1.8.20"
essenty = "1.1.0"
parcelizeDarwin = "0.1.4"
Expand Down
20 changes: 20 additions & 0 deletions docs/component/instance-retaining.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,23 @@ class SomeComponent(
}
}
```

## Retained components (since v2.1.0-alpha-03)

Although discouraged, it is still possible to have all components retained over configuration changes on Android. On the one hand, this makes `InstanceKeeper` no longer required. But on the other hand, this prevents from supplying dependencies that capture the hosting `Activity` or `Fragment`.

!!!warning
Pay attention when supplying dependencies to a retained component to avoid leaking the hosting `Activity` or `Fragment`.

```kotlin
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

val root =
retainedComponent { componentContext ->
DefaultRootComponent(componentContext)
}
}
}
```
2 changes: 1 addition & 1 deletion docs/extensions/compose.md
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ val backDispatcher = BackDispatcher()
val componentContext =
DefaultComponentContext(
lifecycle = lifecycle,
backHandler = backHandler, // Pass BackDispatcher here
backHandler = backDispatcher, // Pass BackDispatcher here
)

val root = DefaultRootComponent(componentContext = componentContext)
Expand Down
10 changes: 5 additions & 5 deletions docs/navigation/stack/browser-history.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ config.devServer = {

Using `WebHistoryController` is easy:

1. Create an instance of `DefaultWebHistoryController` in the JS app and pass it via constructor to a component responsible for
navigation (typically it is the root component)
2. In the component, call the `WebHistoryController.attach` method and supply all arguments
3. In the JS app, pass an initial deeplink to the component
4. Use the deeplink in the component to generate an initial back stack
1. Create an instance of `DefaultWebHistoryController` in the JS app and pass it via constructor to a component responsible for navigation (typically it is the root component).
2. Create `Child Stack` and use `WebHistoryController#historyPaths` property for initial stack. This is required for cases when the page is reloaded (refreshed), so that the stack is aligned with te browser history.
3. In the component, call the `WebHistoryController.attach` method and supply all arguments.
4. In the JS app, pass an initial deeplink to the component.
5. Use the deeplink in the component to generate an initial back stack.

### Example

Expand Down
24 changes: 0 additions & 24 deletions docs/samples.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,30 +64,6 @@ Content:
<img src="https://raw.githubusercontent.com/arkivanov/Decompose/master/docs/media/SampleMultiPaneDesktop.png" width="392">
<img src="https://raw.githubusercontent.com/arkivanov/Decompose/master/docs/media/SampleMultiPaneWeb.gif" width="392">

## Sample Todo List App

<img src="https://raw.githubusercontent.com/JetBrains/compose-jb/master/examples/todoapp/screenshots/todo.png" width="384">

The Sample Todo List App demonstrates the following features:

* Multiplatform: Android, iOS, Desktop and Web
* Shared JetBrains Compose UI for Android and Desktop apps
* JetBrains (multiplatform) Compose UI for the Web browser app
* SwiftUI for iOS app
* Nested components
* Shared routing with view state preservation
* Using `Lifecycle`
* Multi-module structure (one component per module)
* Inter-component communication (via [Reaktive](https://github.com/badoo/Reaktive), just an example)
* MVI using [MVIKotlin](https://github.com/arkivanov/MVIKotlin)
* Data persistence using [SQLDelight](https://github.com/cashapp/sqldelight)

Please refer to the [sample's readme](https://github.com/JetBrains/compose-jb/blob/master/examples/todoapp/README.md) for more information.

### Source Code

The Sample Todo List App can be found in the JetBrains Compose repository [here](https://github.com/JetBrains/compose-jb/tree/master/examples/todoapp).

## Sample Greetings App

![](media/SampleGreetingsDemo.gif)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.arkivanov.decompose.extensions.compose.jetbrains.stack.animation
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import com.arkivanov.decompose.Child
import com.arkivanov.decompose.FaultyDecomposeApi
import com.arkivanov.decompose.router.stack.ChildStack

/**
Expand All @@ -21,9 +22,14 @@ fun interface StackAnimation<C : Any, T : Any> {
/**
* Creates an implementation of [StackAnimation] that allows different [StackAnimator]s.
*
* FaultyDecomposeApi. Please note that this API uses `movableContentOf` Compose API.
* Even though `movableContentOf` is not marked as experimental, it is known to contain bugs,
* e.g. https://issuetracker.google.com/issues/270656235, https://issuetracker.google.com/issues/290343159.
*
* @param disableInputDuringAnimation disables input and touch events while animating, default value is `true`.
* @param selector provides a [StackAnimator] for the current [Child], other [Child] and [Direction].
*/
@FaultyDecomposeApi
fun <C : Any, T : Any> stackAnimation(
disableInputDuringAnimation: Boolean = true,
selector: (child: Child.Created<C, T>, otherChild: Child.Created<C, T>, direction: Direction) -> StackAnimator?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import com.arkivanov.decompose.extensions.compose.jetbrains.stack.Children
import com.arkivanov.decompose.extensions.compose.jetbrains.stack.animation.fade
import com.arkivanov.decompose.extensions.compose.jetbrains.stack.animation.isFront
import com.arkivanov.decompose.extensions.compose.jetbrains.stack.animation.plus
import com.arkivanov.decompose.extensions.compose.jetbrains.stack.animation.scale
import com.arkivanov.decompose.extensions.compose.jetbrains.stack.animation.slide
import com.arkivanov.decompose.extensions.compose.jetbrains.stack.animation.stackAnimation
import com.arkivanov.decompose.router.stack.ChildStack
import com.arkivanov.decompose.value.MutableValue
Expand All @@ -25,13 +23,15 @@ internal fun CountersContent(component: CountersComponent, modifier: Modifier =
Children(
stack = component.childStack,
modifier = modifier,
animation = stackAnimation { _, _, direction ->
if (direction.isFront) {
slide() + fade()
} else {
scale(frontFactor = 1F, backFactor = 0.7F) + fade()
}
},
// Workaround for https://issuetracker.google.com/issues/270656235
animation = stackAnimation(fade() + scale())
// animation = stackAnimation { _, _, direction ->
// if (direction.isFront) {
// slide() + fade()
// } else {
// scale(frontFactor = 1F, backFactor = 0.7F) + fade()
// }
// },
) {
CounterContent(
component = it.instance,
Expand Down

0 comments on commit 628d90b

Please sign in to comment.