Skip to content

Commit 8574810

Browse files
committed
Merge branch 'search-bar-loop-fix'
2 parents 1021690 + 9de2225 commit 8574810

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

app/build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ android {
1414
applicationId = "org.nsh07.wikireader"
1515
minSdk = 26
1616
targetSdk = 36
17-
versionCode = 42
18-
versionName = "2.3.0"
17+
versionCode = 43
18+
versionName = "2.3.1"
1919

2020
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
2121
vectorDrawables {

app/src/main/java/org/nsh07/wikireader/ui/homeScreen/AppSearchBar.kt

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package org.nsh07.wikireader.ui.homeScreen
22

3+
import android.os.Build
4+
import androidx.activity.compose.BackHandler
35
import androidx.compose.animation.AnimatedContent
46
import androidx.compose.animation.core.AnimationSpec
57
import androidx.compose.animation.core.animateFloatAsState
@@ -68,6 +70,8 @@ import androidx.compose.runtime.derivedStateOf
6870
import androidx.compose.runtime.getValue
6971
import androidx.compose.runtime.mutableStateOf
7072
import androidx.compose.runtime.remember
73+
import androidx.compose.runtime.rememberCoroutineScope
74+
import androidx.compose.runtime.setValue
7175
import androidx.compose.ui.Alignment
7276
import androidx.compose.ui.BiasAlignment
7377
import androidx.compose.ui.Modifier
@@ -85,6 +89,8 @@ import androidx.compose.ui.unit.dp
8589
import androidx.compose.ui.unit.max
8690
import androidx.window.core.layout.WindowSizeClass
8791
import coil3.ImageLoader
92+
import kotlinx.coroutines.delay
93+
import kotlinx.coroutines.launch
8894
import org.nsh07.wikireader.R
8995
import org.nsh07.wikireader.data.WikiPrefixSearchResult
9096
import org.nsh07.wikireader.data.WikiSearchResult
@@ -130,6 +136,7 @@ fun AppSearchBar(
130136
) {
131137
val focusRequester = appSearchBarState.focusRequester
132138
val haptic = LocalHapticFeedback.current
139+
val scope = rememberCoroutineScope()
133140
val colorScheme = colorScheme
134141
val history = appSearchBarState.history.toList()
135142
val size = history.size
@@ -138,6 +145,17 @@ fun AppSearchBar(
138145

139146
val (showLanguageSheet, setShowLanguageSheet) = remember { mutableStateOf(false) }
140147

148+
var enabled by remember { mutableStateOf(Build.VERSION.SDK_INT >= 29) }
149+
150+
if (Build.VERSION.SDK_INT < 29) {
151+
LaunchedEffect(Unit) {
152+
scope.launch {
153+
delay(1000)
154+
enabled = true
155+
}
156+
}
157+
}
158+
141159
LaunchedEffect(textFieldState.text) {
142160
loadSearchDebounced(textFieldState.text.toString())
143161
}
@@ -174,7 +192,7 @@ fun AppSearchBar(
174192
}
175193
}
176194
} else null,
177-
enabled = searchBarEnabled,
195+
enabled = searchBarEnabled && enabled,
178196
modifier = Modifier
179197
.fillMaxWidth()
180198
.focusRequester(focusRequester)
@@ -290,6 +308,18 @@ fun AppSearchBar(
290308
},
291309
setSearchStr = updateLanguageSearchStr
292310
)
311+
312+
if (Build.VERSION.SDK_INT < 29) { // Workaround to fix the infinite search bar loop bug
313+
BackHandler(true) {
314+
scope.launch {
315+
enabled = false
316+
searchBarState.animateToCollapsed()
317+
delay(1000)
318+
enabled = true
319+
}
320+
}
321+
}
322+
293323
AnimatedContent(textFieldState.text.trim().isEmpty()) {
294324
when (it) {
295325
true ->
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This update fixes a critical bug that caused the search bar to get stuck in a loop on older Android versions

0 commit comments

Comments
 (0)