Container scroll issue when inner component focus is gained

12 views
Skip to first unread message

carlo...@gmail.com

unread,
Jun 7, 2019, 4:54:27 AM6/7/19
to CodenameOne Discussions
Hi there,

I am developing a short chat application. My layout structure is a BoxLayout.y() for the form where I append each of the message containers, and then in the layeredpane of the form, via a BoxLayout(BoxLayout.Y_AXIS_BOTTOM_LAST), I include the input pane to enter the message text and the send message button. So far so good, and everything works smoothly. 

When we get to fully occupy the area of appended messages and overflow the available area of the form, the expected behaviour is to expand the container, and enable navigation via vertical scrolling. A behaviour requirement is aswell to scroll to the bottommost message when new messages are appended. So far so good. 

The point is that when we are at the bottom of the container in the scroll position, when the TextArea control of the inputpane gains focus, the scroll position of the form gets screwed and the form turns to the top position of the scrolling, hence displaying the first appended message instead of the last.

Since this seems to be a default behaviour can't figure out how to approach a solution. I have tried to apply the same logic as to when new messages are appended with no luck.


Does anyone have an idea how to solve it?

Regards and thanks for your time.

Carlos.


carlo...@gmail.com

unread,
Jun 7, 2019, 5:31:37 AM6/7/19
to CodenameOne Discussions
Hi,

I solved it by slightly digging in the method calls to see if there was a way to deviate how things were handled. Found that when a component gets called, the method scrollComponentToVisible() is called. So since my textarea is inside the form's layered pane, what I did was to override that method:

@Override
    public void scrollComponentToVisible(Component c) {
        if (!this.getLayeredPane().contains(c)){
            super.scrollComponentToVisible(c);
        }
    }

Now, when this method is called for a control in the form's layered pane, the form won't update its scroll position. And this works.

If there's a better way to solve it please advise.

Thanks in advance.

Carlos.

Shai Almog

unread,
Jun 7, 2019, 11:46:31 PM6/7/19
to CodenameOne Discussions
Hi,
is this behavior something you see in the simulator or device?
Scrolling is impacted while editing due to the virtual keyboard occupying space but it shouldn't send you to the top element. I'm not sure I understand the problem description.
Reply all
Reply to author
Forward
0 new messages