Skip to content

Commit

Permalink
Merge branch 'compose-experimental' into v2.2-compose-experimental
Browse files Browse the repository at this point in the history
  • Loading branch information
arkivanov committed Nov 17, 2023
2 parents d747458 + ceb8c4a commit ba2e4c1
Show file tree
Hide file tree
Showing 20 changed files with 245 additions and 233 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ Additional resources:
* Better separation of concerns
* Pluggable platform-specific UI (Compose, SwiftUI, React, etc.)
* Business logic code is testable with pure multiplatform unit tests
* Navigation state is fully exposed - plug any UI you want, animate as you like using your favourite UI framework's API or use predefined API.
* Navigation is a pure function from the old state to a new one - navigate without limits.
* Proper dependency injection (DI) and inversion of control (IoC) via constructor, including but not limited to type-safe arguments.
* Shared navigation logic
* Lifecycle-aware components
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,18 @@ import com.arkivanov.decompose.GettingList

/**
* A state holder for `Child Stack`.
*
* @param active the currently active (top) child of the stack.
* @param backStack the back stack (inactive children), can be empty.
*/
data class ChildStack<out C : Any, out T : Any>(
val active: Child.Created<C, T>,
val backStack: List<Child.Created<C, T>> = emptyList(),
) {

/**
* Creates [ChildStack] with only one child with the specified [configuration] and [instance].
*/
constructor(configuration: C, instance: T) : this(
active = Child.Created(
configuration = configuration,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@ import android.os.Bundle
import androidx.activity.compose.setContent
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Surface
import androidx.compose.ui.Modifier
import com.arkivanov.decompose.ExperimentalDecomposeApi
import com.arkivanov.decompose.defaultComponentContext
import com.arkivanov.decompose.extensions.android.DefaultViewContext
import com.arkivanov.essenty.lifecycle.essentyLifecycle
import com.arkivanov.sample.shared.dynamicfeatures.dynamicfeature.DefaultFeatureInstaller
import com.arkivanov.sample.shared.root.RootComponent
import com.arkivanov.sample.shared.root.DefaultRootComponent
import com.arkivanov.sample.shared.root.RootComponent
import com.arkivanov.sample.shared.root.RootContent
import com.arkivanov.sample.shared.root.RootView

Expand All @@ -38,11 +36,7 @@ class MainActivity : AppCompatActivity() {

private fun drawViaCompose(root: RootComponent) {
setContent {
MaterialTheme {
Surface(color = MaterialTheme.colors.background) {
RootContent(component = root, modifier = Modifier.fillMaxSize())
}
}
RootContent(component = root, modifier = Modifier.fillMaxSize())
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,6 @@ class SkikoAppDelegate @OverrideInit constructor() : UIResponder(), UIApplicatio

window!!.rootViewController = ComposeUIViewController {
Column {
// To skip upper part of screen.
Box(modifier = Modifier.height(64.dp))

PredictiveBackGestureOverlay(
backDispatcher = backDispatcher,
backIcon = { progress, _ ->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.arkivanov.sample.app

import androidx.compose.foundation.LocalScrollbarStyle
import androidx.compose.foundation.defaultScrollbarStyle
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
Expand All @@ -10,12 +8,10 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.material.AlertDialog
import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Surface
import androidx.compose.material.Text
import androidx.compose.material.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
Expand Down Expand Up @@ -72,13 +68,7 @@ fun main() {
state = windowState,
title = "Decompose Sample"
) {
Surface(modifier = Modifier.fillMaxSize()) {
MaterialTheme {
CompositionLocalProvider(LocalScrollbarStyle provides defaultScrollbarStyle()) {
RootContent(root)
}
}
}
RootContent(root)

if (isCloseRequested) {
SaveStateDialog(
Expand Down
18 changes: 0 additions & 18 deletions sample/app-ios/app-ios/CounterView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,21 +71,3 @@ struct CounterView_Previews: PreviewProvider {
CounterView(PreviewCounterComponent())
}
}

class PreviewCounterComponent : CounterComponent {
let model: Value<CounterComponentModel> = mutableValue(
CounterComponentModel(
title: "Counter 0",
text: "123",
isBackEnabled: false
)
)

let dialogSlot: Value<ChildSlot<AnyObject, DialogComponent>> =
mutableValue(ChildSlot(child: nil))

func onInfoClicked() {}
func onNextClicked() {}
func onPrevClicked() {}
}

8 changes: 0 additions & 8 deletions sample/app-ios/app-ios/CountersView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,3 @@ struct CountersView_Previews: PreviewProvider {
CountersView(PreviewCountersComponent())
}
}

class PreviewCountersComponent: CountersComponent {
var backHandler: BackHandler = BackDispatcherKt.BackDispatcher()
let childStack: Value<ChildStack<AnyObject, CounterComponent>> = simpleChildStack(PreviewCounterComponent())

func onBackClicked(toIndex: Int32) {}
func onBackClicked() {}
}
11 changes: 0 additions & 11 deletions sample/app-ios/app-ios/RootView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,3 @@ struct RootView_Previews: PreviewProvider {
RootView(PreviewRootComponent())
}
}

class PreviewRootComponent : RootComponent {
let childStack: Value<ChildStack<AnyObject, RootComponentChild>> =
simpleChildStack(RootComponentChild.CountersChild(component: PreviewCountersComponent()))

func onCountersTabClicked() {}
func onCardsTabClicked() {}
func onMultiPaneTabClicked() {}
func onDynamicFeaturesTabClicked() {}
func onCustomNavigationTabClicked() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -277,26 +277,3 @@ private data class Item<out T : Any>(
internal fun CardsContentPreview() {
CardsContent(PreviewCardsComponent())
}

internal class PreviewCardsComponent : CardsComponent {
override val stack: Value<ChildStack<*, CardComponent>> =
MutableValue(
ChildStack(
active = Child.Created(
configuration = 1,
instance = PreviewCardComponent(color = 0xFFFF0000),
),
backStack = listOf(
Child.Created(
configuration = 2,
instance = PreviewCardComponent(color = 0xFF0000FF),
)
),
)
)

override fun onCardSwiped(index: Int) {}
override fun onAddClicked() {}
override fun onRemoveClicked() {}
}

Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,3 @@ private fun Title(text: String) {
internal fun CardContentPreview() {
CardContent(component = PreviewCardComponent())
}

internal class PreviewCardComponent(
color: Long = 0xFFFF0000,
) : CardComponent {
override val model: Value<Model> =
MutableValue(
Model(
color = color,
title = "1",
status = "Status: Resumed",
text = "Count: 10",
)
)
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@file:Suppress("OPTIONAL_DECLARATION_USAGE_IN_NON_COMMON_SOURCE") // Workaround for KTIJ-22326

package com.arkivanov.sample.shared.counters

import androidx.compose.desktop.ui.tooling.preview.Preview
Expand All @@ -12,14 +14,7 @@ import com.arkivanov.decompose.extensions.compose.jetbrains.stack.animation.plus
import com.arkivanov.decompose.extensions.compose.jetbrains.stack.animation.predictiveback.predictiveBackAnimation
import com.arkivanov.decompose.extensions.compose.jetbrains.stack.animation.scale
import com.arkivanov.decompose.extensions.compose.jetbrains.stack.animation.stackAnimation
import com.arkivanov.decompose.router.stack.ChildStack
import com.arkivanov.decompose.value.MutableValue
import com.arkivanov.decompose.value.Value
import com.arkivanov.essenty.backhandler.BackDispatcher
import com.arkivanov.essenty.backhandler.BackHandler
import com.arkivanov.sample.shared.counters.counter.CounterComponent
import com.arkivanov.sample.shared.counters.counter.CounterContent
import com.arkivanov.sample.shared.counters.counter.PreviewCounterComponent

@Composable
internal fun CountersContent(component: CountersComponent, modifier: Modifier = Modifier) {
Expand Down Expand Up @@ -52,18 +47,3 @@ internal fun CountersContent(component: CountersComponent, modifier: Modifier =
internal fun CountersPreview() {
CountersContent(component = PreviewCountersComponent())
}

internal class PreviewCountersComponent : CountersComponent {
override val backHandler: BackHandler = BackDispatcher()

override val childStack: Value<ChildStack<*, CounterComponent>> =
MutableValue(
ChildStack(
configuration = Unit,
instance = PreviewCounterComponent(),
)
)

override fun onBackClicked() {}
override fun onBackClicked(toIndex: Int) {}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@file:Suppress("OPTIONAL_DECLARATION_USAGE_IN_NON_COMMON_SOURCE") // Workaround for KTIJ-22326

package com.arkivanov.sample.shared.counters.counter

import androidx.compose.desktop.ui.tooling.preview.Preview
Expand All @@ -18,11 +20,6 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.unit.dp
import com.arkivanov.decompose.extensions.compose.jetbrains.subscribeAsState
import com.arkivanov.decompose.router.slot.ChildSlot
import com.arkivanov.decompose.value.MutableValue
import com.arkivanov.decompose.value.Value
import com.arkivanov.sample.shared.counters.counter.CounterComponent.Model
import com.arkivanov.sample.shared.dialog.DialogComponent
import com.arkivanov.sample.shared.dialog.DialogContent

@Composable
Expand Down Expand Up @@ -94,21 +91,3 @@ internal fun CounterContent(component: CounterComponent, modifier: Modifier = Mo
internal fun CounterContentPreview() {
CounterContent(component = PreviewCounterComponent())
}

internal class PreviewCounterComponent : CounterComponent {
override val model: Value<Model> =
MutableValue(
Model(
title = "Counter 0",
text = "123",
isBackEnabled = false,
)
)

override val dialogSlot: Value<ChildSlot<Unit, DialogComponent>> =
MutableValue(ChildSlot())

override fun onNextClicked() {}
override fun onPrevClicked() {}
override fun onInfoClicked() {}
}
Loading

0 comments on commit ba2e4c1

Please sign in to comment.