Giter Site home page Giter Site logo

Comments (4)

m-sasha avatar m-sasha commented on May 30, 2024

Can you provide a complete example of the problem? This works correctly for me:

fun main() = SwingUtilities.invokeLater {
    val frame = JFrame()
    frame.contentPane.add(ComposePanel().also {
        it.setContent {
            Column {
                Text("Hello World")
                Button(onClick = { println("Click") }) {
                    Text("Click me!")
                }
            }
        }
    })
    frame.size = Dimension(400, 500)
    frame.isVisible = true
}

The accessible is not exposed via ComposePanel, but via skiko's HardwareLayer:

internal open class HardwareLayer(
    externalAccessibleFactory: ((Component) -> Accessible)? = null
) : Canvas() {

    private val _externalAccessible = externalAccessibleFactory?.invoke(this)

    override fun getAccessibleContext(): AccessibleContext {
        val res = (_focusedAccessible ?: _externalAccessible)?.accessibleContext
        return res ?: super.getAccessibleContext()
    }

}

from compose-multiplatform.

rpaquay avatar rpaquay commented on May 30, 2024

I don't quite understand what HardwareLayer is about, but what I am trying to say is that I believe ComposePanel should behave the same way as a JPanel, i.e. it exposes the components it contains as Accessible through its implementation of getAccessbleContext. Here is the JPanel implementation:

    public AccessibleContext getAccessibleContext() {
        if (accessibleContext == null) {
            accessibleContext = new AccessibleJPanel();
        }
        return accessibleContext;
    }

    protected class AccessibleJPanel extends AccessibleJComponent {
        protected AccessibleJPanel() {}
        public AccessibleRole getAccessibleRole() {
            return AccessibleRole.PANEL;
        }

        // getAccessibleChildCount and getAccessibleChild are inherited from JComponent, and the
        // inherited implementation looks at the list of child component:
        int getAccessibleChildrenCount() { // Inherited from Container.java
            synchronized (getTreeLock()) {
                int count = 0;
                Component[] children = this.getComponents();
                for (int i = 0; i < children.length; i++) {
                    if (children[i] instanceof Accessible) {
                        count++;
                    }
                }
                return count;
            }
        }
    }

The reason it is important to link parent and children is that it is an expectation of the Java Access Bridge API (and screen readers using the API) that there is a top down Accessible tree that can be used to traverse all UI elements from the top level window (JFrame) to any element displayed in that frame. With the current implementation of ComposePanel, the Accessible tree stops at ComposePanel, and the container does not have the ability (afaik) to expose the sub-tree of Compose components it contains.

The use case we are looking is an IJ plugin (Android Studio) embedding a ComposePanel in a IJ platform ToolWindow. With the current implementation of ComposePanel, the Accessible tree is incomplete, i.e. the traversal "stops" at the ToolWindow container, and nothing is exposed via ComposePanel.

from compose-multiplatform.

m-sasha avatar m-sasha commented on May 30, 2024

Can you provide a small reproducer app for this?

from compose-multiplatform.

igordmn avatar igordmn commented on May 30, 2024

@m-sasha, this is a bug from IntelliJ/Android Studio integration. It probably uses System.setProperty("compose.layers.type", "COMPONENT"). Could you try it with it?

from compose-multiplatform.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.