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

Open
melkonyan-n opened this issue Sep 26, 2024 · 0 comments
Open

SceneView with compose #561

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

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?
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

1 participant