fix: resize bug in retained mode

This commit is contained in:
2026-02-25 00:18:11 -05:00
parent 3c3f26b74a
commit 6ae04b5e82

View File

@@ -108,6 +108,8 @@ function LayoutEngine.new(props, deps)
childrenCount = 0, childrenCount = 0,
containerWidth = 0, containerWidth = 0,
containerHeight = 0, containerHeight = 0,
containerX = 0,
containerY = 0,
childrenHash = "", childrenHash = "",
} }
@@ -1180,6 +1182,10 @@ function LayoutEngine:recalculateUnits(newViewportWidth, newViewportHeight)
end end
-- Recalculate position if using viewport or percentage units -- Recalculate position if using viewport or percentage units
-- Skip position recalculation for flex children (non-explicitly-absolute children with a parent)
-- Their x/y is entirely controlled by the parent's layoutChildren() call
local isFlexChild = self.element.parent and not self.element._explicitlyAbsolute
if not isFlexChild then
if self.element.units.x.unit ~= "px" then if self.element.units.x.unit ~= "px" then
local parentWidth = self.element.parent and self.element.parent.width or newViewportWidth local parentWidth = self.element.parent and self.element.parent.width or newViewportWidth
local baseX = self.element.parent and self.element.parent.x or 0 local baseX = self.element.parent and self.element.parent.x or 0
@@ -1227,6 +1233,7 @@ function LayoutEngine:recalculateUnits(newViewportWidth, newViewportHeight)
self.element.y = self.element.units.y.value * scaleY self.element.y = self.element.units.y.value * scaleY
end end
end end
end
-- Recalculate textSize if auto-scaling is enabled or using viewport/element-relative units -- Recalculate textSize if auto-scaling is enabled or using viewport/element-relative units
if self.element.autoScaleText and self.element.units.textSize.value then if self.element.autoScaleText and self.element.units.textSize.value then
@@ -1504,6 +1511,8 @@ function LayoutEngine:_canSkipLayout()
local childrenCount = #self.element.children local childrenCount = #self.element.children
local containerWidth = self.element.width local containerWidth = self.element.width
local containerHeight = self.element.height local containerHeight = self.element.height
local containerX = self.element.x
local containerY = self.element.y
-- Generate simple hash of children dimensions -- Generate simple hash of children dimensions
local childrenHash = "" local childrenHash = ""
@@ -1520,6 +1529,8 @@ function LayoutEngine:_canSkipLayout()
cache.childrenCount == childrenCount cache.childrenCount == childrenCount
and cache.containerWidth == containerWidth and cache.containerWidth == containerWidth
and cache.containerHeight == containerHeight and cache.containerHeight == containerHeight
and cache.containerX == containerX
and cache.containerY == containerY
and cache.childrenHash == childrenHash and cache.childrenHash == childrenHash
then then
return true -- Layout hasn't changed, can skip return true -- Layout hasn't changed, can skip
@@ -1529,6 +1540,8 @@ function LayoutEngine:_canSkipLayout()
cache.childrenCount = childrenCount cache.childrenCount = childrenCount
cache.containerWidth = containerWidth cache.containerWidth = containerWidth
cache.containerHeight = containerHeight cache.containerHeight = containerHeight
cache.containerX = containerX
cache.containerY = containerY
cache.childrenHash = childrenHash cache.childrenHash = childrenHash
return false -- Layout has changed, must recalculate return false -- Layout has changed, must recalculate