Skip to content

Commit 87422bf

Browse files
fix(android): keep streamed Wear tail visible
Co-authored-by: JARVIS-Glasses <[email protected]>
1 parent 015036c commit 87422bf

2 files changed

Lines changed: 21 additions & 5 deletions

File tree

‎apps/android/wear/src/main/java/ai/openclaw/wear/WearScreens.kt‎

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,7 @@ private fun ThreadVoiceMode(
711711
val coroutineScope = rememberCoroutineScope()
712712
val visibleConversation = conversation.takeLast(VISIBLE_REALTIME_ENTRY_COUNT)
713713
val contentRevision = wearThreadContentRevision(visibleConversation, thinking)
714-
val latestItemIndex = visibleConversation.size + (if (thinking) 1 else 0) - 1
714+
val latestAnchorIndex = wearThreadLatestAnchorIndex(visibleConversation.size, thinking)
715715
var followState by remember { mutableStateOf(WearThreadFollowState()) }
716716

717717
LaunchedEffect(listState) {
@@ -737,8 +737,8 @@ private fun ThreadVoiceMode(
737737
realtimeActive = realtimeActive,
738738
)
739739
followState = update.state
740-
if (update.scrollToLatest && latestItemIndex >= 0) {
741-
listState.requestScrollToItem(latestItemIndex)
740+
if (update.scrollToLatest && latestAnchorIndex >= 0) {
741+
listState.requestScrollToItem(latestAnchorIndex)
742742
}
743743
}
744744

@@ -775,6 +775,10 @@ private fun ThreadVoiceMode(
775775
WearThreadThinking()
776776
}
777777
}
778+
// Follow a trailing anchor: centering a growing bubble can hide its newly streamed tail.
779+
item(key = "realtime-thread-end") {
780+
Spacer(modifier = Modifier.height(1.dp))
781+
}
778782
}
779783
}
780784
if (followState.hasNewContent) {
@@ -787,9 +791,9 @@ private fun ThreadVoiceMode(
787791
.border(1.dp, colors.voiceAccent, RoundedCornerShape(14.dp))
788792
.clickable(role = Role.Button) {
789793
followState = wearThreadFollowLatest(followState)
790-
if (latestItemIndex >= 0) {
794+
if (latestAnchorIndex >= 0) {
791795
coroutineScope.launch {
792-
listState.animateScrollToItem(latestItemIndex)
796+
listState.animateScrollToItem(latestAnchorIndex)
793797
}
794798
}
795799
}.padding(horizontal = 10.dp, vertical = 5.dp),
@@ -923,6 +927,11 @@ internal fun wearThreadContentRevision(
923927
)
924928
}
925929

930+
internal fun wearThreadLatestAnchorIndex(
931+
entryCount: Int,
932+
thinking: Boolean,
933+
): Int = if (entryCount == 0 && !thinking) -1 else entryCount + if (thinking) 1 else 0
934+
926935
internal fun nextWearThreadFollowForContent(
927936
state: WearThreadFollowState,
928937
contentRevision: WearThreadContentRevision,

‎apps/android/wear/src/test/java/ai/openclaw/wear/MainActivityTest.kt‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,13 @@ class MainActivityTest {
7474
assertFalse(continued.state.hasNewContent)
7575
}
7676

77+
@Test
78+
fun threadFollowTargetsTrailingAnchorAfterLatestContent() {
79+
assertEquals(-1, wearThreadLatestAnchorIndex(entryCount = 0, thinking = false))
80+
assertEquals(1, wearThreadLatestAnchorIndex(entryCount = 1, thinking = false))
81+
assertEquals(3, wearThreadLatestAnchorIndex(entryCount = 2, thinking = true))
82+
}
83+
7784
@Test
7885
fun threadFollowPreservesManualScrollUntilLatestIsRequested() {
7986
val initial =

0 commit comments

Comments
 (0)