|
@@ -0,0 +1,99 @@
|
|
|
+package com.fastest.pass.dashboard.presentation.ui.component
|
|
|
+
|
|
|
+import androidx.compose.foundation.layout.Box
|
|
|
+import androidx.compose.foundation.layout.fillMaxSize
|
|
|
+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.LaunchedEffect
|
|
|
+import androidx.compose.runtime.mutableStateOf
|
|
|
+import androidx.compose.runtime.remember
|
|
|
+import androidx.compose.ui.Modifier
|
|
|
+import androidx.compose.ui.graphics.Color
|
|
|
+import androidx.compose.ui.platform.LocalContext
|
|
|
+import androidx.compose.ui.res.painterResource
|
|
|
+import androidx.compose.ui.viewinterop.AndroidView
|
|
|
+import androidx.fragment.app.FragmentActivity
|
|
|
+import androidx.fragment.app.FragmentContainerView
|
|
|
+import com.fastest.pass.R
|
|
|
+import com.fastest.pass.account.presentation.ui.fragment.AccountFragment
|
|
|
+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
|
|
|
+import com.fastest.pass.security.presentation.ui.fragment.SecurityFragment
|
|
|
+import com.fastest.pass.ui.theme.Gray_Splash
|
|
|
+
|
|
|
+@Composable
|
|
|
+fun BottomTab() {
|
|
|
+
|
|
|
+ val activity = LocalContext.current as FragmentActivity
|
|
|
+ var selectedTab = remember { mutableStateOf<Screen>(Screen.Home) }
|
|
|
+
|
|
|
+ Scaffold(
|
|
|
+ bottomBar = {
|
|
|
+ BottomNavigationBar(
|
|
|
+ selectedTab = selectedTab.value,
|
|
|
+ onTabSelected = { screen ->
|
|
|
+ selectedTab.value = screen
|
|
|
+ }
|
|
|
+ )
|
|
|
+ }
|
|
|
+ ) { paddingValues ->
|
|
|
+ Box(modifier = Modifier.padding(paddingValues)) {
|
|
|
+ // Add a container for hosting fragments
|
|
|
+ AndroidView(
|
|
|
+ factory = { context ->
|
|
|
+ FragmentContainerView(context).apply {
|
|
|
+ id = R.id.fragment_container_view
|
|
|
+ }
|
|
|
+ },
|
|
|
+ modifier = Modifier.fillMaxSize()
|
|
|
+ )
|
|
|
+
|
|
|
+ // Handle fragment replacement when the selected tab changes
|
|
|
+ LaunchedEffect(selectedTab.value) {
|
|
|
+ loadFragment(activity, selectedTab.value)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+@Composable
|
|
|
+fun BottomNavigationBar(selectedTab: Screen, onTabSelected: (Screen) -> Unit) {
|
|
|
+ val items = listOf(Screen.Home, Screen.Browse, Screen.Security, Screen.Account)
|
|
|
+
|
|
|
+ BottomNavigation(
|
|
|
+ backgroundColor = Gray_Splash
|
|
|
+ ) {
|
|
|
+ items.forEach { screen ->
|
|
|
+ BottomNavigationItem(
|
|
|
+ icon = { Icon(painterResource(id = screen.icon), contentDescription = null) },
|
|
|
+ label = { Text(screen.title) },
|
|
|
+ selected = selectedTab == screen,
|
|
|
+ onClick = { onTabSelected(screen) },
|
|
|
+ selectedContentColor = Color.Red, // You can customize selected item color
|
|
|
+ unselectedContentColor = Color.Gray
|
|
|
+ )
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+fun loadFragment(activity: FragmentActivity, screen: Screen) {
|
|
|
+ val fragment = when (screen) {
|
|
|
+ Screen.Home -> HomeFragment()// Replace with your actual fragments
|
|
|
+ Screen.Browse -> BrowseFragment()
|
|
|
+ Screen.Security -> SecurityFragment()
|
|
|
+ Screen.Account -> AccountFragment()
|
|
|
+ }
|
|
|
+
|
|
|
+ activity.supportFragmentManager.beginTransaction()
|
|
|
+ .replace(R.id.fragment_container_view, fragment)
|
|
|
+ .commit()
|
|
|
+}
|
|
|
+
|
|
|
+
|