Skip to content

Commit

Permalink
Merge branch '2.x' of github.com:bumble-tech/appyx into 2.x-do-not-ap…
Browse files Browse the repository at this point in the history
…ply-if-no-gestures
  • Loading branch information
KovalevAndrey committed Jan 23, 2024
2 parents afb36ca + 6c419cf commit c252a00
Show file tree
Hide file tree
Showing 97 changed files with 552 additions and 1,029 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ Please refer to [2.0.0-alpha10 – Migration guide](2.0.0-alpha10.md)
- [#642](https://github.com/bumble-tech/appyx/pull/642) – Renamings
- [#643](https://github.com/bumble-tech/appyx/pull/643) – Unify AppyxComponent composable between appyx-navigation and appyx-interactions modules
- [#651](https://github.com/bumble-tech/appyx/pull/651) - Keep only one instance of SaveStateMap typealias and moved it to `com.bumble.appyx.utils.multiplatform` package
- [#654](https://github.com/bumble-tech/appyx/pull/654) - Renamings
- [#652](https://github.com/bumble-tech/appyx/pull/652) - KSP processor renamed from `mutable-ui-processor` to `appyx-processor`
- [#654](https://github.com/bumble-tech/appyx/pull/654) - Renamings
- [#657](https://github.com/bumble-tech/appyx/pull/657) - Rename ParentNode & Node to Node and LeafNode
- [#644](https://github.com/bumble-tech/appyx/pull/644) – Refactor AppyxComponent and application of draggable modifier

### Fixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ class Modal<InteractionTarget : Any>(
revertGestureSpec = animationSpec,
),
disableAnimations: Boolean = false,
isDebug: Boolean = false,
) : BaseAppyxComponent<InteractionTarget, ModalModel.State<InteractionTarget>>(
scope = scope,
model = model,
Expand All @@ -39,6 +38,5 @@ class Modal<InteractionTarget : Any>(
backPressStrategy = backPressStrategy,
defaultAnimationSpec = animationSpec,
gestureSettleConfig = gestureSettleConfig,
disableAnimations = disableAnimations,
isDebug = isDebug
disableAnimations = disableAnimations
)
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ class BackStack<InteractionTarget : Any>(
backPressStrategy: BackPressHandlerStrategy<InteractionTarget, BackStackModel.State<InteractionTarget>> =
PopBackstackStrategy(scope),
disableAnimations: Boolean = false,
isDebug: Boolean = false
) : BaseAppyxComponent<InteractionTarget, BackStackModel.State<InteractionTarget>>(
scope = scope,
model = model,
Expand All @@ -35,7 +34,6 @@ class BackStack<InteractionTarget : Any>(
gestureSettleConfig = gestureSettleConfig,
backPressStrategy = backPressStrategy,
defaultAnimationSpec = animationSpec,
disableAnimations = disableAnimations,
isDebug = isDebug
disableAnimations = disableAnimations
)

Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,14 @@ open class Spotlight<InteractionTarget : Any>(
revertGestureSpec = animationSpec,
),
disableAnimations: Boolean = false,
isDebug: Boolean = false
) : BaseAppyxComponent<InteractionTarget, SpotlightModel.State<InteractionTarget>>(
scope = scope,
model = model,
visualisation = visualisation,
gestureFactory = gestureFactory,
defaultAnimationSpec = animationSpec,
gestureSettleConfig = gestureSettleConfig,
disableAnimations = disableAnimations,
isDebug = isDebug
disableAnimations = disableAnimations
) {
val activeIndex: StateFlow<Float> = model.output
.mapState(scope) { it.currentTargetState.activeIndex }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import com.bumble.appyx.interactions.core.Element
import com.bumble.appyx.interactions.core.model.backpresshandlerstrategies.BackPressHandlerStrategy
import com.bumble.appyx.interactions.core.model.backpresshandlerstrategies.DontHandleBackPress
import com.bumble.appyx.interactions.core.model.progress.AnimatedProgressController
import com.bumble.appyx.interactions.core.model.progress.DebugProgressInputSource
import com.bumble.appyx.interactions.core.model.progress.DragProgressController
import com.bumble.appyx.interactions.core.model.progress.Draggable
import com.bumble.appyx.interactions.core.model.progress.HasDefaultAnimationSpec
Expand All @@ -17,12 +16,12 @@ import com.bumble.appyx.interactions.core.model.transition.Operation
import com.bumble.appyx.interactions.core.model.transition.Operation.Mode.IMMEDIATE
import com.bumble.appyx.interactions.core.model.transition.TransitionModel
import com.bumble.appyx.interactions.core.state.MutableSavedStateMap
import com.bumble.appyx.interactions.core.ui.DefaultAnimationSpec
import com.bumble.appyx.interactions.core.ui.Visualisation
import com.bumble.appyx.interactions.core.ui.context.TransitionBounds
import com.bumble.appyx.interactions.core.ui.context.TransitionBoundsAware
import com.bumble.appyx.interactions.core.ui.context.UiContext
import com.bumble.appyx.interactions.core.ui.context.UiContextAware
import com.bumble.appyx.interactions.core.ui.DefaultAnimationSpec
import com.bumble.appyx.interactions.core.ui.gesture.GestureFactory
import com.bumble.appyx.interactions.core.ui.gesture.GestureSettleConfig
import com.bumble.appyx.interactions.core.ui.output.ElementUiModel
Expand Down Expand Up @@ -56,7 +55,6 @@ open class BaseAppyxComponent<InteractionTarget : Any, ModelState : Any>(
private val backPressStrategy: BackPressHandlerStrategy<InteractionTarget, ModelState> = DontHandleBackPress(),
private val animateSettle: Boolean = false,
private val disableAnimations: Boolean = false,
private val isDebug: Boolean = false
) : AppyxComponent<InteractionTarget, ModelState>,
HasDefaultAnimationSpec<Float>,
Draggable,
Expand All @@ -82,7 +80,6 @@ open class BaseAppyxComponent<InteractionTarget : Any, ModelState : Any>(

private val instant = InstantProgressController(model = model)
private var animated: AnimatedProgressController<InteractionTarget, ModelState>? = null
private var debug: DebugProgressInputSource<InteractionTarget, ModelState>? = null
private val drag = DragProgressController(
model = model,
gestureFactory = { _gestureFactory },
Expand Down Expand Up @@ -141,12 +138,11 @@ open class BaseAppyxComponent<InteractionTarget : Any, ModelState : Any>(
override fun onAddedToComposition(scope: CoroutineScope) {
animationScope = scope
createAnimatedProgressController(scope)
createdDebugInputSource()
}

override fun onRemovedFromComposition() {
// TODO finish unfinished transitions
if (isDebug) debug?.stopModel() else animated?.stopModel()
animated?.stopModel()
animationScope?.cancel()
}

Expand All @@ -159,12 +155,6 @@ open class BaseAppyxComponent<InteractionTarget : Any, ModelState : Any>(
)
}

private fun createdDebugInputSource() {
debug = DebugProgressInputSource(
transitionModel = model,
)
}

override fun updateContext(uiContext: UiContext) {
if (this.uiContext != uiContext) {
this.uiContext = uiContext
Expand Down Expand Up @@ -238,9 +228,7 @@ open class BaseAppyxComponent<InteractionTarget : Any, ModelState : Any>(
animationSpec
)
val animatedSource = animated
val debugSource = debug
when {
(isDebug && debugSource != null) -> debugSource.operation(operation)
animatedSource == null || disableAnimations -> instant.operation(
operation
)
Expand Down Expand Up @@ -282,15 +270,11 @@ open class BaseAppyxComponent<InteractionTarget : Any, ModelState : Any>(
}

private fun settle(gestureSettleConfig: GestureSettleConfig) {
if (isDebug) {
debug?.settle()
} else {
animated?.settle(
completionThreshold = gestureSettleConfig.completionThreshold,
completeGestureSpec = gestureSettleConfig.completeGestureSpec,
revertGestureSpec = gestureSettleConfig.revertGestureSpec,
)
}
animated?.settle(
completionThreshold = gestureSettleConfig.completionThreshold,
completeGestureSpec = gestureSettleConfig.completeGestureSpec,
revertGestureSpec = gestureSettleConfig.revertGestureSpec,
)
}

// TODO plugin?!
Expand All @@ -300,10 +284,6 @@ open class BaseAppyxComponent<InteractionTarget : Any, ModelState : Any>(
scope.cancel()
}

fun setNormalisedProgress(progress: Float) {
debug?.setNormalisedProgress(progress)
}

override fun handleBackPress(): Boolean = backPressStrategy.handleBackPress()

override fun canHandeBackPress(): StateFlow<Boolean> = backPressStrategy.canHandleBackPress
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import com.bumble.appyx.utils.testing.ui.rules.AppyxTestActivity
import java.util.concurrent.CountDownLatch
import java.util.concurrent.TimeUnit

class AppyxTestScenario<T : Node>(
class AppyxTestScenario<T : Node<*>>(
private val composeTestRule: ComposeTestRule = createEmptyComposeRule(),
/** Add decorations like custom theme or CompositionLocalProvider. Do not forget to invoke `content()`. */
private val decorator: (@Composable (content: @Composable () -> Unit) -> Unit) = { content -> content() },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import com.bumble.appyx.navigation.AppyxTestScenario
import com.bumble.appyx.navigation.children.nodeOrNull
import com.bumble.appyx.navigation.composable.PermanentChild
import com.bumble.appyx.navigation.modality.NodeContext
import com.bumble.appyx.navigation.node.PermanentChildTest.TestParentNode.Child
import com.bumble.appyx.navigation.node.PermanentChildTest.TestNode.Child
import com.bumble.appyx.utils.multiplatform.Parcelable
import com.bumble.appyx.utils.multiplatform.Parcelize
import org.junit.Assert.assertEquals
Expand All @@ -22,8 +22,8 @@ import org.junit.Test

class PermanentChildTest {

var nodeFactory: (nodeContext: NodeContext) -> TestParentNode = {
TestParentNode(nodeContext = it)
var nodeFactory: (nodeContext: NodeContext) -> TestNode = {
TestNode(nodeContext = it)
}

@get:Rule
Expand Down Expand Up @@ -65,7 +65,7 @@ class PermanentChildTest {

private fun createPermanentAppyxComponentWithInteractionKey() {
nodeFactory = {
TestParentNode(
TestNode(
nodeContext = it,
permanentAppyxComponent = PermanentAppyxComponent(
savedStateMap = null,
Expand All @@ -76,11 +76,11 @@ class PermanentChildTest {

}

class TestParentNode(
class TestNode(
nodeContext: NodeContext,
private val permanentAppyxComponent: PermanentAppyxComponent<Child> =
PermanentAppyxComponent(savedStateMap = nodeContext.savedStateMap)
) : ParentNode<Child>(
) : Node<Child>(
nodeContext = nodeContext,
appyxComponent = permanentAppyxComponent
) {
Expand All @@ -90,7 +90,7 @@ class PermanentChildTest {

var renderPermanentChild by mutableStateOf(true)

override fun buildChildNode(navTarget: Child, nodeContext: NodeContext): Node =
override fun buildChildNode(navTarget: Child, nodeContext: NodeContext): Node<*> =
node(nodeContext) { modifier ->
BasicText(
text = navTarget.toString(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ import com.bumble.appyx.utils.customisations.NodeCustomisationDirectoryImpl


/**
* Composable function to host [Node].
* Composable function to host [Node<*>].
*
* This wrapper uses [LocalConfiguration] to provide [ScreenSize] automatically.
*/
@Suppress("ComposableParamOrder") // detekt complains as 'factory' param isn't a pure lambda
@Composable
fun <N : Node> NodeHost(
fun <N : Node<*>> NodeHost(
lifecycle: Lifecycle,
integrationPoint: IntegrationPoint,
modifier: Modifier = Modifier,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ package com.bumble.appyx.navigation.node

import com.bumble.appyx.navigation.platform.PlatformLifecycleRegistry

val Node.androidLifecycle: androidx.lifecycle.Lifecycle
val Node<*>.androidLifecycle: androidx.lifecycle.Lifecycle
get() = (lifecycle as PlatformLifecycleRegistry).androidLifecycleRegistry
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ import com.bumble.appyx.navigation.node.Node
// Changing this to an interface would be a breaking change
@Suppress("UnnecessaryAbstractClass")
abstract class Builder<P> {
abstract fun build(nodeContext: NodeContext, payload: P): Node
abstract fun build(nodeContext: NodeContext, payload: P): Node<*>
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ import com.bumble.appyx.navigation.node.Node
// Changing this to an interface would be a breaking change
@Suppress("UnnecessaryAbstractClass")
abstract class SimpleBuilder {
abstract fun build(nodeContext: NodeContext): Node
abstract fun build(nodeContext: NodeContext): Node<*>
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.bumble.appyx.navigation.node.Node
import com.bumble.appyx.navigation.plugin.NodeAware
import kotlin.reflect.KClass

interface ChildAware<N: Node> : NodeAware<N> {
interface ChildAware<N: Node<*>> : NodeAware<N> {

fun <T : Any> whenChildAttached(
child: KClass<T>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ import kotlin.reflect.safeCast

internal sealed class ChildAwareCallbackInfo {

abstract fun onRegistered(activeNodes: List<Node>)
abstract fun onRegistered(activeNodes: List<Node<*>>)

class Single<T : Any>(
private val child: KClass<T>,
private val callback: ChildCallback<T>,
private val parentLifecycle: Lifecycle,
) : ChildAwareCallbackInfo() {

fun onNewNodeAppeared(newNode: Node) {
fun onNewNodeAppeared(newNode: Node<*>) {
if (parentLifecycle.isDestroyed) return
val castedNode = child.safeCast(newNode)
if (castedNode != null) {
Expand All @@ -31,7 +31,7 @@ internal sealed class ChildAwareCallbackInfo {
}
}

override fun onRegistered(activeNodes: List<Node>) {
override fun onRegistered(activeNodes: List<Node<*>>) {
activeNodes.forEach { node ->
onNewNodeAppeared(node)
}
Expand All @@ -47,17 +47,17 @@ internal sealed class ChildAwareCallbackInfo {
) : ChildAwareCallbackInfo() {

fun onNewNodeAppeared(
activeNodes: Collection<Node>,
newNode: Node,
ignoreNodes: Set<Node>,
activeNodes: Collection<Node<*>>,
newNode: Node<*>,
ignoreNodes: Set<Node<*>>,
) {
val second = getOther(newNode) ?: return
activeNodes
.filter { second.isInstance(it) && it != newNode && it !in ignoreNodes }
.forEach { notify(newNode, it) }
}

override fun onRegistered(activeNodes: List<Node>) {
override fun onRegistered(activeNodes: List<Node<*>>) {
activeNodes.forEachIndexed { index, node ->
onNewNodeAppeared(
// Do not include already handled nodes to avoid call duplication
Expand All @@ -68,7 +68,7 @@ internal sealed class ChildAwareCallbackInfo {
}
}

private fun notify(node1: Node, node2: Node) {
private fun notify(node1: Node<*>, node2: Node<*>) {
if (parentLifecycle.isDestroyed) return
val lifecycle =
MinimumCombinedLifecycle(
Expand All @@ -83,7 +83,7 @@ internal sealed class ChildAwareCallbackInfo {
}
}

private fun getOther(node: Node): KClass<*>? =
private fun getOther(node: Node<*>): KClass<*>? =
when {
child1.isInstance(node) -> child2
child2.isInstance(node) -> child1
Expand Down
Loading

0 comments on commit c252a00

Please sign in to comment.