Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flatten RedwoodView and RedwoodView.Root #2391

Merged
merged 5 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Fixed:
- Fix inconsistencies between iOS and Android for `Column` and `Row` layouts.

Breaking:
- Replace `CodeListener` with `RedwoodView.Root`. This puts the loading/error/ready state with the UI that displays that state.
- Replace `CodeListener` with new functions in `RedwoodView`. This puts the loading/error/ready state with the UI that displays that state.


## [0.15.0] - 2024-09-30
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public fun <W : Any> RedwoodComposition(
widgetSystem: WidgetSystem<W>,
onEndChanges: () -> Unit = {},
): RedwoodComposition {
view.root.children.remove(0, view.root.children.widgets.size)
view.children.remove(0, view.children.widgets.size)

val saveableStateRegistry = view.savedStateRegistry?.let { viewRegistry ->
val state = viewRegistry.consumeRestoredState()
Expand Down Expand Up @@ -95,7 +95,7 @@ public fun <W : Any> RedwoodComposition(

return RedwoodComposition(
scope,
view.root.children,
view.children,
view.onBackPressedDispatcher,
saveableStateRegistry,
view.uiConfiguration,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
public class app/cash/redwood/treehouse/composeui/ComposeUiRoot : app/cash/redwood/widget/RedwoodView$Root {
public class app/cash/redwood/treehouse/composeui/DynamicContent {
public static final field $stable I
public fun <init> ()V
public fun Render (Landroidx/compose/runtime/Composer;I)V
public fun contentState (IZLjava/lang/Throwable;)V
public synthetic fun getChildren ()Lapp/cash/redwood/widget/Widget$Children;
public fun getChildren ()Lapp/cash/redwood/widget/compose/ComposeWidgetChildren;
public fun getModifier ()Lapp/cash/redwood/Modifier;
public synthetic fun getValue ()Ljava/lang/Object;
public fun getValue ()Lkotlin/jvm/functions/Function2;
public fun restart (Lkotlin/jvm/functions/Function0;)V
public fun setModifier (Lapp/cash/redwood/Modifier;)V
public fun Render (Lapp/cash/redwood/widget/compose/ComposeWidgetChildren;Landroidx/compose/runtime/Composer;I)V
public fun contentState (Lkotlinx/coroutines/CoroutineScope;IZLjava/lang/Throwable;)V
public final fun getAttached ()Z
public final fun getLoadCount ()I
public final fun getRestart ()Lkotlin/jvm/functions/Function0;
public final fun getUncaughtException ()Ljava/lang/Throwable;
public final fun restart (Lkotlin/jvm/functions/Function0;)V
}

public final class app/cash/redwood/treehouse/composeui/TreehouseContentKt {
public static final fun TreehouseContent (Lapp/cash/redwood/treehouse/TreehouseApp;Lapp/cash/redwood/treehouse/TreehouseView$WidgetSystem;Lapp/cash/redwood/treehouse/TreehouseContentSource;Landroidx/compose/ui/Modifier;Lkotlin/jvm/functions/Function1;Landroidx/compose/runtime/Composer;II)V
public static final fun TreehouseContent (Lapp/cash/redwood/treehouse/TreehouseApp;Lapp/cash/redwood/treehouse/TreehouseView$WidgetSystem;Lapp/cash/redwood/treehouse/TreehouseContentSource;Landroidx/compose/ui/Modifier;Lapp/cash/redwood/treehouse/composeui/DynamicContent;Landroidx/compose/runtime/Composer;II)V
}

Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
public class app/cash/redwood/treehouse/composeui/ComposeUiRoot : app/cash/redwood/widget/RedwoodView$Root {
public class app/cash/redwood/treehouse/composeui/DynamicContent {
public static final field $stable I
public fun <init> ()V
public fun Render (Landroidx/compose/runtime/Composer;I)V
public fun contentState (IZLjava/lang/Throwable;)V
public synthetic fun getChildren ()Lapp/cash/redwood/widget/Widget$Children;
public fun getChildren ()Lapp/cash/redwood/widget/compose/ComposeWidgetChildren;
public fun getModifier ()Lapp/cash/redwood/Modifier;
public synthetic fun getValue ()Ljava/lang/Object;
public fun getValue ()Lkotlin/jvm/functions/Function2;
public fun restart (Lkotlin/jvm/functions/Function0;)V
public fun setModifier (Lapp/cash/redwood/Modifier;)V
public fun Render (Lapp/cash/redwood/widget/compose/ComposeWidgetChildren;Landroidx/compose/runtime/Composer;I)V
public fun contentState (Lkotlinx/coroutines/CoroutineScope;IZLjava/lang/Throwable;)V
public final fun getAttached ()Z
public final fun getLoadCount ()I
public final fun getRestart ()Lkotlin/jvm/functions/Function0;
public final fun getUncaughtException ()Ljava/lang/Throwable;
public final fun restart (Lkotlin/jvm/functions/Function0;)V
}

public final class app/cash/redwood/treehouse/composeui/TreehouseContentKt {
public static final fun TreehouseContent (Lapp/cash/redwood/treehouse/TreehouseApp;Lapp/cash/redwood/treehouse/TreehouseView$WidgetSystem;Lapp/cash/redwood/treehouse/TreehouseContentSource;Landroidx/compose/ui/Modifier;Lkotlin/jvm/functions/Function1;Landroidx/compose/runtime/Composer;II)V
public static final fun TreehouseContent (Lapp/cash/redwood/treehouse/TreehouseApp;Lapp/cash/redwood/treehouse/TreehouseView$WidgetSystem;Lapp/cash/redwood/treehouse/TreehouseContentSource;Landroidx/compose/ui/Modifier;Lapp/cash/redwood/treehouse/composeui/DynamicContent;Landroidx/compose/runtime/Composer;II)V
}

Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,24 @@
// - Show declarations: true

// Library unique name: <app.cash.redwood:redwood-treehouse-host-composeui>
open class app.cash.redwood.treehouse.composeui/ComposeUiRoot : app.cash.redwood.widget/RedwoodView.Root<kotlin/Function2<androidx.compose.runtime/Composer, kotlin/Int, kotlin/Unit>> { // app.cash.redwood.treehouse.composeui/ComposeUiRoot|null[0]
constructor <init>() // app.cash.redwood.treehouse.composeui/ComposeUiRoot.<init>|<init>(){}[0]
open class app.cash.redwood.treehouse.composeui/DynamicContent { // app.cash.redwood.treehouse.composeui/DynamicContent|null[0]
constructor <init>() // app.cash.redwood.treehouse.composeui/DynamicContent.<init>|<init>(){}[0]

open val children // app.cash.redwood.treehouse.composeui/ComposeUiRoot.children|{}children[0]
open fun <get-children>(): app.cash.redwood.widget.compose/ComposeWidgetChildren // app.cash.redwood.treehouse.composeui/ComposeUiRoot.children.<get-children>|<get-children>(){}[0]
open val value // app.cash.redwood.treehouse.composeui/ComposeUiRoot.value|{}value[0]
open fun <get-value>(): kotlin/Function2<androidx.compose.runtime/Composer, kotlin/Int, kotlin/Unit> // app.cash.redwood.treehouse.composeui/ComposeUiRoot.value.<get-value>|<get-value>(){}[0]
final var attached // app.cash.redwood.treehouse.composeui/DynamicContent.attached|{}attached[0]
final fun <get-attached>(): kotlin/Boolean // app.cash.redwood.treehouse.composeui/DynamicContent.attached.<get-attached>|<get-attached>(){}[0]
final var loadCount // app.cash.redwood.treehouse.composeui/DynamicContent.loadCount|{}loadCount[0]
final fun <get-loadCount>(): kotlin/Int // app.cash.redwood.treehouse.composeui/DynamicContent.loadCount.<get-loadCount>|<get-loadCount>(){}[0]
final var restart // app.cash.redwood.treehouse.composeui/DynamicContent.restart|{}restart[0]
final fun <get-restart>(): kotlin/Function0<kotlin/Unit>? // app.cash.redwood.treehouse.composeui/DynamicContent.restart.<get-restart>|<get-restart>(){}[0]
final var uncaughtException // app.cash.redwood.treehouse.composeui/DynamicContent.uncaughtException|{}uncaughtException[0]
final fun <get-uncaughtException>(): kotlin/Throwable? // app.cash.redwood.treehouse.composeui/DynamicContent.uncaughtException.<get-uncaughtException>|<get-uncaughtException>(){}[0]

open var modifier // app.cash.redwood.treehouse.composeui/ComposeUiRoot.modifier|{}modifier[0]
open fun <get-modifier>(): app.cash.redwood/Modifier // app.cash.redwood.treehouse.composeui/ComposeUiRoot.modifier.<get-modifier>|<get-modifier>(){}[0]
open fun <set-modifier>(app.cash.redwood/Modifier) // app.cash.redwood.treehouse.composeui/ComposeUiRoot.modifier.<set-modifier>|<set-modifier>(app.cash.redwood.Modifier){}[0]

open fun Render(androidx.compose.runtime/Composer?, kotlin/Int) // app.cash.redwood.treehouse.composeui/ComposeUiRoot.Render|Render(androidx.compose.runtime.Composer?;kotlin.Int){}[0]
open fun contentState(kotlin/Int, kotlin/Boolean, kotlin/Throwable?) // app.cash.redwood.treehouse.composeui/ComposeUiRoot.contentState|contentState(kotlin.Int;kotlin.Boolean;kotlin.Throwable?){}[0]
open fun restart(kotlin/Function0<kotlin/Unit>?) // app.cash.redwood.treehouse.composeui/ComposeUiRoot.restart|restart(kotlin.Function0<kotlin.Unit>?){}[0]
final fun restart(kotlin/Function0<kotlin/Unit>?) // app.cash.redwood.treehouse.composeui/DynamicContent.restart|restart(kotlin.Function0<kotlin.Unit>?){}[0]
open fun Render(app.cash.redwood.widget.compose/ComposeWidgetChildren, androidx.compose.runtime/Composer?, kotlin/Int) // app.cash.redwood.treehouse.composeui/DynamicContent.Render|Render(app.cash.redwood.widget.compose.ComposeWidgetChildren;androidx.compose.runtime.Composer?;kotlin.Int){}[0]
open fun contentState(kotlinx.coroutines/CoroutineScope, kotlin/Int, kotlin/Boolean, kotlin/Throwable?) // app.cash.redwood.treehouse.composeui/DynamicContent.contentState|contentState(kotlinx.coroutines.CoroutineScope;kotlin.Int;kotlin.Boolean;kotlin.Throwable?){}[0]
}

final val app.cash.redwood.treehouse.composeui/app_cash_redwood_treehouse_composeui_ComposeUiRoot$stableprop // app.cash.redwood.treehouse.composeui/app_cash_redwood_treehouse_composeui_ComposeUiRoot$stableprop|#static{}app_cash_redwood_treehouse_composeui_ComposeUiRoot$stableprop[0]
final val app.cash.redwood.treehouse.composeui/app_cash_redwood_treehouse_composeui_DynamicContent$stableprop // app.cash.redwood.treehouse.composeui/app_cash_redwood_treehouse_composeui_DynamicContent$stableprop|#static{}app_cash_redwood_treehouse_composeui_DynamicContent$stableprop[0]

final fun <#A: app.cash.redwood.treehouse/AppService> app.cash.redwood.treehouse.composeui/TreehouseContent(app.cash.redwood.treehouse/TreehouseApp<#A>, app.cash.redwood.treehouse/TreehouseView.WidgetSystem<kotlin/Function2<androidx.compose.runtime/Composer, kotlin/Int, kotlin/Unit>>, app.cash.redwood.treehouse/TreehouseContentSource<#A>, androidx.compose.ui/Modifier?, kotlin/Function1<kotlinx.coroutines/CoroutineScope, app.cash.redwood.widget/RedwoodView.Root<kotlin/Function2<androidx.compose.runtime/Composer, kotlin/Int, kotlin/Unit>>>?, androidx.compose.runtime/Composer?, kotlin/Int, kotlin/Int) // app.cash.redwood.treehouse.composeui/TreehouseContent|TreehouseContent(app.cash.redwood.treehouse.TreehouseApp<0:0>;app.cash.redwood.treehouse.TreehouseView.WidgetSystem<kotlin.Function2<androidx.compose.runtime.Composer,kotlin.Int,kotlin.Unit>>;app.cash.redwood.treehouse.TreehouseContentSource<0:0>;androidx.compose.ui.Modifier?;kotlin.Function1<kotlinx.coroutines.CoroutineScope,app.cash.redwood.widget.RedwoodView.Root<kotlin.Function2<androidx.compose.runtime.Composer,kotlin.Int,kotlin.Unit>>>?;androidx.compose.runtime.Composer?;kotlin.Int;kotlin.Int){0§<app.cash.redwood.treehouse.AppService>}[0]
final fun app.cash.redwood.treehouse.composeui/app_cash_redwood_treehouse_composeui_ComposeUiRoot$stableprop_getter(): kotlin/Int // app.cash.redwood.treehouse.composeui/app_cash_redwood_treehouse_composeui_ComposeUiRoot$stableprop_getter|app_cash_redwood_treehouse_composeui_ComposeUiRoot$stableprop_getter(){}[0]
final fun <#A: app.cash.redwood.treehouse/AppService> app.cash.redwood.treehouse.composeui/TreehouseContent(app.cash.redwood.treehouse/TreehouseApp<#A>, app.cash.redwood.treehouse/TreehouseView.WidgetSystem<kotlin/Function2<androidx.compose.runtime/Composer, kotlin/Int, kotlin/Unit>>, app.cash.redwood.treehouse/TreehouseContentSource<#A>, androidx.compose.ui/Modifier?, app.cash.redwood.treehouse.composeui/DynamicContent?, androidx.compose.runtime/Composer?, kotlin/Int, kotlin/Int) // app.cash.redwood.treehouse.composeui/TreehouseContent|TreehouseContent(app.cash.redwood.treehouse.TreehouseApp<0:0>;app.cash.redwood.treehouse.TreehouseView.WidgetSystem<kotlin.Function2<androidx.compose.runtime.Composer,kotlin.Int,kotlin.Unit>>;app.cash.redwood.treehouse.TreehouseContentSource<0:0>;androidx.compose.ui.Modifier?;app.cash.redwood.treehouse.composeui.DynamicContent?;androidx.compose.runtime.Composer?;kotlin.Int;kotlin.Int){0§<app.cash.redwood.treehouse.AppService>}[0]
final fun app.cash.redwood.treehouse.composeui/app_cash_redwood_treehouse_composeui_DynamicContent$stableprop_getter(): kotlin/Int // app.cash.redwood.treehouse.composeui/app_cash_redwood_treehouse_composeui_DynamicContent$stableprop_getter|app_cash_redwood_treehouse_composeui_DynamicContent$stableprop_getter(){}[0]
Original file line number Diff line number Diff line change
Expand Up @@ -16,37 +16,40 @@
package app.cash.redwood.treehouse.composeui

import androidx.compose.runtime.Composable
import app.cash.redwood.Modifier
import app.cash.redwood.widget.RedwoodView
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import app.cash.redwood.widget.compose.ComposeWidgetChildren
import kotlinx.coroutines.CoroutineScope

/**
* A default base implementation of [RedwoodView.Root].
*
* This composition contributes nothing to the view hierarchy. It delegates directly to its child
* views.
*/
public open class ComposeUiRoot : RedwoodView.Root<@Composable () -> Unit> {
override val children: ComposeWidgetChildren = ComposeWidgetChildren()

override var modifier: Modifier = Modifier
public open class DynamicContent {
public var loadCount: Int by mutableIntStateOf(0)
private set
public var attached: Boolean by mutableStateOf(false)
private set
public var uncaughtException: Throwable? by mutableStateOf(null)
private set
public var restart: (() -> Unit)? by mutableStateOf(null)
private set

override fun contentState(
public open fun contentState(
scope: CoroutineScope,
loadCount: Int,
attached: Boolean,
uncaughtException: Throwable?,
) {
this.loadCount = loadCount
this.attached = attached
this.uncaughtException = uncaughtException
}

override fun restart(restart: (() -> Unit)?) {
}

override val value: @Composable () -> Unit = {
Render()
public fun restart(restart: (() -> Unit)?) {
this.restart = restart
}

@Composable
public open fun Render() {
public open fun Render(children: ComposeWidgetChildren) {
children.Render()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,8 @@ import app.cash.redwood.ui.OnBackPressedDispatcher
import app.cash.redwood.ui.Size
import app.cash.redwood.ui.UiConfiguration
import app.cash.redwood.ui.dp as redwoodDp
import app.cash.redwood.widget.RedwoodView
import app.cash.redwood.widget.SavedStateRegistry
import kotlinx.coroutines.CoroutineScope
import app.cash.redwood.widget.compose.ComposeWidgetChildren
import kotlinx.coroutines.flow.MutableStateFlow

@Composable
Expand All @@ -56,7 +55,7 @@ public fun <A : AppService> TreehouseContent(
widgetSystem: WidgetSystem<@Composable () -> Unit>,
contentSource: TreehouseContentSource<A>,
modifier: Modifier = Modifier,
root: ((CoroutineScope) -> RedwoodView.Root<@Composable () -> Unit>) = { _ -> ComposeUiRoot() },
dynamicContent: DynamicContent = DynamicContent(),
) {
val onBackPressedDispatcher = platformOnBackPressedDispatcher()
val scope = rememberCoroutineScope()
Expand All @@ -75,7 +74,20 @@ public fun <A : AppService> TreehouseContent(
)
val treehouseView = remember(widgetSystem) {
object : TreehouseView<@Composable () -> Unit> {
override val root: RedwoodView.Root<@Composable () -> Unit> = root(scope)
override val children: ComposeWidgetChildren = ComposeWidgetChildren()

override val value: @Composable () -> Unit = {
dynamicContent.Render(children)
}

override fun contentState(loadCount: Int, attached: Boolean, uncaughtException: Throwable?) {
dynamicContent.contentState(scope, loadCount, attached, uncaughtException)
}

override fun restart(restart: (() -> Unit)?) {
dynamicContent.restart(restart)
}

override val onBackPressedDispatcher = onBackPressedDispatcher
override val uiConfiguration = MutableStateFlow(uiConfiguration)

Expand Down Expand Up @@ -106,7 +118,7 @@ public fun <A : AppService> TreehouseContent(
}
},
) {
treehouseView.root.value()
treehouseView.value()
}
}

Expand Down
13 changes: 8 additions & 5 deletions redwood-treehouse-host/api/android/redwood-treehouse-host.api
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,17 @@ public abstract interface class app/cash/redwood/treehouse/TreehouseDispatchers
public abstract fun getZipline ()Lkotlinx/coroutines/CoroutineDispatcher;
}

public final class app/cash/redwood/treehouse/TreehouseLayout : app/cash/redwood/widget/RedwoodLayout, app/cash/redwood/treehouse/TreehouseView {
public fun <init> (Landroid/content/Context;Lapp/cash/redwood/treehouse/TreehouseView$WidgetSystem;Landroidx/activity/OnBackPressedDispatcher;Lapp/cash/redwood/widget/RedwoodView$Root;)V
public synthetic fun <init> (Landroid/content/Context;Lapp/cash/redwood/treehouse/TreehouseView$WidgetSystem;Landroidx/activity/OnBackPressedDispatcher;Lapp/cash/redwood/widget/RedwoodView$Root;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun getReadyForContent ()Z
public class app/cash/redwood/treehouse/TreehouseLayout : app/cash/redwood/widget/RedwoodLayout, app/cash/redwood/treehouse/TreehouseView {
public fun <init> (Landroid/content/Context;Lapp/cash/redwood/treehouse/TreehouseView$WidgetSystem;Landroidx/activity/OnBackPressedDispatcher;)V
public final fun getReadyForContent ()Z
public fun getReadyForContentChangeListener ()Lapp/cash/redwood/treehouse/TreehouseView$ReadyForContentChangeListener;
public fun getSaveCallback ()Lapp/cash/redwood/treehouse/TreehouseView$SaveCallback;
public fun getStateSnapshotId-kwWZ-Q0 ()Ljava/lang/String;
public final fun getStateSnapshotId-kwWZ-Q0 ()Ljava/lang/String;
public fun getWidgetSystem ()Lapp/cash/redwood/treehouse/TreehouseView$WidgetSystem;
protected fun onAttachedToWindow ()V
protected fun onDetachedFromWindow ()V
protected fun onRestoreInstanceState (Landroid/os/Parcelable;)V
protected fun onSaveInstanceState ()Landroid/os/Parcelable;
public fun setReadyForContentChangeListener (Lapp/cash/redwood/treehouse/TreehouseView$ReadyForContentChangeListener;)V
public fun setSaveCallback (Lapp/cash/redwood/treehouse/TreehouseView$SaveCallback;)V
}
Expand Down
Loading