Skip to content

Commit

Permalink
Merge pull request #16 from UmairKhalid786/feature/nested_navigation_…
Browse files Browse the repository at this point in the history
…introduced

Nested navigation introduced
  • Loading branch information
UmairKhalid786 authored Mar 27, 2023
2 parents b01b734 + 7585f21 commit da2f716
Show file tree
Hide file tree
Showing 14 changed files with 231 additions and 36 deletions.
23 changes: 23 additions & 0 deletions app/src/main/java/com/techlads/composetv/favorites/SearchScreen.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.techlads.composetv.favorites

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview

@Composable
fun FavoritesScreen(){
Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
Text(text = "Favorites")
}
}


@Preview
@Composable
fun FavoritesScreenPrev() {
FavoritesScreen()
}
16 changes: 16 additions & 0 deletions app/src/main/java/com/techlads/composetv/home/HomeNestedScreen.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.techlads.composetv.home

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import com.techlads.composetv.hero.HeroItem
import com.techlads.composetv.home.carousel.HomeCarousel

@Composable
fun HomeNestedScreen(){
Column(Modifier.fillMaxSize()) {
HeroItem()
HomeCarousel(Modifier.weight(1f))
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
package com.techlads.composetv.home

import androidx.compose.animation.ExperimentalAnimationApi
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.wrapContentWidth
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import com.google.accompanist.navigation.animation.rememberAnimatedNavController
import com.techlads.composetv.home.navigation.NestedHomeNavigation
import com.techlads.composetv.leftmenu.LeftMenu
import com.techlads.composetv.leftmenu.data.MenuData

@OptIn(ExperimentalAnimationApi::class)
@Composable
fun HomeScreenContent() {

val navController = rememberAnimatedNavController()

val isExpanded = remember {
mutableStateOf(false)
}
Expand All @@ -27,9 +33,10 @@ fun HomeScreenContent() {
isExpanded.value = !isExpanded.value && isSelected
}
) {

navController.navigate(it.id)
}
NestedHomeNavigation()

NestedHomeNavigation(navController)
}
}

Expand Down
15 changes: 0 additions & 15 deletions app/src/main/java/com/techlads/composetv/home/MenuData.kt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
package com.techlads.composetv.home.navigation

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.animation.ExperimentalAnimationApi
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import com.techlads.composetv.hero.HeroItem
import com.techlads.composetv.home.carousel.HomeCarousel
import androidx.navigation.NavHostController
import com.google.accompanist.navigation.animation.rememberAnimatedNavController

