Merge pull request #1022 from iamohdisa/feat/double-tap-search-focus

feat: double tap on search tab to focus on search input
This commit is contained in:
Muhammed Nayif Rahman 2026-05-13 14:04:01 +05:30 committed by GitHub
commit bc4beced9e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 33 additions and 2 deletions

View file

@ -531,6 +531,7 @@ private fun MainAppContent(
val hapticFeedback = LocalHapticFeedback.current
val coroutineScope = rememberCoroutineScope()
var selectedTab by rememberSaveable { mutableStateOf(AppScreenTab.Home) }
var searchFocusRequestCount by remember { mutableStateOf(0) }
val currentBackStackEntry by navController.currentBackStackEntryAsState()
val nativeRequestedTab by remember { NativeTabBridge.requestedTab }.collectAsStateWithLifecycle()
val liquidGlassNativeTabBarEnabled by remember {
@ -597,6 +598,9 @@ private fun MainAppContent(
LaunchedEffect(selectedTab) {
NativeTabBridge.publishSelectedTab(selectedTab.toNativeNavigationTab())
if (selectedTab != AppScreenTab.Search) {
searchFocusRequestCount = 0
}
}
DisposableEffect(
@ -1049,7 +1053,13 @@ private fun MainAppContent(
)
NavItem(
selected = selectedTab == AppScreenTab.Search,
onClick = { selectedTab = AppScreenTab.Search },
onClick = {
if (selectedTab == AppScreenTab.Search) {
searchFocusRequestCount++
} else {
selectedTab = AppScreenTab.Search
}
},
icon = Res.drawable.sidebar_search,
contentDescription = stringResource(Res.string.compose_nav_search),
)
@ -1083,6 +1093,7 @@ private fun MainAppContent(
.fillMaxSize()
.padding(innerPadding),
selectedTab = selectedTab,
searchFocusRequestCount = searchFocusRequestCount,
animateHomeCollectionGifs = tabsRouteActive,
onCatalogClick = onCatalogClick,
onPosterClick = { meta ->
@ -1137,7 +1148,13 @@ private fun MainAppContent(
if (isTabletLayout && !useNativeBottomTabs) {
TabletFloatingTopBar(
selectedTab = selectedTab,
onTabSelected = { selectedTab = it },
onTabSelected = { tab ->
if (tab == AppScreenTab.Search && selectedTab == AppScreenTab.Search) {
searchFocusRequestCount++
} else {
selectedTab = tab
}
},
onProfileSelected = onProfileSelected,
onAddProfileRequested = onSwitchProfile,
)
@ -2085,6 +2102,7 @@ private fun rememberGuardedPopBackStack(
private fun AppTabHost(
selectedTab: AppScreenTab,
modifier: Modifier = Modifier,
searchFocusRequestCount: Int = 0,
animateHomeCollectionGifs: Boolean = true,
onCatalogClick: ((HomeCatalogSection) -> Unit)? = null,
onPosterClick: ((MetaPreview) -> Unit)? = null,
@ -2132,6 +2150,7 @@ private fun AppTabHost(
modifier = Modifier.fillMaxSize(),
onPosterClick = onPosterClick,
onPosterLongClick = onPosterLongClick,
searchFocusRequestCount = searchFocusRequestCount,
)
}

View file

@ -33,6 +33,8 @@ import androidx.compose.runtime.snapshotFlow
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.Alignment
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.text.font.FontWeight
@ -80,7 +82,16 @@ fun SearchScreen(
modifier: Modifier = Modifier,
onPosterClick: ((MetaPreview) -> Unit)? = null,
onPosterLongClick: ((MetaPreview) -> Unit)? = null,
searchFocusRequestCount: Int = 0,
) {
val focusRequester = remember { FocusRequester() }
LaunchedEffect(searchFocusRequestCount) {
if (searchFocusRequestCount > 0) {
focusRequester.requestFocus()
}
}
LaunchedEffect(Unit) {
AddonRepository.initialize()
WatchedRepository.ensureLoaded()
@ -240,6 +251,7 @@ fun SearchScreen(
value = query,
onValueChange = { query = it },
placeholder = stringResource(Res.string.compose_search_placeholder),
modifier = Modifier.focusRequester(focusRequester),
trailingContent = if (query.isNotBlank()) {
{
IconButton(onClick = { query = "" }) {