lapce/floem

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

charlescgs opened this issue · 0 comments

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.