-
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b18b49d
commit 5c4e6a9
Showing
23 changed files
with
102 additions
and
220 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 55 additions & 24 deletions
79
desktopApp/src/jvmMain/kotlin/org/michaelbel/movies/MoviesDesktop.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,66 @@ | ||
package org.michaelbel.movies | ||
|
||
import androidx.compose.ui.window.singleWindowApplication | ||
import moe.tlaster.precompose.PreComposeApp | ||
import org.koin.core.context.startKoin | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.CompositionLocalProvider | ||
import androidx.compose.runtime.DisposableEffect | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.ui.window.Window | ||
import androidx.compose.ui.window.application | ||
import androidx.lifecycle.ViewModelStore | ||
import androidx.lifecycle.ViewModelStoreOwner | ||
import androidx.lifecycle.viewmodel.compose.LocalViewModelStoreOwner | ||
import org.michaelbel.movies.common.ThemeData | ||
import org.michaelbel.movies.common.theme.AppTheme | ||
import org.michaelbel.movies.di.appKoinModule | ||
import org.michaelbel.movies.ui.theme.MoviesTheme | ||
|
||
fun main() { | ||
startKoin { | ||
modules(appKoinModule) | ||
fun main() = application { | ||
Window(onCloseRequest = ::exitApplication, title = "Movies") { | ||
App() | ||
} | ||
} | ||
|
||
singleWindowApplication( | ||
title = "Movies", | ||
icon = null | ||
@Composable | ||
private fun App() = withViewModelStoreOwner { | ||
MoviesTheme( | ||
themeData = ThemeData( | ||
appTheme = AppTheme.FollowSystem, | ||
dynamicColors = false, | ||
paletteKey = 0, | ||
seedColor = 0 | ||
), | ||
theme = AppTheme.FollowSystem, | ||
enableEdgeToEdge = { _,_ -> } | ||
) { | ||
PreComposeApp { | ||
MoviesTheme( | ||
themeData = ThemeData( | ||
appTheme = AppTheme.FollowSystem, | ||
dynamicColors = false, | ||
paletteKey = 0, | ||
seedColor = 0 | ||
), | ||
theme = AppTheme.FollowSystem, | ||
enableEdgeToEdge = { _,_ -> } | ||
) { | ||
MainWindowContent() | ||
} | ||
} | ||
MainWindowContent() | ||
} | ||
} | ||
|
||
private class ComposeViewModelStoreOwner: ViewModelStoreOwner { | ||
override val viewModelStore = ViewModelStore() | ||
fun dispose() { viewModelStore.clear() } | ||
} | ||
|
||
@Composable | ||
private fun rememberComposeViewModelStoreOwner(): ViewModelStoreOwner { | ||
val viewModelStoreOwner = remember { ComposeViewModelStoreOwner() } | ||
DisposableEffect(viewModelStoreOwner) { | ||
onDispose { viewModelStoreOwner.dispose() } | ||
} | ||
return viewModelStoreOwner | ||
} | ||
|
||
@Composable | ||
internal fun withViewModelStoreOwner(content: @Composable () -> Unit) { | ||
if (LocalViewModelStoreOwner.current != null) { | ||
// Normal case: use system-provided owner | ||
content() | ||
} else { | ||
// Fallback case: use ViewModelStoreOwner with scope of this composable. | ||
// It's required for Compose Multiplatform for now because it's not providing default value yet. | ||
// Expected to be fixed in Compose Multiplatform 1.7.0 | ||
CompositionLocalProvider( | ||
LocalViewModelStoreOwner provides rememberComposeViewModelStoreOwner(), | ||
content = content | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.