Skip to content

Commit 4efa408

Browse files
committed
Fix tests and lint issues.
Fixing the tests required addressing some underlying issues in `SearchBar`
1 parent 18c20e8 commit 4efa408

File tree

2 files changed

+16
-6
lines changed
  • features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/customreaction/picker
  • libraries/designsystem/src/main/kotlin/io/element/android/libraries/designsystem/theme/components

2 files changed

+16
-6
lines changed

features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/customreaction/picker/EmojiPickerPresenter.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import androidx.compose.runtime.getValue
1313
import androidx.compose.runtime.mutableStateOf
1414
import androidx.compose.runtime.remember
1515
import androidx.compose.runtime.setValue
16+
import androidx.compose.ui.platform.LocalInspectionMode
1617
import io.element.android.emojibasebindings.Emoji
1718
import io.element.android.emojibasebindings.EmojibaseStore
1819
import io.element.android.libraries.architecture.Presenter
@@ -57,9 +58,13 @@ class EmojiPickerPresenter(
5758
}
5859
}
5960

61+
val isInPreview = LocalInspectionMode.current
6062
fun handleEvents(event: EmojiPickerEvents) {
6163
when (event) {
62-
is EmojiPickerEvents.ToggleSearchActive -> isSearchActive = event.isActive
64+
// For some reason, in preview mode the SearchBar emits this event with an `isActive = true` value automatically
65+
is EmojiPickerEvents.ToggleSearchActive -> if (!isInPreview) {
66+
isSearchActive = event.isActive
67+
}
6368
is EmojiPickerEvents.UpdateSearchQuery -> searchQuery = event.query
6469
}
6570
}
@@ -73,4 +78,3 @@ class EmojiPickerPresenter(
7378
)
7479
}
7580
}
76-

libraries/designsystem/src/main/kotlin/io/element/android/libraries/designsystem/theme/components/SearchBar.kt

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ import androidx.compose.material3.TextFieldColors
2323
import androidx.compose.material3.TextFieldDefaults
2424
import androidx.compose.runtime.Composable
2525
import androidx.compose.runtime.Immutable
26+
import androidx.compose.runtime.LaunchedEffect
27+
import androidx.compose.runtime.getValue
2628
import androidx.compose.runtime.remember
29+
import androidx.compose.runtime.rememberUpdatedState
2730
import androidx.compose.ui.Modifier
2831
import androidx.compose.ui.graphics.Color
2932
import androidx.compose.ui.graphics.Shape
@@ -67,16 +70,19 @@ fun <T> SearchBar(
6770
) {
6871
val focusManager = LocalFocusManager.current
6972

70-
if (!active) {
71-
onQueryChange("")
72-
focusManager.clearFocus()
73+
val updatedOnQueryChange by rememberUpdatedState(onQueryChange)
74+
LaunchedEffect(active) {
75+
if (!active) {
76+
updatedOnQueryChange("")
77+
focusManager.clearFocus()
78+
}
7379
}
7480

7581
SearchBar(
7682
inputField = {
7783
SearchBarDefaults.InputField(
7884
query = query,
79-
onQueryChange = onQueryChange,
85+
onQueryChange = updatedOnQueryChange,
8086
onSearch = { focusManager.clearFocus() },
8187
expanded = active,
8288
onExpandedChange = onActiveChange,

0 commit comments

Comments
 (0)