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

Re-expose FrameClock in guest code #2475

Merged
merged 1 commit into from
Nov 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
1 change: 1 addition & 0 deletions redwood-treehouse-guest/api/redwood-treehouse-guest.api
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
public final class app/cash/redwood/treehouse/StandardAppLifecycle : app/cash/redwood/treehouse/AppLifecycle {
public synthetic fun <init> (Lapp/cash/redwood/protocol/guest/ProtocolWidgetSystemFactory;Lkotlinx/serialization/json/Json;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun close ()V
public final fun getFrameClock ()Landroidx/compose/runtime/MonotonicFrameClock;
public fun getGuestProtocolVersion-7jYel6c ()Ljava/lang/String;
public fun sendFrame (J)V
public fun start (Lapp/cash/redwood/treehouse/AppLifecycle$Host;)V
Expand Down
2 changes: 2 additions & 0 deletions redwood-treehouse-guest/api/redwood-treehouse-guest.klib.api
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
final class app.cash.redwood.treehouse/StandardAppLifecycle : app.cash.redwood.treehouse/AppLifecycle { // app.cash.redwood.treehouse/StandardAppLifecycle|null[0]
constructor <init>(app.cash.redwood.protocol.guest/ProtocolWidgetSystemFactory, kotlinx.serialization.json/Json, kotlin/UInt) // app.cash.redwood.treehouse/StandardAppLifecycle.<init>|<init>(app.cash.redwood.protocol.guest.ProtocolWidgetSystemFactory;kotlinx.serialization.json.Json;kotlin.UInt){}[0]

final val frameClock // app.cash.redwood.treehouse/StandardAppLifecycle.frameClock|{}frameClock[0]
final fun <get-frameClock>(): androidx.compose.runtime/MonotonicFrameClock // app.cash.redwood.treehouse/StandardAppLifecycle.frameClock.<get-frameClock>|<get-frameClock>(){}[0]
final val guestProtocolVersion // app.cash.redwood.treehouse/StandardAppLifecycle.guestProtocolVersion|{}guestProtocolVersion[0]
final fun <get-guestProtocolVersion>(): app.cash.redwood.protocol/RedwoodVersion // app.cash.redwood.treehouse/StandardAppLifecycle.guestProtocolVersion.<get-guestProtocolVersion>|<get-guestProtocolVersion>(){}[0]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package app.cash.redwood.treehouse

import androidx.compose.runtime.BroadcastFrameClock
import androidx.compose.runtime.MonotonicFrameClock
import app.cash.redwood.protocol.EventTag
import app.cash.redwood.protocol.Id
import app.cash.redwood.protocol.RedwoodVersion
Expand Down Expand Up @@ -49,11 +51,12 @@ public class StandardAppLifecycle(
}
}

internal fun requestHostFrame() {
private val broadcastFrameClock = BroadcastFrameClock {
if (started) {
host.requestFrame()
}
}
public val frameClock: MonotonicFrameClock get() = broadcastFrameClock

internal val mismatchHandler: ProtocolMismatchHandler = object : ProtocolMismatchHandler {
override fun onUnknownEvent(widgetTag: WidgetTag, tag: EventTag) {
Expand Down Expand Up @@ -85,6 +88,7 @@ public class StandardAppLifecycle(
}

override fun sendFrame(timeNanos: Long) {
broadcastFrameClock.sendFrame(timeNanos)
for (frameListener in frameListeners) {
frameListener.onFrame(timeNanos)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
package app.cash.redwood.treehouse

import androidx.compose.runtime.BroadcastFrameClock
import androidx.compose.runtime.saveable.SaveableStateRegistry
import app.cash.redwood.compose.RedwoodComposition
import app.cash.redwood.protocol.Change
Expand Down Expand Up @@ -60,12 +59,7 @@ private class RedwoodZiplineTreehouseUi(
EventSink by guestAdapter,
StandardAppLifecycle.FrameListener {

private val clock = BroadcastFrameClock {
appLifecycle.requestHostFrame()
}

override fun onFrame(timeNanos: Long) {
clock.sendFrame(timeNanos)
guestAdapter.emitChanges()
}

Expand Down Expand Up @@ -139,7 +133,7 @@ private class RedwoodZiplineTreehouseUi(
appLifecycle.addFrameListener(this)

val composition = ProtocolRedwoodComposition(
scope = coroutineScope + clock,
scope = coroutineScope + appLifecycle.frameClock,
guestAdapter = guestAdapter,
widgetVersion = appLifecycle.widgetVersion,
onBackPressedDispatcher = host.asOnBackPressedDispatcher(),
Expand Down