Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to NavigationSuiteScaffold #140

Draft
wants to merge 18 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 29 additions & 54 deletions app/src/main/kotlin/com/imashnake/animite/features/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,20 @@ import android.view.WindowManager
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.ExperimentalSharedTransitionApi
import androidx.compose.animation.SharedTransitionLayout
import androidx.compose.animation.slideInVertically
import androidx.compose.animation.slideOutVertically
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.LocalContentColor
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.currentBackStackEntryAsState
import androidx.navigation.compose.rememberNavController
import androidx.navigation.navDeepLink
import com.imashnake.animite.api.anilist.sanitize.media.MediaList
Expand All @@ -35,8 +29,6 @@ import com.imashnake.animite.features.media.MediaPage
import com.imashnake.animite.features.searchbar.SearchFrontDrop
import com.imashnake.animite.features.theme.AnimiteTheme
import com.imashnake.animite.navigation.HomeRoute
import com.imashnake.animite.navigation.NavigationBar
import com.imashnake.animite.navigation.NavigationBarPaths
import com.imashnake.animite.navigation.ProfileRoute
import com.imashnake.animite.navigation.SocialRoute
import com.imashnake.animite.profile.ProfileScreen
Expand Down Expand Up @@ -68,31 +60,23 @@ class MainActivity : ComponentActivity() {
}
}

@OptIn(ExperimentalSharedTransitionApi::class)
@OptIn(ExperimentalSharedTransitionApi::class, ExperimentalSharedTransitionApi::class)
@Composable
fun MainScreen(modifier: Modifier = Modifier) {
val navController = rememberNavController()

val currentBackStackEntry by navController.currentBackStackEntryAsState()
val isNavBarVisible = remember(currentBackStackEntry) {
if (currentBackStackEntry != null) {
NavigationBarPaths.entries.any { it.matchesDestination(currentBackStackEntry!!) }
} else {
false
}
}

// TODO: Refactor to use Scaffold once AnimatedVisibility issues are fixed;
// see https://issuetracker.google.com/issues/258270139.
Box(modifier) {
CompositionLocalProvider(
LocalContentColor provides MaterialTheme.colorScheme.onBackground
) {
Scaffold(
modifier = modifier,
contentWindowInsets = WindowInsets(0)
) {
Box(Modifier.padding(it)) {
SharedTransitionLayout {
NavHost(navController = navController, startDestination = HomeRoute) {
composable<HomeRoute> {
HomeScreen(
onNavigateToMediaItem = { navController.navigate(it) },
navController = navController,
sharedTransitionScope = this@SharedTransitionLayout,
animatedVisibilityScope = this,
)
Expand All @@ -108,42 +92,33 @@ fun MainScreen(modifier: Modifier = Modifier) {
navDeepLink { uriPattern = ANILIST_AUTH_DEEPLINK }
)
) {
ProfileScreen()
ProfileScreen(navController)
}
composable<SocialRoute> {
SocialScreen()
SocialScreen(navController)
}
}
}
}

SearchFrontDrop(
hasExtraPadding = isNavBarVisible,
onItemClick = { id, mediaType ->
navController.navigate(
MediaPage(
id = id,
source = MediaList.Type.SEARCH.name,
mediaType.rawValue
SearchFrontDrop(
hasExtraPadding = true,
onItemClick = { id, mediaType ->
navController.navigate(
MediaPage(
id = id,
source = MediaList.Type.SEARCH.name,
mediaType.rawValue
)
)
)
},
modifier = Modifier
.align(Alignment.BottomEnd)
.padding(
start = LocalPaddings.current.large,
end = LocalPaddings.current.large,
bottom = LocalPaddings.current.large
)
)

AnimatedVisibility(
visible = isNavBarVisible,
modifier = Modifier.align(Alignment.BottomCenter),
enter = slideInVertically { it },
exit = slideOutVertically { it }
) {
NavigationBar(navController = navController)
},
modifier = Modifier
.align(Alignment.BottomEnd)
.padding(
start = LocalPaddings.current.large,
end = LocalPaddings.current.large,
bottom = LocalPaddings.current.large
)
)
}
}
}
Loading
Loading