I am facing an issue in 1 of my screens, app crash...
# decompose
v
I am facing an issue in 1 of my screens, app crashes when its minimized, i.e. goes to background
Copy code
kotlinx.serialization.SerializationException: Serializer for subclass 'class com.medial.app.ui.screens.screens.home.tabs.news.NewsTabComponent$navigateToFilters$1' is not found in the polymorphic scope of 'Function1'.
                                                                                                    Check if class with serial name 'class com.medial.app.ui.screens.screens.home.tabs.news.NewsTabComponent$navigateToFilters$1' exists and serializer is registered in a corresponding SerializersModule.
                                                                                                    To be registered automatically, class 'class com.medial.app.ui.screens.screens.home.tabs.news.NewsTabComponent$navigateToFilters$1' has to be '@Serializable', and the base class 'Function1' has to be sealed and '@Serializable'.
This is the error I’m facing
This is my Screen Config and Component
Copy code
@Serializable
data class FilterScreen(
    val filters: Pair<List<String>, List<String>>,
    val onFilterSelect: (Pair<List<String>, List<String>>) -> Unit
) : ScreenConfig("Filters")

class FilterComponent(
    componentContext: ComponentContext,
    filters: Pair<List<String>, List<String>>,
    private val onFilterSelected: (Pair<List<String>, List<String>>) -> Unit,
    private val onNavEvent: (AppNavEvents) -> Unit
)
And this is the function mentioned in the error
Copy code
fun navigateToFilters(){
        val filters = sourceFilters.value.toList() to categoryFilters.value.toList()
        onNavEvent(NewsTabNavEvents.NavigateToFilters(filters, ::onFiltersSelected))
    }
a
Can you please show
NewsTabNavEvents.NavigateToFilters
class?
v
Copy code
data class NavigateToFilters(
        val filters: Pair<List<String>, List<String>>,
        val onSelected: (Pair<List<String>, List<String>>) -> Unit
    ) : NewsTabNavEvents
a
The issue is because
FilterScreen
can't be serialized.
Pair
is not serializable, and you also can't serialize functions.
I might be wrong about Pair though, it could be handled implicitly by
kotlinx-serialization
.
Yeah, Pair is fine as long as all its sub-types are also serializable.
v
I can split it into two different params no issue there I cant pass lambda functions ?
a
You can't serialize functions (aka lambdas).
Usually, you can pass lambdas to components at the place when you call constructors.
v
Any way to navigate to screen which can return result?
a
Sure, you can just pass a callback. And call the callback from the child component once the result is available.
v
Understood, its the interface approach Thanks for helping
👍 1
a
v
Thanks, Seems I missed this part in the doc
👍 1