Skip to content

Commit

Permalink
Merge pull request #109 from VictorKabata/remove-precompose-deprication
Browse files Browse the repository at this point in the history
Resolved precompose deprecation warning
  • Loading branch information
VictorKabata authored Jan 3, 2024
2 parents 0f35864 + c14de55 commit c8cc138
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 43 deletions.
4 changes: 2 additions & 2 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@

## Checklist
<!-- Mark the completed items with [x] and provide any additional comments when necessary. -->
- [ ] I have tested the changes on both Android and iOS platforms.
- [ ] I have tested the changes on both Android, iOS and Desktop platforms.
- [ ] I have written unit tests for the new code ___(if applicable)___.
- [ ] I have updated the project's documentation ___(if necessary)___.
- [ ] I have checked for any potential code duplications and removed them.
- [ ] I have run the Kotlin/Compose Multiplatform Gradle tasks and verified that they complete successfully.
- [ ] I have run the Kotlin/Compose Multiplatform Gradle tasks and verified that they were completed successfully.
- [ ] I have considered the impact of these changes on the existing codebase.

## Additional Notes
Expand Down
1 change: 1 addition & 0 deletions appAndroid/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ dependencies {
api(project(":shared"))

implementation(libs.androidX.core)
implementation(libs.androidX.activity)

implementation(libs.material)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.vickbt.notflix.ui.activity

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.animation.ExperimentalAnimationApi
import com.vickbt.shared.ui.screens.main.MainScreen
import moe.tlaster.precompose.lifecycle.PreComposeActivity
import moe.tlaster.precompose.lifecycle.setContent

@ExperimentalAnimationApi
class MainActivity : PreComposeActivity() {
class MainActivity : ComponentActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.ApplicationScope
import androidx.compose.ui.window.Window
import androidx.compose.ui.window.WindowPosition
import androidx.compose.ui.window.rememberWindowState
import com.vickbt.shared.ui.screens.main.MainScreen
import moe.tlaster.precompose.PreComposeWindow

@Composable
fun MainWindow(applicationScope: ApplicationScope) {
PreComposeWindow(
Window(
onCloseRequest = { applicationScope.exitApplication() },
title = "Notflix",
state = rememberWindowState(
Expand Down
3 changes: 2 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ imageLoader = "1.7.1"
materialWindowSizeClass = "0.3.0"

#Android Versions
androidxActivity = "1.8.2"

#Desktop Versions
kamel = "0.4.0"
Expand Down Expand Up @@ -105,8 +106,8 @@ preCompose-viewmodel = { module = "moe.tlaster:precompose-viewmodel", version.re
material-windowSizeClass = { module = "dev.chrisbanes.material3:material3-window-size-class-multiplatform", version.ref = "materialWindowSizeClass" }

#Android Lib Dependencies
kotlin-stdlib = { module = "org.jetbrains.kotlin:kotlin-stdlib", version.ref = "kotlin" }
androidX-core = { module = "androidx.core:core-ktx", version.ref = "androidxCore" }
androidX-activity={module="androidx.activity:activity-compose", version.ref="androidxActivity"}
material = { module = "com.google.android.material:material", version.ref = "material" }
koin-android = { module = "io.insert-koin:koin-android", version.ref = "koinAndroid" }
koin-androidx-compose = { module = "io.insert-koin:koin-androidx-compose", version.ref = "koinAndroidxCompose" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ fun FavoritesScreen(navigator: Navigator, viewModel: FavoritesViewModel = koinIn
topBar = { AppBar("Favorites") }
) { paddingValues ->
Box(modifier = Modifier.fillMaxSize().padding(paddingValues)) {
LazyColumn(modifier = Modifier.fillMaxSize().padding(bottom = 90.dp)) {
LazyColumn(
modifier = Modifier.fillMaxSize()
.padding(bottom = 90.dp, start = 16.dp, end = 16.dp)
) {
items(items = favoriteMovies.favoriteMovies ?: emptyList()) { favoriteMovie ->
MovieCardDescription(
modifier = Modifier.fillMaxWidth().height(260.dp).padding(vertical = 4.dp),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,54 +18,57 @@ import com.vickbt.shared.ui.components.NavRailBar
import com.vickbt.shared.ui.navigation.Navigation
import com.vickbt.shared.ui.theme.NotflixTheme
import com.vickbt.shared.utils.WindowSize
import moe.tlaster.precompose.PreComposeApp
import moe.tlaster.precompose.navigation.rememberNavigator
import org.koin.compose.koinInject

@Composable
fun MainScreen(viewModel: MainViewModel = koinInject()) {
val appUiState = viewModel.mainUiState.collectAsState().value
var windowSize by remember { mutableStateOf(WindowSize.COMPACT) }
PreComposeApp {
val appUiState = viewModel.mainUiState.collectAsState().value
var windowSize by remember { mutableStateOf(WindowSize.COMPACT) }

val isDarkTheme = appUiState.selectedTheme != 0
val isDarkTheme = appUiState.selectedTheme != 0

NotflixTheme(darkTheme = isDarkTheme) {
val navigator = rememberNavigator()
NotflixTheme(darkTheme = isDarkTheme) {
val navigator = rememberNavigator()

val topLevelDestinations = listOf(
NavigationItem.Home,
NavigationItem.Favorites,
NavigationItem.Settings
)
val topLevelDestinations = listOf(
NavigationItem.Home,
NavigationItem.Favorites,
NavigationItem.Settings
)

val isTopLevelDestination =
navigator.currentEntry.collectAsState(null).value?.route?.route in topLevelDestinations.map { it.route }
val isTopLevelDestination =
navigator.currentEntry.collectAsState(null).value?.route?.route in topLevelDestinations.map { it.route }

val showNavigationRail = windowSize != WindowSize.COMPACT
val showNavigationRail = windowSize != WindowSize.COMPACT

Scaffold(
bottomBar = {
if (isTopLevelDestination && !showNavigationRail) {
BottomNavBar(bottomNavItems = topLevelDestinations, navigator = navigator)
Scaffold(
bottomBar = {
if (isTopLevelDestination && !showNavigationRail) {
BottomNavBar(bottomNavItems = topLevelDestinations, navigator = navigator)
}
}
}
) { paddingValues ->
) { paddingValues ->

BoxWithConstraints(modifier = Modifier.fillMaxSize()) {
windowSize = WindowSize.basedOnWidth(this.minWidth)
BoxWithConstraints(modifier = Modifier.fillMaxSize()) {
windowSize = WindowSize.basedOnWidth(this.minWidth)

Row(modifier = Modifier.fillMaxSize()) {
if (isTopLevelDestination && showNavigationRail) {
NavRailBar(
navigationItems = topLevelDestinations,
navigator = navigator
Row(modifier = Modifier.fillMaxSize()) {
if (isTopLevelDestination && showNavigationRail) {
NavRailBar(
navigationItems = topLevelDestinations,
navigator = navigator
)
}

Navigation(
navigator = navigator,
windowSize = windowSize,
paddingValues = paddingValues
)
}

Navigation(
navigator = navigator,
windowSize = windowSize,
paddingValues = paddingValues
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.vickbt.shared.utils

import androidx.compose.ui.window.ComposeUIViewController
import com.vickbt.shared.ui.screens.main.MainScreen
import moe.tlaster.precompose.PreComposeApplication

fun MainViewController() = PreComposeApplication { MainScreen() }
fun MainViewController() = ComposeUIViewController { MainScreen() }

0 comments on commit c8cc138

Please sign in to comment.