Skip to content

Commit 8e1c34e

Browse files
authored
fix(android): keep the composer visible with slash suggestions (#130555)
1 parent c6fa27a commit 8e1c34e

4 files changed

Lines changed: 173 additions & 10 deletions

File tree

‎apps/android/app/src/main/java/ai/openclaw/app/AndroidScreenshotFixture.kt‎

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -462,13 +462,22 @@ internal object AndroidScreenshotFixture {
462462
put(
463463
"commands",
464464
buildJsonArray {
465-
add(
466-
buildJsonObject {
467-
put("name", JsonPrimitive("status"))
468-
put("description", JsonPrimitive("Show current OpenClaw status"))
469-
put("acceptsArgs", JsonPrimitive(false))
470-
},
471-
)
465+
listOf(
466+
Triple("help", "Show available commands.", false),
467+
Triple("commands", "List all slash commands.", false),
468+
Triple("tools", "List available runtime tools.", true),
469+
Triple("skill", "Run a skill by name.", true),
470+
Triple("learn", "Draft a reusable skill from recent work or named sources.", true),
471+
Triple("loop", "Loop a prompt: /loop [interval] <prompt> | /loop status | /loop stop [name]", true),
472+
).forEach { (name, description, acceptsArgs) ->
473+
add(
474+
buildJsonObject {
475+
put("name", JsonPrimitive(name))
476+
put("description", JsonPrimitive(description))
477+
put("acceptsArgs", JsonPrimitive(acceptsArgs))
478+
},
479+
)
480+
}
472481
},
473482
)
474483
put(

‎apps/android/app/src/main/java/ai/openclaw/app/ui/chat/ChatScreen.kt‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ import androidx.compose.foundation.rememberScrollState
101101
import androidx.compose.foundation.shape.CircleShape
102102
import androidx.compose.foundation.shape.RoundedCornerShape
103103
import androidx.compose.foundation.text.BasicTextField
104+
import androidx.compose.foundation.verticalScroll
104105
import androidx.compose.material.icons.Icons
105106
import androidx.compose.material.icons.automirrored.filled.Send
106107
import androidx.compose.material.icons.automirrored.filled.VolumeUp
@@ -2345,6 +2346,8 @@ private fun ChatComposer(
23452346
SlashCommandPanel(
23462347
commands = slashCommands,
23472348
onSelect = { command -> onValueChange(slashCommandCompletion(command)) },
2349+
// Reserve the editor and run controls before measuring suggestions.
2350+
modifier = Modifier.weight(1f, fill = false),
23482351
)
23492352
}
23502353

@@ -2615,9 +2618,10 @@ private fun ChatModelPickerRow(
26152618
private fun SlashCommandPanel(
26162619
commands: List<ChatCommandEntry>,
26172620
onSelect: (ChatCommandEntry) -> Unit,
2621+
modifier: Modifier,
26182622
) {
2619-
ClawPanel(contentPadding = PaddingValues(horizontal = 0.dp, vertical = 0.dp)) {
2620-
Column {
2623+
ClawPanel(modifier = modifier, contentPadding = PaddingValues(horizontal = 0.dp, vertical = 0.dp)) {
2624+
Column(modifier = Modifier.verticalScroll(rememberScrollState())) {
26212625
if (commands.isEmpty()) {
26222626
Text(
26232627
text = nativeString("No commands found"),

‎apps/android/app/src/test/java/ai/openclaw/app/AndroidScreenshotFixtureTest.kt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class AndroidScreenshotFixtureTest {
5050
?.content,
5151
)
5252
assertEquals(1, metadata["models"]?.jsonArray?.size)
53-
assertEquals(1, metadata["commands"]?.jsonArray?.size)
53+
assertEquals(6, metadata["commands"]?.jsonArray?.size)
5454
assertEquals(
5555
AndroidScreenshotFixture.cronJobName,
5656
cronJobs
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
package ai.openclaw.app.ui.chat
2+
3+
import ai.openclaw.app.AndroidScreenshotFixture
4+
import ai.openclaw.app.AndroidScreenshotScene
5+
import ai.openclaw.app.MainViewModel
6+
import ai.openclaw.app.NodeApp
7+
import ai.openclaw.app.NodeRuntime
8+
import ai.openclaw.app.NodeRuntimeMode
9+
import ai.openclaw.app.SecurePrefs
10+
import ai.openclaw.app.ui.design.ClawDesignTheme
11+
import android.content.Context
12+
import android.provider.Settings
13+
import androidx.compose.foundation.layout.Box
14+
import androidx.compose.foundation.layout.size
15+
import androidx.compose.ui.Modifier
16+
import androidx.compose.ui.draw.clipToBounds
17+
import androidx.compose.ui.platform.testTag
18+
import androidx.compose.ui.test.assertHasClickAction
19+
import androidx.compose.ui.test.assertIsDisplayed
20+
import androidx.compose.ui.test.assertTextEquals
21+
import androidx.compose.ui.test.getUnclippedBoundsInRoot
22+
import androidx.compose.ui.test.hasSetTextAction
23+
import androidx.compose.ui.test.junit4.v2.createComposeRule
24+
import androidx.compose.ui.test.onNodeWithContentDescription
25+
import androidx.compose.ui.test.onNodeWithTag
26+
import androidx.compose.ui.test.onNodeWithText
27+
import androidx.compose.ui.test.performClick
28+
import androidx.compose.ui.test.performScrollTo
29+
import androidx.compose.ui.test.performTextReplacement
30+
import androidx.compose.ui.unit.dp
31+
import androidx.lifecycle.SavedStateHandle
32+
import androidx.lifecycle.ViewModelStore
33+
import org.junit.After
34+
import org.junit.Assert.assertTrue
35+
import org.junit.Before
36+
import org.junit.Rule
37+
import org.junit.Test
38+
import org.junit.runner.RunWith
39+
import org.robolectric.RobolectricTestRunner
40+
import org.robolectric.RuntimeEnvironment
41+
import org.robolectric.annotation.Config
42+
import java.util.UUID
43+
44+
@RunWith(RobolectricTestRunner::class)
45+
@Config(sdk = [34], qualifiers = "w360dp-h800dp-420dpi")
46+
class ChatComposerLayoutTest {
47+
@get:Rule
48+
val composeRule = createComposeRule()
49+
50+
private lateinit var app: NodeApp
51+
private lateinit var prefs: SecurePrefs
52+
private lateinit var runtime: NodeRuntime
53+
private var originalRuntime: NodeRuntime? = null
54+
private val viewModelStore = ViewModelStore()
55+
private var originalAnimatorScale: String? = null
56+
57+
@Before
58+
fun setUp() {
59+
app = RuntimeEnvironment.getApplication() as NodeApp
60+
prefs = SecurePrefs(app, app.getSharedPreferences("chat-composer-${UUID.randomUUID()}", Context.MODE_PRIVATE))
61+
AndroidScreenshotFixture.configure(AndroidScreenshotScene.Chat)
62+
runtime = NodeRuntime(app, prefs, NodeRuntimeMode.ScreenshotFixture)
63+
originalRuntime = app.peekRuntime()
64+
setApplicationRuntime(runtime)
65+
originalAnimatorScale = Settings.Global.getString(app.contentResolver, Settings.Global.ANIMATOR_DURATION_SCALE)
66+
Settings.Global.putFloat(app.contentResolver, Settings.Global.ANIMATOR_DURATION_SCALE, 0f)
67+
}
68+
69+
@After
70+
fun tearDown() {
71+
viewModelStore.clear()
72+
setApplicationRuntime(originalRuntime)
73+
runtime.disconnect()
74+
AndroidScreenshotFixture.configure(AndroidScreenshotScene.Home)
75+
Settings.Global.putString(app.contentResolver, Settings.Global.ANIMATOR_DURATION_SCALE, originalAnimatorScale)
76+
}
77+
78+
@Test
79+
fun slashSuggestionsKeepEditorAndStopVisibleAndLastSuggestionReachable() {
80+
showChat()
81+
val editor = composeRule.onNode(hasSetTextAction())
82+
editor.performTextReplacement("/")
83+
editor.assertTextEquals("/")
84+
85+
assertEditorAndStopVisible()
86+
val lastSuggestion = composeRule.onNodeWithText("/loop").performScrollTo().assertIsDisplayed()
87+
assertEditorAndStopVisible()
88+
lastSuggestion.performClick()
89+
editor.assertTextEquals("/loop ")
90+
assertEditorAndStopVisible()
91+
}
92+
93+
@Test
94+
fun normalTextAndShortSuggestionListsKeepComposerVisible() {
95+
showChat()
96+
val editor = composeRule.onNode(hasSetTextAction())
97+
listOf("hello", "/help", "/unknown").forEach { input ->
98+
editor.performTextReplacement(input)
99+
editor.assertTextEquals(input)
100+
assertEditorAndStopVisible()
101+
}
102+
}
103+
104+
private fun showChat() {
105+
val viewModel = MainViewModel(app, prefs, SavedStateHandle())
106+
viewModelStore.put("chat", viewModel)
107+
viewModel.enterScreenshotFixtureMode(AndroidScreenshotScene.Chat)
108+
composeRule.setContent {
109+
ClawDesignTheme {
110+
// A portrait phone's remaining content viewport after its IME opens.
111+
Box(Modifier.size(width = 360.dp, height = 400.dp).clipToBounds().testTag("chat-viewport")) {
112+
ChatScreen(
113+
viewModel = viewModel,
114+
talkActive = false,
115+
showSidebarButton = true,
116+
onOpenSidebar = {},
117+
onToggleTalk = {},
118+
onOpenSessions = {},
119+
onOpenDashboard = {},
120+
onOpenGatewaySettings = {},
121+
)
122+
}
123+
}
124+
}
125+
composeRule.waitUntil { viewModel.chatCommands.value.size == 6 }
126+
}
127+
128+
private fun assertEditorAndStopVisible() {
129+
val viewport = composeRule.onNodeWithTag("chat-viewport").getUnclippedBoundsInRoot()
130+
val editorNode = composeRule.onNode(hasSetTextAction())
131+
val stopNode = composeRule.onNodeWithContentDescription("Stop")
132+
val editor = editorNode.getUnclippedBoundsInRoot()
133+
val stop = stopNode.getUnclippedBoundsInRoot()
134+
assertTrue("Editor must retain a visible line: $editor inside $viewport", editor.bottom > editor.top)
135+
assertTrue("Stop must retain its touch target: $stop inside $viewport", stop.bottom - stop.top >= 48.dp)
136+
for (bounds in listOf(editor, stop)) {
137+
assertTrue("Composer control must stay below the viewport top", bounds.top >= viewport.top)
138+
assertTrue("Composer control must stay above the viewport bottom", bounds.bottom <= viewport.bottom)
139+
}
140+
editorNode.assertIsDisplayed()
141+
stopNode.assertIsDisplayed().assertHasClickAction()
142+
}
143+
144+
private fun setApplicationRuntime(value: NodeRuntime?) {
145+
NodeApp::class.java
146+
.getDeclaredField("runtimeInstance")
147+
.apply { isAccessible = true }
148+
.set(app, value)
149+
}
150+
}

0 commit comments

Comments
 (0)