@Composable
fun NestedHomeNavigation() {
Column(Modifier.fillMaxSize()) {
HeroItem()
HomeCarousel(Modifier.weight(1f))
}
fun NestedHomeNavigation(navController: NavHostController) {
NestedHomeScreenNavigation(navController)
}

@OptIn(ExperimentalAnimationApi::class)
@Preview
@Composable
fun NestedHomeNavigationPrev() {
NestedHomeNavigation()
NestedHomeNavigation(rememberAnimatedNavController())
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package com.techlads.composetv.home.navigation

import androidx.compose.animation.ExperimentalAnimationApi
import androidx.compose.runtime.Composable
import androidx.navigation.NavHostController
import com.google.accompanist.navigation.animation.AnimatedNavHost
import com.google.accompanist.navigation.animation.composable
import com.techlads.composetv.favorites.FavoritesScreen
import com.techlads.composetv.home.HomeNestedScreen
import com.techlads.composetv.movies.MoviesScreen
import com.techlads.composetv.navigation.tabEnterTransition
import com.techlads.composetv.navigation.tabExitTransition
import com.techlads.composetv.search.SearchScreen
import com.techlads.composetv.settings.SettingsScreen
import com.techlads.composetv.songs.SongsScreen

@OptIn(ExperimentalAnimationApi::class)
@Composable
fun NestedHomeScreenNavigation(navController: NavHostController) {
AnimatedNavHost(navController = navController, startDestination = NestedScreens.Home.title) {
// e.g will add auth routes here if when we will extend project
composable(
NestedScreens.Home.title,
enterTransition = { tabEnterTransition() },
exitTransition = { tabExitTransition() }) {
HomeNestedScreen()
}

composable(
NestedScreens.Search.title,
enterTransition = { tabEnterTransition() },
exitTransition = { tabExitTransition() }) {
SearchScreen()
}

composable(
NestedScreens.Movies.title,
enterTransition = { tabEnterTransition() },
exitTransition = { tabExitTransition() }) {
MoviesScreen()
}

composable(
NestedScreens.Songs.title,
enterTransition = { tabEnterTransition() },
exitTransition = { tabExitTransition() }) {
SongsScreen()
}

composable(
NestedScreens.Favorites.title,
enterTransition = { tabEnterTransition() },
exitTransition = { tabExitTransition() }) {
FavoritesScreen()
}

composable(
NestedScreens.Settings.title,
enterTransition = { tabEnterTransition() },
exitTransition = { tabExitTransition() }) {
SettingsScreen()
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.techlads.composetv.home.navigation

sealed class NestedScreens(val title: String) {
object Home : NestedScreens("home")
object Search : NestedScreens("search")
object Movies : NestedScreens("movies")
object Songs : NestedScreens("songs")
object Favorites : NestedScreens("favourites")
object Settings : NestedScreens("settings")
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.techlads.composetv.home.navigation.NestedScreens
import com.techlads.composetv.leftmenu.model.MenuItem
import compose.icons.LineAwesomeIcons
import compose.icons.lineawesomeicons.CogSolid
Expand Down Expand Up @@ -63,7 +64,7 @@ fun LeftMenu(
)
Spacer(modifier = Modifier.weight(1f))
LeftMenuItem(
menuItem = MenuItem("", "Settings", LineAwesomeIcons.CogSolid),
menuItem = MenuItem(NestedScreens.Settings.title, "Settings", LineAwesomeIcons.CogSolid),
modifier = Modifier.fillMaxWidth(),
expanded = isExpanded,
onMenuFocused = onMenuFocused,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package com.techlads.composetv.leftmenu.data

import com.techlads.composetv.home.navigation.NestedScreens.*
import com.techlads.composetv.leftmenu.model.MenuItem
import compose.icons.LineAwesomeIcons
import compose.icons.lineawesomeicons.*

object MenuData {
val menuItems = listOf(
MenuItem("", "Home", LineAwesomeIcons.HomeSolid),
MenuItem("", "Search", LineAwesomeIcons.SearchSolid),
MenuItem("", "Movies", LineAwesomeIcons.VideoSolid),
MenuItem("", "Songs", LineAwesomeIcons.MusicSolid),
MenuItem("", "Favorites", LineAwesomeIcons.HeartSolid),
MenuItem(Home.title, "Home", LineAwesomeIcons.HomeSolid),
MenuItem(Search.title, "Search", LineAwesomeIcons.SearchSolid),
MenuItem(Movies.title, "Movies", LineAwesomeIcons.VideoSolid),
MenuItem(Songs.title, "Songs", LineAwesomeIcons.MusicSolid),
MenuItem(Favorites.title, "Favorites", LineAwesomeIcons.HeartSolid),
)
}
23 changes: 23 additions & 0 deletions app/src/main/java/com/techlads/composetv/movies/MoviesScreen.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.techlads.composetv.movies

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview

@Composable
fun MoviesScreen(){
Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
Text(text = "Movies")
}
}


@Preview
@Composable
fun MoviesScreenPrev() {
MoviesScreen()
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ fun AppNavigation(navController: NavHostController) {
}
}

private fun tabExitTransition(
fun tabExitTransition(
duration: Int = 500
) = fadeOut(tween(duration / 2, easing = LinearEasing))

private fun tabEnterTransition(
fun tabEnterTransition(
duration: Int = 500, delay: Int = duration - 350
) = fadeIn(tween(duration, duration - delay))

Expand Down
23 changes: 23 additions & 0 deletions app/src/main/java/com/techlads/composetv/search/SearchScreen.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.techlads.composetv.search

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview

@Composable
fun SearchScreen(){
Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
Text(text = "Search")
}
}


@Preview
@Composable
fun SearchScreenPrev() {
SearchScreen()
}
23 changes: 23 additions & 0 deletions app/src/main/java/com/techlads/composetv/settings/SearchScreen.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.techlads.composetv.settings

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview

@Composable
fun SettingsScreen(){
Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
Text(text = "Settings")
}
}


@Preview
@Composable
fun SettingsScreenPrev() {
SettingsScreen()
}
23 changes: 23 additions & 0 deletions app/src/main/java/com/techlads/composetv/songs/SearchScreen.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.techlads.composetv.songs

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview

@Composable
fun SongsScreen(){
Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
Text(text = "Songs")
}
}


@Preview
@Composable
fun SongsScreenPrev() {
SongsScreen()
}

0 comments on commit da2f716

Please sign in to comment.