Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How should I use ComposeView to setLayout in Balloon? #10

Open
wosika opened this issue Nov 10, 2021 · 2 comments
Open

How should I use ComposeView to setLayout in Balloon? #10

wosika opened this issue Nov 10, 2021 · 2 comments

Comments

@wosika
Copy link

wosika commented Nov 10, 2021

  • Library Version com.github.skydoves:orchestra-balloon:1.1.1

  • Affected Device(s) Android 10

Describe the Bug:

I try to write like this

BalloonAnchor(
            reference = row,
            balloon = Balloon.Builder(LocalContext.current).apply {
                setLayout(ComposeView(LocalContext.current).apply {
                    setContent {
                        // In Compose world
                        MaterialTheme {
                            Text("Hello Compose!")
                        }
                    }
                })
            }.build(),
            onAnchorClick = { balloon, anchor ->
                balloon.showAsDropDown(anchor)
            }
        )

it crashed

  java.lang.IllegalStateException: Cannot locate windowRecomposer; View androidx.compose.ui.platform.ComposeView{8b981b1 V.E...... ......I. 0,0-0,0} is not attached to a window
        at androidx.compose.ui.platform.WindowRecomposer_androidKt.getWindowRecomposer(WindowRecomposer.android.kt:225)
        at androidx.compose.ui.platform.AbstractComposeView.resolveParentCompositionContext(ComposeView.android.kt:244)
        at androidx.compose.ui.platform.AbstractComposeView.ensureCompositionCreated(ComposeView.android.kt:251)
        at androidx.compose.ui.platform.AbstractComposeView.onMeasure(ComposeView.android.kt:288)
        at android.view.View.measure(View.java:25477)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6981)
        at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
        at android.view.View.measure(View.java:25477)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6981)
        at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
        at android.view.View.measure(View.java:25477)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6981)
        at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
        at android.view.View.measure(View.java:25477)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6981)
        at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
        at android.view.View.measure(View.java:25477)
        at com.skydoves.balloon.Balloon$showAsDropDown$$inlined$show$1.run(Balloon.kt:747)
        at android.os.Handler.handleCallback(Handler.java:883)
        at android.os.Handler.dispatchMessage(Handler.java:100)
        at android.os.Looper.loop(Looper.java:217)
        at android.app.ActivityThread.main(ActivityThread.java:8002)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:502)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:955)
@hoboris
Copy link

hoboris commented Dec 22, 2022

@wosika Have you found a way to use a custom layout with Compose since ?

@wosika
Copy link
Author

wosika commented Dec 22, 2022

You can try the solution I've used elsewhere @hoboris

    val composeView = ComposeView(context).apply {
			setContent { }

   val frameLayout = FrameLayout(context).apply {
                         //core
			id = android.R.id.content
			ViewTreeLifecycleOwner.set(this, lifecycleOwner)
			setViewTreeSavedStateRegistryOwner(saveOwner)
		

			layoutParams = FrameLayout.LayoutParams(
				ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.WRAP_CONTENT
			)
			addView(composeView)
		}
		contentView = frameLayout
}



val lifecycleOwner = LocalLifecycleOwner.current
val stateRegistryOwner = LocalSavedStateRegistryOwner.current

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants