Skip to content

Commit

Permalink
open search when clicking explore tab again (#127)
Browse files Browse the repository at this point in the history
  • Loading branch information
axiel7 committed Apr 22, 2024
1 parent c470cf7 commit 08eb594
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,11 @@ class NavActionManager(
}

fun toSearch() {
navController.navigate(NavDestination.Search.route())
navController.navigate(
NavDestination.Search.putArguments(
mapOf(NavArgument.Focus to TriBoolean.TRUE.value.toString())
)
)
}

fun toSearchOnMyList(mediaType: MediaType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ enum class NavDestination(

val namedNavArguments get() = arguments.map { it.toNamedNavArgument() }

fun putArguments(arguments: Map<NavArgument, String?>): String {
fun putArguments(arguments: Map<NavArgument, String?> = emptyMap()): String {
var routeWithArguments = route()
this.arguments.forEach { destArg ->
val value = arguments.getOrDefault(destArg.argument, null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import com.axiel7.anihyou.common.firstBlocking
import com.axiel7.anihyou.data.model.DeepLink
import com.axiel7.anihyou.ui.common.BottomDestination.Companion.toBottomDestinationIndex
import com.axiel7.anihyou.ui.common.Theme
import com.axiel7.anihyou.ui.common.navigation.NavActionManager
import com.axiel7.anihyou.ui.screens.home.HomeTab
import com.axiel7.anihyou.ui.screens.main.composables.MainBottomNavBar
import com.axiel7.anihyou.ui.screens.main.composables.MainNavigationRail
Expand Down Expand Up @@ -176,13 +177,15 @@ fun MainView(
deepLink: DeepLink?,
) {
val navController = rememberNavController()
val navActionManager = NavActionManager.rememberNavActionManager(navController)
val isCompactScreen = windowSizeClass.widthSizeClass == WindowWidthSizeClass.Compact

Scaffold(
bottomBar = {
if (isCompactScreen) {
MainBottomNavBar(
navController = navController,
navActionManager = navActionManager,
onItemSelected = saveLastTab
)
}
Expand All @@ -193,6 +196,7 @@ fun MainView(
if (isCompactScreen) {
MainNavigation(
navController = navController,
navActionManager = navActionManager,
isCompactScreen = true,
isLoggedIn = isLoggedIn,
lastTabOpened = lastTabOpened,
Expand All @@ -209,6 +213,7 @@ fun MainView(
)
MainNavigation(
navController = navController,
navActionManager = navActionManager,
isCompactScreen = false,
isLoggedIn = isLoggedIn,
lastTabOpened = lastTabOpened,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import com.axiel7.anihyou.ui.common.BottomDestination.Companion.toBottomDestinat
import com.axiel7.anihyou.ui.common.navigation.DestArgument.Companion.getBoolean
import com.axiel7.anihyou.ui.common.navigation.DestArgument.Companion.getIntArg
import com.axiel7.anihyou.ui.common.navigation.DestArgument.Companion.getStringArg
import com.axiel7.anihyou.ui.common.navigation.NavActionManager.Companion.rememberNavActionManager
import com.axiel7.anihyou.ui.common.navigation.NavActionManager
import com.axiel7.anihyou.ui.common.navigation.NavArgument
import com.axiel7.anihyou.ui.common.navigation.NavDestination
import com.axiel7.anihyou.ui.composables.FullScreenImageView
Expand Down Expand Up @@ -55,6 +55,7 @@ import com.axiel7.anihyou.ui.screens.usermedialist.UserMediaListHostView
@Composable
fun MainNavigation(
navController: NavHostController,
navActionManager: NavActionManager,
isCompactScreen: Boolean,
isLoggedIn: Boolean,
lastTabOpened: Int,
Expand All @@ -67,9 +68,6 @@ fun MainNavigation(
label = "bottom_bar_padding"
)

// common navigation actions
val navActionManager = rememberNavActionManager(navController)

LaunchedEffect(deepLink) {
if (deepLink != null) {
when (deepLink.type) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ import androidx.navigation.NavController
import androidx.navigation.NavGraph.Companion.findStartDestination
import androidx.navigation.compose.currentBackStackEntryAsState
import com.axiel7.anihyou.ui.common.BottomDestination
import com.axiel7.anihyou.ui.common.navigation.NavActionManager

@Composable
fun MainBottomNavBar(
navController: NavController,
navActionManager: NavActionManager,
onItemSelected: (Int) -> Unit,
) {
val navBackStackEntry by navController.currentBackStackEntryAsState()
Expand Down Expand Up @@ -55,13 +57,23 @@ fun MainBottomNavBar(
},
selected = isSelected,
onClick = {
onItemSelected(index)
navController.navigate(dest.route) {
popUpTo(navController.graph.findStartDestination().id) {
saveState = true
if (isSelected) {
when (dest) {
BottomDestination.Explore -> {
navActionManager.toSearch()
}

else -> {}
}
} else {
onItemSelected(index)
navController.navigate(dest.route) {
popUpTo(navController.graph.findStartDestination().id) {
saveState = true
}
launchSingleTop = true
restoreState = true
}
launchSingleTop = true
restoreState = true
}
}
)
Expand Down

0 comments on commit 08eb594

Please sign in to comment.