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

Scroll offset reset after view marked as hidden (tabs switch) #709

Open
charlescgs opened this issue Dec 19, 2024 · 0 comments · May be fixed by #710
Open

Scroll offset reset after view marked as hidden (tabs switch) #709

charlescgs opened this issue Dec 19, 2024 · 0 comments · May be fixed by #710

Comments

@charlescgs
Copy link
Contributor

charlescgs commented Dec 19, 2024

I was having an issue with scrolled view on tab, that on change always was going back to the top.

After some digging @jrmoulton has found the fix:

/// Computes the layout of the view's children, if any.
pub fn default_compute_layout(id: ViewId, cx: &mut ComputeLayoutCx) -> Option<Rect> {
    let mut layout_rect: Option<Rect> = None;
    for child in id.children() {
        if !child.style_has_hidden() { // <-- Add this
            let child_layout = cx.compute_view_layout(child);
            if let Some(child_layout) = child_layout {
                if let Some(rect) = layout_rect {
                    layout_rect = Some(rect.union(child_layout));
                } else {
                    layout_rect = Some(child_layout);
                }
            }
        }
    }
    layout_rect
}

The problem was: when the tab was marked as hidden (on tab change) it still has had it's layout computed. It was given a size of zero and when the scroll view saw that it's size has been updated it was changing the scroll offset.

The solution is: to not call compute layout on a hidden view.

@charlescgs charlescgs linked a pull request Dec 19, 2024 that will close this issue
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

Successfully merging a pull request may close this issue.

1 participant