Skip to content

Commit

Permalink
#8 - Extracting screen composables from RallyDestinations
Browse files Browse the repository at this point in the history
  • Loading branch information
jhg3410 committed Feb 23, 2023
1 parent c72dff9 commit e2e8fc5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.currentBackStackEntryAsState
import androidx.navigation.compose.rememberNavController
import com.example.compose.rally.ui.accounts.AccountsScreen
import com.example.compose.rally.ui.bills.BillsScreen
import com.example.compose.rally.ui.components.RallyTabRow
import com.example.compose.rally.ui.overview.OverviewScreen
import com.example.compose.rally.ui.theme.RallyTheme

/**
Expand All @@ -54,7 +57,8 @@ fun RallyApp() {
val currentBackStack by navController.currentBackStackEntryAsState()
val currentDestination = currentBackStack?.destination

val currentScreen = rallyTabRowScreens.find { it.route == currentDestination?.route } ?: Overview
val currentScreen =
rallyTabRowScreens.find { it.route == currentDestination?.route } ?: Overview
Scaffold(
topBar = {
RallyTabRow(
Expand All @@ -72,13 +76,20 @@ fun RallyApp() {
modifier = Modifier.padding(innerPadding)
) {
composable(route = Overview.route) {
Overview.screen()
OverviewScreen(
onClickSeeAllAccounts = {
navController.navigateSingleTopTo(Accounts.route)
},
onClickSeeAllBills = {
navController.navigateSingleTopTo(Bills.route)
}
)
}
composable(route = Accounts.route) {
Accounts.screen()
AccountsScreen()
}
composable(route = Bills.route) {
Bills.screen()
BillsScreen()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import com.example.compose.rally.ui.overview.OverviewScreen
interface RallyDestination {
val icon: ImageVector
val route: String
val screen: @Composable () -> Unit
}

/**
Expand All @@ -43,27 +42,23 @@ interface RallyDestination {
object Overview : RallyDestination {
override val icon = Icons.Filled.PieChart
override val route = "overview"
override val screen: @Composable () -> Unit = { OverviewScreen() }
}

object Accounts : RallyDestination {
override val icon = Icons.Filled.AttachMoney
override val route = "accounts"
override val screen: @Composable () -> Unit = { AccountsScreen() }
}

object Bills : RallyDestination {
override val icon = Icons.Filled.MoneyOff
override val route = "bills"
override val screen: @Composable () -> Unit = { BillsScreen() }
}

object SingleAccount : RallyDestination {
// Added for simplicity, this icon will not in fact be used, as SingleAccount isn't
// part of the RallyTabRow selection
override val icon = Icons.Filled.Money
override val route = "single_account"
override val screen: @Composable () -> Unit = { SingleAccountScreen() }
const val accountTypeArg = "account_type"
}

Expand Down

0 comments on commit e2e8fc5

Please sign in to comment.