Skip to content

Commit

Permalink
[fix]解决导航动画的生命周期导致viewModel异常复用的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
cy745 committed Dec 29, 2024
1 parent 3e63d55 commit 4b5267f
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,9 @@ inline fun <reified T : ViewModel> Screen.screenVM(
qualifier: Qualifier? = null,
viewModelStoreOwner: ViewModelStoreOwner = checkNotNull(
value = getScreenViewModelStoreOwner() ?: LocalViewModelStoreOwner.current,
lazyMessage = { "No Registered ViewModelStoreOwner was provided via registerMap for ${T::class.java}" }
lazyMessage = { "No ViewModelStoreOwner was provided for ${T::class.java}" }
),
key: String? = null,
key: String? = this.key,
extras: CreationExtras = defaultExtras(viewModelStoreOwner),
scope: Scope = currentKoinScope(),
noinline parameters: ParametersDefinition? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ data class AlbumDetailScreen(

@Composable
override fun provideScreenActions(): List<ScreenAction> {
val vm = screenVM<AlbumDetailVM>()
val vm = screenVM<AlbumDetailVM>(
parameters = { parametersOf(albumId) }
)
val state by vm.state

return remember {
Expand Down Expand Up @@ -97,7 +99,9 @@ data class AlbumDetailScreen(

@Composable
override fun Content() {
val vm = screenVM<AlbumDetailVM>(parameters = { parametersOf(albumId) })
val vm = screenVM<AlbumDetailVM>(
parameters = { parametersOf(albumId) }
)
val songs by vm.songs
val state by vm.state
val album by vm.album
Expand Down
9 changes: 7 additions & 2 deletions lalbum/src/main/java/com/lalilu/lalbum/screen/AlbumsScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import com.lalilu.remixicon.editor.text
import com.lalilu.remixicon.media.albumFill
import com.lalilu.remixicon.system.menuSearchLine
import com.zhangke.krouter.annotation.Destination
import org.koin.core.parameter.parametersOf

@Destination("/pages/albums")
data class AlbumsScreen(
Expand All @@ -43,7 +44,9 @@ data class AlbumsScreen(

@Composable
override fun provideScreenActions(): List<ScreenAction> {
val albumsVM = screenVM<AlbumsVM>()
val albumsVM = screenVM<AlbumsVM>(
parameters = { parametersOf(albumsId) }
)
val state by albumsVM.state

return remember {
Expand Down Expand Up @@ -83,7 +86,9 @@ data class AlbumsScreen(

@Composable
override fun Content() {
val vm = screenVM<AlbumsVM>()
val vm = screenVM<AlbumsVM>(
parameters = { parametersOf(albumsId) }
)
val state by vm.state
val albums by vm.albums

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ data class ArtistDetailScreen(

@Composable
override fun provideScreenActions(): List<ScreenAction> {
val vm = screenVM<ArtistDetailVM>()
val vm = screenVM<ArtistDetailVM>(
parameters = { parametersOf(artistName) }
)
val state by vm.state

return remember {
Expand Down Expand Up @@ -99,7 +101,9 @@ data class ArtistDetailScreen(

@Composable
override fun Content() {
val vm = screenVM<ArtistDetailVM>(parameters = { parametersOf(artistName) })
val vm = screenVM<ArtistDetailVM>(
parameters = { parametersOf(artistName) }
)
val songs by vm.songs
val state by vm.state
val artist by vm.artist
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import androidx.compose.runtime.remember
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.stringResource
import cafe.adriel.voyager.core.screen.Screen
import cafe.adriel.voyager.core.screen.ScreenKey
import com.lalilu.RemixIcon
import com.lalilu.common.ext.requestFor
import com.lalilu.component.base.screen.ScreenAction
Expand Down Expand Up @@ -41,6 +42,7 @@ import org.koin.core.qualifier.named
data class PlaylistDetailScreen(
val playlistId: String
) : Screen, ScreenInfoFactory, ScreenActionFactory, ScreenBarFactory {
override val key: ScreenKey = "${super.key}:$playlistId"

@Composable
override fun provideScreenInfo(): ScreenInfo = remember {
Expand Down

0 comments on commit 4b5267f

Please sign in to comment.