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

SceneView with compose #561

Closed
melkonyan-n opened this issue Sep 26, 2024 · 2 comments
Closed

SceneView with compose #561

melkonyan-n opened this issue Sep 26, 2024 · 2 comments
Labels

Comments

@melkonyan-n
Copy link

Hi! Thank you for library.
I`m now crearting an ar app with compose and need to add node with custom compose view.

I tried with ViewNode2:

private fun **createViewNode**(context: Context, engine: Engine): ViewNode2 {
    val composeView = ComposeView(context).apply { setContent { RenderableLayout() }}
    return ViewNode2(
        engine = engine,
        windowManager = ViewNode2.WindowManager(context),
        materialLoader = MaterialLoader(engine, context),
        view = composeView
    )
}

my composable:

@Composable
fun RenderableLayout(text: String) {
    MaterialTheme {
        Card(
            modifier = Modifier.size(100.dp),
            shape = MaterialTheme.shapes.medium,
            colors = CardColors(
                containerColor = Color.White,
                contentColor = Color.White,
                disabledContainerColor = Color.Yellow,
                disabledContentColor = Color.Green
            )
        ) {
            Text(
                modifier = Modifier
                    .padding(2.dp)
                    .align(Alignment.CenterHorizontally),
                text = text,
                style = MaterialTheme.typography.bodyLarge.copy(color = Color.Black),
            )
        }
    }
}

used:

...
onGestureListener = rememberOnGestureListener(onSingleTapConfirmed = { motionEvent, node ->
                if (node == null) {
                   frame?.hitTest(motionEvent)?.firstOrNull { hitResult ->
                        AnchorNode(
                            engine = engine,
                            anchor = hitResult.createAnchor()
                        ).also { anchorNode ->
                            childNodes += anchorNode
                            **createViewNode**(context, engine).apply { parent = anchorNode }
                        }
                        true
                   }
                } else {
                    node.parent = null
                }
            })

The best I could achieve:

  • user taps on the screen
  • view is placed.
    But the view is plain black (I suppose it is not rendered).
    Can you help me to understand, where is problem and how to fix it?
Copy link

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the Stale label Dec 26, 2024
Copy link

github-actions bot commented Jan 3, 2025

Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please feel free to create a new issue with up-to-date information.

@github-actions github-actions bot closed this as completed Jan 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant