Skip to content

Commit

Permalink
Remove old ZiplineTreehouseUi.start overloads
Browse files Browse the repository at this point in the history
These have been deprecated for more than one year.
  • Loading branch information
JakeWharton committed Nov 21, 2024
1 parent d496ac0 commit a608e3c
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 89 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 @@ -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
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 a608e3c

Please sign in to comment.