mirror of
https://github.com/LiveFastEatTrashRaccoon/RaccoonForLemmy.git
synced 2025-02-02 22:57:39 +01:00
fix(posts): crash due to serialization in main screen
This commit is contained in:
parent
345402435c
commit
1b353e893b
@ -3,7 +3,7 @@ package com.github.diegoberaldin.raccoonforlemmy.android
|
||||
import android.app.Application
|
||||
import com.github.diegoberaldin.racconforlemmy.core.utils.AppInfo
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.crashreport.CrashReportManager
|
||||
import com.github.diegoberaldin.raccoonforlemmy.sharedHelperModule
|
||||
import com.github.diegoberaldin.raccoonforlemmy.di.sharedHelperModule
|
||||
import org.koin.android.ext.android.inject
|
||||
import org.koin.android.ext.koin.androidContext
|
||||
import org.koin.android.ext.koin.androidLogger
|
||||
|
@ -1,4 +1,4 @@
|
||||
package com.github.diegoberaldin.raccoonforlemmy
|
||||
package com.github.diegoberaldin.raccoonforlemmy.di
|
||||
|
||||
import com.github.diegoberaldin.racconforlemmy.core.utils.hapticFeedbackModule
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.api.di.coreApiModule
|
||||
@ -17,6 +17,7 @@ import org.koin.dsl.module
|
||||
|
||||
val sharedHelperModule = module {
|
||||
includes(
|
||||
internalSharedModule,
|
||||
coreAppearanceModule,
|
||||
corePreferencesModule,
|
||||
coreApiModule,
|
@ -0,0 +1,9 @@
|
||||
package com.github.diegoberaldin.raccoonforlemmy.di
|
||||
|
||||
import com.github.diegoberaldin.raccoonforlemmy.MainViewModel
|
||||
import org.koin.java.KoinJavaComponent.inject
|
||||
|
||||
actual fun getMainViewModel(): MainViewModel {
|
||||
val res: MainViewModel by inject(MainViewModel::class.java)
|
||||
return res
|
||||
}
|
@ -20,6 +20,7 @@ import androidx.compose.ui.layout.onGloballyPositioned
|
||||
import androidx.compose.ui.unit.IntOffset
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.toSize
|
||||
import cafe.adriel.voyager.core.model.rememberScreenModel
|
||||
import cafe.adriel.voyager.core.screen.Screen
|
||||
import cafe.adriel.voyager.navigator.tab.CurrentTab
|
||||
import cafe.adriel.voyager.navigator.tab.TabNavigator
|
||||
@ -29,6 +30,7 @@ import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.md_theme_b
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.md_theme_dark_surface
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.md_theme_light_surface
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.di.getNavigationCoordinator
|
||||
import com.github.diegoberaldin.raccoonforlemmy.di.getMainViewModel
|
||||
import com.github.diegoberaldin.raccoonforlemmy.feature.home.ui.HomeTab
|
||||
import com.github.diegoberaldin.raccoonforlemmy.feature.inbox.ui.InboxTab
|
||||
import com.github.diegoberaldin.raccoonforlemmy.feature.profile.ui.ProfileTab
|
||||
@ -39,7 +41,6 @@ import kotlin.math.roundToInt
|
||||
|
||||
internal class MainScreen : Screen {
|
||||
|
||||
private var bottomBarOffsetHeightPx = mutableStateOf(0f)
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
@ -47,14 +48,18 @@ internal class MainScreen : Screen {
|
||||
val themeRepository = remember { getThemeRepository() }
|
||||
var bottomBarHeightPx by remember { mutableStateOf(0f) }
|
||||
val bottomNavBarCoordinator = remember { getNavigationCoordinator() }
|
||||
val model = rememberScreenModel { getMainViewModel() }
|
||||
|
||||
LaunchedEffect(bottomNavBarCoordinator) {
|
||||
val scrollConnection = object : NestedScrollConnection {
|
||||
override fun onPreScroll(available: Offset, source: NestedScrollSource): Offset {
|
||||
val delta = available.y
|
||||
val newOffset =
|
||||
(bottomBarOffsetHeightPx.value + delta).coerceIn(-bottomBarHeightPx, 0f)
|
||||
bottomBarOffsetHeightPx.value = newOffset
|
||||
(model.bottomBarOffsetHeightPx.value + delta).coerceIn(
|
||||
-bottomBarHeightPx,
|
||||
0f
|
||||
)
|
||||
model.bottomBarOffsetHeightPx.value = newOffset
|
||||
return Offset.Zero
|
||||
}
|
||||
}
|
||||
@ -80,7 +85,7 @@ internal class MainScreen : Screen {
|
||||
.offset {
|
||||
IntOffset(
|
||||
x = 0,
|
||||
y = -bottomBarOffsetHeightPx.value.roundToInt()
|
||||
y = -model.bottomBarOffsetHeightPx.value.roundToInt()
|
||||
)
|
||||
},
|
||||
contentPadding = PaddingValues(0.dp),
|
||||
|
@ -0,0 +1,10 @@
|
||||
package com.github.diegoberaldin.raccoonforlemmy
|
||||
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import cafe.adriel.voyager.core.model.ScreenModel
|
||||
|
||||
class MainViewModel : ScreenModel {
|
||||
|
||||
var bottomBarOffsetHeightPx = mutableStateOf(0f)
|
||||
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package com.github.diegoberaldin.raccoonforlemmy.di
|
||||
|
||||
import com.github.diegoberaldin.raccoonforlemmy.MainViewModel
|
||||
import org.koin.dsl.module
|
||||
|
||||
internal val internalSharedModule = module {
|
||||
factory { MainViewModel() }
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
package com.github.diegoberaldin.raccoonforlemmy.di
|
||||
|
||||
import com.github.diegoberaldin.raccoonforlemmy.MainViewModel
|
||||
|
||||
expect fun getMainViewModel(): MainViewModel
|
@ -1,4 +1,4 @@
|
||||
package com.github.diegoberaldin.raccoonforlemmy
|
||||
package com.github.diegoberaldin.raccoonforlemmy.di
|
||||
|
||||
import com.github.diegoberaldin.racconforlemmy.core.utils.AppInfo
|
||||
import com.github.diegoberaldin.racconforlemmy.core.utils.hapticFeedbackModule
|
||||
@ -20,6 +20,7 @@ import platform.Foundation.NSBundle
|
||||
fun initKoin() {
|
||||
startKoin {
|
||||
modules(
|
||||
internalSharedModule,
|
||||
coreAppearanceModule,
|
||||
corePreferencesModule,
|
||||
coreApiModule,
|
@ -0,0 +1,13 @@
|
||||
package com.github.diegoberaldin.raccoonforlemmy.di
|
||||
|
||||
import com.github.diegoberaldin.raccoonforlemmy.MainViewModel
|
||||
import org.koin.core.component.KoinComponent
|
||||
import org.koin.core.component.inject
|
||||
|
||||
actual fun getMainViewModel(): MainViewModel {
|
||||
return MainDiHelper.mainViewModel
|
||||
}
|
||||
|
||||
internal object MainDiHelper : KoinComponent {
|
||||
val mainViewModel: MainViewModel by inject()
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user