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

View file

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