Skip to content

Commit

Permalink
Re-expose FrameClock in guest code (#2475)
Browse files Browse the repository at this point in the history
It can be used for other things.
  • Loading branch information
JakeWharton authored Nov 21, 2024
1 parent 41c58b5 commit 033ddce
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
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

0 comments on commit 033ddce

Please sign in to comment.