Mark
12/16/2024, 5:28 AMStringResourceContext interface (essentially the subset of Android Context functions like getString) provided through DI (koin) throughout my app and am wondering whether it makes sense to also have LocalStringResourceContext for access in composable. Apparently, since the instance of this interface never changes, it doesn’t make sense and I can just use koinInject() instead. However, koinInject() is not a @ReadOnlyComposable and so cannot be used in @ReadOnlyComposable functions. (Code in thread)Mark
12/16/2024, 5:28 AMfun interface StringGetter {
operator fun invoke(context: StringResourceContext): String
@Composable
@ReadOnlyComposable
operator fun invoke() = invoke(LocalStringResourceContext.current)
instead would have to be:
fun interface StringGetter {
operator fun invoke(context: StringResourceContext): String
@Composable
@ReadOnlyComposable
operator fun invoke() = invoke(LocalKoinScope.current.getKoin().get())
or just remove @ReadOnlyComposable and I’m not sure the performance impact of that:
fun interface StringGetter {
operator fun invoke(context: StringResourceContext): String
@Composable
operator fun invoke() = invoke(koinInject())Mark
12/16/2024, 6:48 AMStringGetter.invoke() results in this runtime error (and I can’t see any pattern for why this might be happening):
java.lang.AbstractMethodError: abstract method "java.lang.String StringGetter.invoke(androidx.compose.runtime.Composer, int)"
at FooBarDialogKt.FooBarDialog(FooBarDialog.kt:49)
at FooBarDialogKt.FooBarDialog(FooBarDialog.kt:23)
at Foo.FooDialog(Foo.kt:93)
at Foo.FooDialog$lambda$3(Unknown Source:6)
at Foo.$r8$lambda$e3QgwvEpizXt98xiUXZPA6WHqz4(Unknown Source:0)
at Foo$$ExternalSyntheticLambda0.invoke(D8$$SyntheticClass:0)
at androidx.compose.runtime.RecomposeScopeImpl.compose(RecomposeScopeImpl.kt:192)