Skip to content

Commit

Permalink
Remove old ZiplineTreehouseUi.start overloads (#2477)
Browse files Browse the repository at this point in the history
These have been deprecated for more than one year.
  • Loading branch information
JakeWharton authored Nov 22, 2024
1 parent 365b927 commit ee74367
Show file tree
Hide file tree
Showing 9 changed files with 3 additions and 112 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

Breaking:
- Treehouse hosts running Redwood 0.11.0 or older are not longer actively supported. They will continue to work, but they will experience indefinite memory leaks of native widgets.
- Old, deprecated overloads of `ZiplineTreehouseUi.start` have been removed. The new overloads have been available since Redwood 0.8.0 for over a year.

New:
- `UIConfiguration.viewInsets` tracks the safe area of the specific `RedwoodView` being targeted. This is currently implemented for views on Android and UIViews on iOS.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,18 @@ package app.cash.redwood.treehouse

import androidx.compose.runtime.saveable.SaveableStateRegistry
import app.cash.redwood.compose.RedwoodComposition
import app.cash.redwood.protocol.Change
import app.cash.redwood.protocol.EventSink
import app.cash.redwood.protocol.guest.GuestProtocolAdapter
import app.cash.redwood.protocol.guest.ProtocolRedwoodComposition
import app.cash.redwood.ui.Cancellable
import app.cash.redwood.ui.OnBackPressedCallback
import app.cash.redwood.ui.OnBackPressedDispatcher
import app.cash.redwood.ui.UiConfiguration
import app.cash.zipline.ZiplineScope
import app.cash.zipline.ZiplineScoped
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Job
import kotlinx.coroutines.cancel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.job
import kotlinx.coroutines.plus

Expand Down Expand Up @@ -79,46 +76,7 @@ private class RedwoodZiplineTreehouseUi(

private lateinit var saveableStateRegistry: SaveableStateRegistry

@Suppress("OVERRIDE_DEPRECATION")
override fun start(
changesSink: ChangesSinkService,
uiConfigurations: StateFlow<UiConfiguration>,
stateSnapshot: StateSnapshot?,
) {
start(changesSink, NullOnBackPressedDispatcherService, uiConfigurations, stateSnapshot)
}

@Suppress("OVERRIDE_DEPRECATION")
override fun start(
changesSink: ChangesSinkService,
onBackPressedDispatcher: OnBackPressedDispatcherService,
uiConfigurations: StateFlow<UiConfiguration>,
stateSnapshot: StateSnapshot?,
) {
val host = object : ZiplineTreehouseUi.Host {
override val uiConfigurations = uiConfigurations
override val stateSnapshot = stateSnapshot

override fun sendChanges(changes: List<Change>) {
changesSink.sendChanges(changes)
}

override fun addOnBackPressedCallback(
onBackPressedCallbackService: OnBackPressedCallbackService,
): CancellableService = onBackPressedDispatcher.addCallback(onBackPressedCallbackService)
}

start(host, changesSink)
}

override fun start(host: ZiplineTreehouseUi.Host) {
start(host, host)
}

private fun start(
host: ZiplineTreehouseUi.Host,
changesSink: ChangesSinkService,
) {
this.saveableStateRegistry = SaveableStateRegistry(
restoredValues = host.stateSnapshot?.content,
// Note: values will only be restored by SaveableStateRegistry if `canBeSaved` returns true.
Expand All @@ -128,7 +86,7 @@ private class RedwoodZiplineTreehouseUi(
canBeSaved = { true },
)

guestAdapter.initChangesSink(changesSink)
guestAdapter.initChangesSink(host)

appLifecycle.addFrameListener(this)

Expand Down Expand Up @@ -190,10 +148,3 @@ private fun OnBackPressedCallback.asService() = object : OnBackPressedCallbackSe
enabledChangedCallback = null
}
}

private object NullOnBackPressedDispatcherService : OnBackPressedDispatcherService {
override fun addCallback(onBackPressedCallback: OnBackPressedCallbackService) =
object : CancellableService {
override fun cancel() = Unit
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import app.cash.redwood.ui.OnBackPressedCallback
import app.cash.redwood.ui.OnBackPressedDispatcher
import app.cash.redwood.ui.UiConfiguration
import app.cash.redwood.widget.Widget
import app.cash.zipline.ZiplineApiMismatchException
import app.cash.zipline.ZiplineScope
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineScope
Expand Down Expand Up @@ -500,16 +499,7 @@ private class ViewContentCodeBinding<A : AppService>(
stateSnapshot = viewOrNull?.stateSnapshotId?.let {
stateStore.get(it.value.orEmpty())
}
try {
treehouseUi.start(this@ViewContentCodeBinding)
} catch (e: ZiplineApiMismatchException) {
// Fall back to calling the function that doesn't have a back pressed dispatcher.
treehouseUi.start(
changesSink = this@ViewContentCodeBinding,
uiConfigurations = uiConfigurationFlow,
stateSnapshot = stateSnapshot,
)
}
treehouseUi.start(this@ViewContentCodeBinding)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ import app.cash.redwood.protocol.Id
import app.cash.redwood.protocol.PropertyChange
import app.cash.redwood.protocol.PropertyTag
import app.cash.redwood.protocol.WidgetTag
import app.cash.redwood.ui.UiConfiguration
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.serialization.json.JsonPrimitive

/**
Expand Down Expand Up @@ -90,25 +88,6 @@ class FakeZiplineTreehouseUi(
return result
}

@Suppress("OVERRIDE_DEPRECATION")
override fun start(
changesSink: ChangesSinkService,
onBackPressedDispatcher: OnBackPressedDispatcherService,
uiConfigurations: StateFlow<UiConfiguration>,
stateSnapshot: StateSnapshot?,
) {
error("unexpected call")
}

@Suppress("OVERRIDE_DEPRECATION")
override fun start(
changesSink: ChangesSinkService,
uiConfigurations: StateFlow<UiConfiguration>,
stateSnapshot: StateSnapshot?,
) {
error("unexpected call")
}

override fun close() {
for (cancellableService in extraServicesToClose) {
cancellableService.close()
Expand Down
2 changes: 0 additions & 2 deletions redwood-treehouse/api/android/redwood-treehouse.api
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,6 @@ public final class app/cash/redwood/treehouse/StateSnapshotKt {
public abstract interface class app/cash/redwood/treehouse/ZiplineTreehouseUi : app/cash/redwood/protocol/EventSink, app/cash/zipline/ZiplineService {
public static final field Companion Lapp/cash/redwood/treehouse/ZiplineTreehouseUi$Companion;
public fun snapshotState ()Lapp/cash/redwood/treehouse/StateSnapshot;
public abstract fun start (Lapp/cash/redwood/treehouse/ChangesSinkService;Lapp/cash/redwood/treehouse/OnBackPressedDispatcherService;Lkotlinx/coroutines/flow/StateFlow;Lapp/cash/redwood/treehouse/StateSnapshot;)V
public abstract fun start (Lapp/cash/redwood/treehouse/ChangesSinkService;Lkotlinx/coroutines/flow/StateFlow;Lapp/cash/redwood/treehouse/StateSnapshot;)V
public abstract fun start (Lapp/cash/redwood/treehouse/ZiplineTreehouseUi$Host;)V
}

Expand Down
2 changes: 0 additions & 2 deletions redwood-treehouse/api/jvm/redwood-treehouse.api
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,6 @@ public final class app/cash/redwood/treehouse/StateSnapshotKt {
public abstract interface class app/cash/redwood/treehouse/ZiplineTreehouseUi : app/cash/redwood/protocol/EventSink, app/cash/zipline/ZiplineService {
public static final field Companion Lapp/cash/redwood/treehouse/ZiplineTreehouseUi$Companion;
public fun snapshotState ()Lapp/cash/redwood/treehouse/StateSnapshot;
public abstract fun start (Lapp/cash/redwood/treehouse/ChangesSinkService;Lapp/cash/redwood/treehouse/OnBackPressedDispatcherService;Lkotlinx/coroutines/flow/StateFlow;Lapp/cash/redwood/treehouse/StateSnapshot;)V
public abstract fun start (Lapp/cash/redwood/treehouse/ChangesSinkService;Lkotlinx/coroutines/flow/StateFlow;Lapp/cash/redwood/treehouse/StateSnapshot;)V
public abstract fun start (Lapp/cash/redwood/treehouse/ZiplineTreehouseUi$Host;)V
}

Expand Down
2 changes: 0 additions & 2 deletions redwood-treehouse/api/redwood-treehouse.klib.api
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ abstract interface app.cash.redwood.treehouse/OnBackPressedDispatcherService : a
}

abstract interface app.cash.redwood.treehouse/ZiplineTreehouseUi : app.cash.redwood.protocol/EventSink, app.cash.zipline/ZiplineService { // app.cash.redwood.treehouse/ZiplineTreehouseUi|null[0]
abstract fun start(app.cash.redwood.treehouse/ChangesSinkService, app.cash.redwood.treehouse/OnBackPressedDispatcherService, kotlinx.coroutines.flow/StateFlow<app.cash.redwood.ui/UiConfiguration>, app.cash.redwood.treehouse/StateSnapshot?) // app.cash.redwood.treehouse/ZiplineTreehouseUi.start|start(app.cash.redwood.treehouse.ChangesSinkService;app.cash.redwood.treehouse.OnBackPressedDispatcherService;kotlinx.coroutines.flow.StateFlow<app.cash.redwood.ui.UiConfiguration>;app.cash.redwood.treehouse.StateSnapshot?){}[0]
abstract fun start(app.cash.redwood.treehouse/ChangesSinkService, kotlinx.coroutines.flow/StateFlow<app.cash.redwood.ui/UiConfiguration>, app.cash.redwood.treehouse/StateSnapshot?) // app.cash.redwood.treehouse/ZiplineTreehouseUi.start|start(app.cash.redwood.treehouse.ChangesSinkService;kotlinx.coroutines.flow.StateFlow<app.cash.redwood.ui.UiConfiguration>;app.cash.redwood.treehouse.StateSnapshot?){}[0]
abstract fun start(app.cash.redwood.treehouse/ZiplineTreehouseUi.Host) // app.cash.redwood.treehouse/ZiplineTreehouseUi.start|start(app.cash.redwood.treehouse.ZiplineTreehouseUi.Host){}[0]
open fun snapshotState(): app.cash.redwood.treehouse/StateSnapshot? // app.cash.redwood.treehouse/ZiplineTreehouseUi.snapshotState|snapshotState(){}[0]

Expand Down
6 changes: 0 additions & 6 deletions redwood-treehouse/api/zipline-api.toml
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,6 @@ functions = [
# fun snapshotState(): app.cash.redwood.treehouse.StateSnapshot
"mPBGCHFl",

# fun start(app.cash.redwood.treehouse.ChangesSinkService, app.cash.redwood.treehouse.OnBackPressedDispatcherService, kotlinx.coroutines.flow.StateFlow<app.cash.redwood.ui.UiConfiguration>, app.cash.redwood.treehouse.StateSnapshot): kotlin.Unit
"UkTy28z8",

# fun start(app.cash.redwood.treehouse.ChangesSinkService, kotlinx.coroutines.flow.StateFlow<app.cash.redwood.ui.UiConfiguration>, app.cash.redwood.treehouse.StateSnapshot): kotlin.Unit
"FiVQXMQW",

# fun start(app.cash.redwood.treehouse.ZiplineTreehouseUi.Host): kotlin.Unit
"h9yZr91W",
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,6 @@ public interface ZiplineTreehouseUi :
EventSink {
public fun start(host: Host)

@Deprecated("Use `start` method that takes in a Host")
public fun start(
changesSink: ChangesSinkService,
onBackPressedDispatcher: OnBackPressedDispatcherService,
uiConfigurations: StateFlow<UiConfiguration>,
stateSnapshot: StateSnapshot?,
)

@Deprecated(
"Use `start` method that takes in an `OnBackPressedDispatcherService` instead.",
ReplaceWith("start(changesSink, TODO(), uiConfigurations, stateSnapshot)"),
)
public fun start(
changesSink: ChangesSinkService,
uiConfigurations: StateFlow<UiConfiguration>,
stateSnapshot: StateSnapshot?,
)

public fun snapshotState(): StateSnapshot? = null

/** Access to the host that presents this UI. */
Expand Down

0 comments on commit ee74367

Please sign in to comment.