|
@@ -1,5 +1,6 @@
|
|
|
package com.fastest.pass.dashboard.presentation.ui.component
|
|
|
|
|
|
+import android.util.Log
|
|
|
import androidx.compose.foundation.Image
|
|
|
import androidx.compose.foundation.background
|
|
|
import androidx.compose.foundation.layout.Box
|
|
@@ -9,12 +10,16 @@ import androidx.compose.foundation.layout.height
|
|
|
import androidx.compose.foundation.layout.padding
|
|
|
import androidx.compose.material.BottomNavigation
|
|
|
import androidx.compose.material.BottomNavigationItem
|
|
|
+import androidx.compose.material3.Icon
|
|
|
import androidx.compose.material3.Scaffold
|
|
|
import androidx.compose.material3.Text
|
|
|
import androidx.compose.runtime.Composable
|
|
|
+import androidx.compose.runtime.DisposableEffect
|
|
|
import androidx.compose.runtime.LaunchedEffect
|
|
|
+import androidx.compose.runtime.getValue
|
|
|
import androidx.compose.runtime.mutableStateOf
|
|
|
import androidx.compose.runtime.remember
|
|
|
+import androidx.compose.runtime.setValue
|
|
|
import androidx.compose.ui.Alignment
|
|
|
import androidx.compose.ui.Modifier
|
|
|
import androidx.compose.ui.graphics.Color
|
|
@@ -26,8 +31,10 @@ import androidx.compose.ui.unit.dp
|
|
|
import androidx.compose.ui.viewinterop.AndroidView
|
|
|
import androidx.fragment.app.FragmentActivity
|
|
|
import androidx.fragment.app.FragmentContainerView
|
|
|
+import androidx.fragment.app.FragmentManager
|
|
|
import com.fastest.pass.R
|
|
|
import com.fastest.pass.account.presentation.ui.fragment.AccountFragment
|
|
|
+import com.fastest.pass.browse.presentation.ui.fragment.NewItemBrowseFragment
|
|
|
import com.fastest.pass.dashboard.domain.model.Screen
|
|
|
import com.fastest.pass.home.presentation.ui.fragment.BrowseFragment
|
|
|
import com.fastest.pass.home.presentation.ui.fragment.HomeFragment
|
|
@@ -36,18 +43,20 @@ import com.fastest.pass.ui.theme.Gray_Splash
|
|
|
|
|
|
@Composable
|
|
|
fun BottomTab() {
|
|
|
-
|
|
|
val activity = LocalContext.current as FragmentActivity
|
|
|
var selectedTab = remember { mutableStateOf<Screen>(Screen.Home) }
|
|
|
+ var isBottomBarVisible by remember { mutableStateOf(true) }
|
|
|
|
|
|
Scaffold(
|
|
|
bottomBar = {
|
|
|
- BottomNavigationBar(
|
|
|
- selectedTab = selectedTab.value,
|
|
|
- onTabSelected = { screen ->
|
|
|
- selectedTab.value = screen
|
|
|
- }
|
|
|
- )
|
|
|
+ if (isBottomBarVisible) {
|
|
|
+ BottomNavigationBar(
|
|
|
+ selectedTab = selectedTab.value,
|
|
|
+ onTabSelected = { screen ->
|
|
|
+ selectedTab.value = screen
|
|
|
+ }
|
|
|
+ )
|
|
|
+ }
|
|
|
}
|
|
|
) { paddingValues ->
|
|
|
Box(modifier = Modifier
|
|
@@ -65,14 +74,33 @@ fun BottomTab() {
|
|
|
modifier = Modifier.fillMaxSize()
|
|
|
)
|
|
|
|
|
|
+// DisposableEffect(key1 = activity) {
|
|
|
+// val listener = FragmentManager.OnBackStackChangedListener {
|
|
|
+// val currentFragment = activity.supportFragmentManager.fragments.lastOrNull()
|
|
|
+//
|
|
|
+// Log.d("test_navbar", "frag = ${currentFragment?.id} $currentFragment")
|
|
|
+//
|
|
|
+// isBottomBarVisible = when (currentFragment) {
|
|
|
+// is HomeFragment -> true
|
|
|
+// is BrowseFragment -> true
|
|
|
+// is AccountFragment -> true
|
|
|
+// is NewItemBrowseFragment -> false
|
|
|
+// else -> false
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// activity.supportFragmentManager.addOnBackStackChangedListener(listener)
|
|
|
+// onDispose {
|
|
|
+// activity.supportFragmentManager.removeOnBackStackChangedListener(listener)
|
|
|
+// }
|
|
|
+// }
|
|
|
+
|
|
|
// Handle fragment replacement when the selected tab changes
|
|
|
LaunchedEffect(selectedTab.value) {
|
|
|
loadFragment(activity, selectedTab.value)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
|
|
|
@Composable
|
|
@@ -82,7 +110,7 @@ fun BottomNavigationBar(selectedTab: Screen, onTabSelected: (Screen) -> Unit) {
|
|
|
|
|
|
BottomNavigation(
|
|
|
backgroundColor = colorResource(id = R.color.blue_login),
|
|
|
- contentColor = colorResource(id = R.color.gray_text),
|
|
|
+ contentColor = colorResource(id = R.color.white),
|
|
|
modifier = Modifier
|
|
|
.fillMaxWidth()
|
|
|
.height(70.dp),
|
|
@@ -95,10 +123,8 @@ fun BottomNavigationBar(selectedTab: Screen, onTabSelected: (Screen) -> Unit) {
|
|
|
Image(
|
|
|
painter = painterResource(id = screen.icon),
|
|
|
contentDescription = null,
|
|
|
- colorFilter = ColorFilter.tint(
|
|
|
- if (selectedTab == screen) colorResource(id = R.color.white)
|
|
|
- else colorResource(id = R.color.gray_text)
|
|
|
- ),
|
|
|
+ colorFilter = ColorFilter.tint(if (selectedTab == screen) colorResource(id = R.color.white)
|
|
|
+ else colorResource(id = R.color.gray_text)),
|
|
|
) },
|
|
|
label = {
|
|
|
Text(
|
|
@@ -109,14 +135,13 @@ fun BottomNavigationBar(selectedTab: Screen, onTabSelected: (Screen) -> Unit) {
|
|
|
},
|
|
|
selected = selectedTab == screen,
|
|
|
onClick = { onTabSelected(screen) },
|
|
|
- selectedContentColor = Color.Gray, // You can customize selected item color
|
|
|
- unselectedContentColor = Color.Gray
|
|
|
+ selectedContentColor = Color.Transparent, // You can customize selected item color
|
|
|
+ unselectedContentColor = Color.Transparent
|
|
|
)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
fun loadFragment(activity: FragmentActivity, screen: Screen) {
|
|
|
val fragment = when (screen) {
|
|
|
Screen.Home -> HomeFragment()// Replace with your actual fragments
|