fix: resize bug in retained mode
This commit is contained in:
@@ -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,51 +1182,56 @@ function LayoutEngine:recalculateUnits(newViewportWidth, newViewportHeight)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Recalculate position if using viewport or percentage units
|
-- Recalculate position if using viewport or percentage units
|
||||||
if self.element.units.x.unit ~= "px" then
|
-- Skip position recalculation for flex children (non-explicitly-absolute children with a parent)
|
||||||
local parentWidth = self.element.parent and self.element.parent.width or newViewportWidth
|
-- Their x/y is entirely controlled by the parent's layoutChildren() call
|
||||||
local baseX = self.element.parent and self.element.parent.x or 0
|
local isFlexChild = self.element.parent and not self.element._explicitlyAbsolute
|
||||||
local offsetX = Units.resolve(
|
if not isFlexChild then
|
||||||
self.element.units.x.value,
|
if self.element.units.x.unit ~= "px" then
|
||||||
self.element.units.x.unit,
|
local parentWidth = self.element.parent and self.element.parent.width or newViewportWidth
|
||||||
newViewportWidth,
|
local baseX = self.element.parent and self.element.parent.x or 0
|
||||||
newViewportHeight,
|
local offsetX = Units.resolve(
|
||||||
parentWidth
|
self.element.units.x.value,
|
||||||
)
|
self.element.units.x.unit,
|
||||||
self.element.x = baseX + offsetX
|
newViewportWidth,
|
||||||
else
|
newViewportHeight,
|
||||||
-- For pixel units, update position relative to parent's new position (with base scaling)
|
parentWidth
|
||||||
if self.element.parent then
|
)
|
||||||
local baseX = self.element.parent.x
|
self.element.x = baseX + offsetX
|
||||||
local scaledOffset = self._Context.baseScale and (self.element.units.x.value * scaleX)
|
else
|
||||||
or self.element.units.x.value
|
-- For pixel units, update position relative to parent's new position (with base scaling)
|
||||||
self.element.x = baseX + scaledOffset
|
if self.element.parent then
|
||||||
elseif self._Context.baseScale then
|
local baseX = self.element.parent.x
|
||||||
-- Top-level element with pixel position - apply base scaling
|
local scaledOffset = self._Context.baseScale and (self.element.units.x.value * scaleX)
|
||||||
self.element.x = self.element.units.x.value * scaleX
|
or self.element.units.x.value
|
||||||
|
self.element.x = baseX + scaledOffset
|
||||||
|
elseif self._Context.baseScale then
|
||||||
|
-- Top-level element with pixel position - apply base scaling
|
||||||
|
self.element.x = self.element.units.x.value * scaleX
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
if self.element.units.y.unit ~= "px" then
|
if self.element.units.y.unit ~= "px" then
|
||||||
local parentHeight = self.element.parent and self.element.parent.height or newViewportHeight
|
local parentHeight = self.element.parent and self.element.parent.height or newViewportHeight
|
||||||
local baseY = self.element.parent and self.element.parent.y or 0
|
local baseY = self.element.parent and self.element.parent.y or 0
|
||||||
local offsetY = Units.resolve(
|
local offsetY = Units.resolve(
|
||||||
self.element.units.y.value,
|
self.element.units.y.value,
|
||||||
self.element.units.y.unit,
|
self.element.units.y.unit,
|
||||||
newViewportWidth,
|
newViewportWidth,
|
||||||
newViewportHeight,
|
newViewportHeight,
|
||||||
parentHeight
|
parentHeight
|
||||||
)
|
)
|
||||||
self.element.y = baseY + offsetY
|
self.element.y = baseY + offsetY
|
||||||
else
|
else
|
||||||
-- For pixel units, update position relative to parent's new position (with base scaling)
|
-- For pixel units, update position relative to parent's new position (with base scaling)
|
||||||
if self.element.parent then
|
if self.element.parent then
|
||||||
local baseY = self.element.parent.y
|
local baseY = self.element.parent.y
|
||||||
local scaledOffset = self._Context.baseScale and (self.element.units.y.value * scaleY)
|
local scaledOffset = self._Context.baseScale and (self.element.units.y.value * scaleY)
|
||||||
or self.element.units.y.value
|
or self.element.units.y.value
|
||||||
self.element.y = baseY + scaledOffset
|
self.element.y = baseY + scaledOffset
|
||||||
elseif self._Context.baseScale then
|
elseif self._Context.baseScale then
|
||||||
-- Top-level element with pixel position - apply base scaling
|
-- Top-level element with pixel position - apply base scaling
|
||||||
self.element.y = self.element.units.y.value * scaleY
|
self.element.y = self.element.units.y.value * scaleY
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user