-
-
Notifications
You must be signed in to change notification settings - Fork 85
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Multiple retainedComponent (RootComponent) ComponentContext for android app will crash #807
Comments
Thanks for reporting! This looks like a bug. From the top of my head, For now, please use the following approach. class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val (root, dash) = retainedComponent {
RootComponent(it.childContext("root")) to DashBoardRootComponent(it.childContext("dash"))
}
setContent {
App(rootF, dashF)
}
}
} Also regarding the desktop version, please make sure you are following the docs. Usually, components should be created outside of Compose. |
Thank you so much sir,
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val (rootComponent, dashBoardRootComponent) = retainedComponent {
RootComponent(it.childContext("root")) to
DashBoardRootComponent(it.childContext("dash"))
}
setContent {
App(rootComponent, dashBoardRootComponent)
}
}
}It will work as I need it to.
As per your suggestion I updated my
desktop entry point code.
fun main() = application {
Window(
onCloseRequest = ::exitApplication,
title = "neon-music-kmp",
) {
val root = runOnUiThread {
RootComponent(
componentContext = DefaultComponentContext(LifecycleRegistry())
)
}
val dashBoardRoot = runOnUiThread {
DashBoardRootComponent(
componentContext = DefaultComponentContext(LifecycleRegistry())
)
}
App(root, dashBoardRoot)
}
}
Now it's working fine. Thanks again.
…On Fri, Nov 8, 2024 at 3:57 PM Arkadii Ivanov ***@***.***> wrote:
Thanks for reporting! This looks like a bug. From the top of my head,
retainedComponent was supposed to be the only one in an Activity.
However, there is the key argument there, which probably there for a
reason. I will try fixing it or provides updates here.
For now, please use the following approach.
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val (root, dash) = retainedComponent {
RootComponent(it.childContext("root")) to DashBoardRootComponent(it.childContext("dash"))
}
setContent {
App(rootF, dashF)
}
}
}
Also regarding the desktop version, please make sure you are following the
docs
<https://arkivanov.github.io/Decompose/component/overview/#jvmdesktop-with-compose>.
Usually, components should be created outside of Compose.
—
Reply to this email directly, view it on GitHub
<#807 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AHNIYGJ5TJBYFHJD7LYEBW3Z7SGX3AVCNFSM6AAAAABRMXEI6SVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDINRUGM2DOMBYHA>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
--
*- VISHAL BHIMPORWALA*
|
Here my RootComponent class
Here my DashBoardRootComponent class
My App Component
For Android MainActivity 1st Try
Logcat :
For Android MainActivity 2nd Try from chatGpt reference
Logcat :
I am facing this issue only for android
Do code for desktop also but it will working fine.
Here Desktop entry point
Can any one explain me where i need to give unique key for android retainedComponent ?
Tell me if i am wrong in anything.
The text was updated successfully, but these errors were encountered: