Skip to content

Commit

Permalink
#8 - Navigating to SingleAccountScreen with arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
jhg3410 committed Feb 24, 2023
1 parent e2e8fc5 commit 4fee6f8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ 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.accounts.SingleAccountScreen
import com.example.compose.rally.ui.bills.BillsScreen
import com.example.compose.rally.ui.components.RallyTabRow
import com.example.compose.rally.ui.overview.OverviewScreen
Expand Down Expand Up @@ -82,15 +83,30 @@ fun RallyApp() {
},
onClickSeeAllBills = {
navController.navigateSingleTopTo(Bills.route)
},
onAccountClick = { accountType ->
navController.navigateToSingAccount(accountType)
}
)
}
composable(route = Accounts.route) {
AccountsScreen()
AccountsScreen(
onAccountClick = { accountType ->
navController.navigateToSingAccount(accountType)
}
)
}
composable(route = Bills.route) {
BillsScreen()
}
composable(
route = SingleAccount.routeWithArgs,
arguments = SingleAccount.arguments
) { navBackStackEntry ->
val accountType =
navBackStackEntry.arguments?.getString(SingleAccount.accountTypeArg)
SingleAccountScreen(accountType = accountType)
}
}
}
}
Expand All @@ -106,4 +122,8 @@ fun NavHostController.navigateSingleTopTo(route: String) =
}
launchSingleTop = true
restoreState = true
}
}

fun NavHostController.navigateToSingAccount(accountType:String) {
this.navigateSingleTopTo("${SingleAccount.route}/$accountType")
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,9 @@ import androidx.compose.material.icons.filled.AttachMoney
import androidx.compose.material.icons.filled.Money
import androidx.compose.material.icons.filled.MoneyOff
import androidx.compose.material.icons.filled.PieChart
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.vector.ImageVector
import com.example.compose.rally.ui.accounts.AccountsScreen
import com.example.compose.rally.ui.accounts.SingleAccountScreen
import com.example.compose.rally.ui.bills.BillsScreen
import com.example.compose.rally.ui.overview.OverviewScreen
import androidx.navigation.NavType
import androidx.navigation.navArgument

/**
* Contract for information needed on every Rally navigation destination
Expand Down Expand Up @@ -60,6 +57,10 @@ object SingleAccount : RallyDestination {
override val icon = Icons.Filled.Money
override val route = "single_account"
const val accountTypeArg = "account_type"
val routeWithArgs = "${route}/{${accountTypeArg}}"
val arguments = listOf(
navArgument(accountTypeArg) { type = NavType.StringType }
)
}

// Screens to be displayed in the top RallyTabRow
Expand Down

0 comments on commit 4fee6f8

Please sign in to comment.