Skip to content

Commit

Permalink
Fix horizontal distribution in RTL layout
Browse files Browse the repository at this point in the history
  • Loading branch information
NickEntin committed May 25, 2023
1 parent 07c18e7 commit 2de2b82
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 12 additions & 8 deletions Paralayout/UIView+Distribution.swift
Original file line number Diff line number Diff line change
Expand Up @@ -254,17 +254,21 @@ extension UIView {
let receiverLayoutDirection = effectiveUserInterfaceLayoutDirection

// Okay, ready to go!
var viewOrigin = axis.leadingEdge(of: layoutBounds, layoutDirection: receiverLayoutDirection)
var leadingEdgePosition = axis.leadingEdge(of: layoutBounds, layoutDirection: receiverLayoutDirection)
for item in items {
switch item {
case .view(let subview, let insets):
var frame = subview.untransformedFrame

switch axis {
case .horizontal:
frame.origin.x = (viewOrigin - insets.left).roundedToPixel(in: self)
case .vertical:
frame.origin.y = (viewOrigin - insets.top).roundedToPixel(in: self)
switch (axis, receiverLayoutDirection) {
case (.horizontal, .leftToRight):
frame.origin.x = (leadingEdgePosition - insets.left).roundedToPixel(in: self)
case (.horizontal, .rightToLeft):
frame.origin.x = (leadingEdgePosition + insets.right - frame.width).roundedToPixel(in: self)
case (.vertical, _):
frame.origin.y = (leadingEdgePosition - insets.top).roundedToPixel(in: self)
@unknown default:
fatalError("Unknown user interface layout direction")
}

applyOrthogonalAlignment(&frame, layoutBounds)
Expand All @@ -287,9 +291,9 @@ extension UIView {

switch (axis, receiverLayoutDirection) {
case (.horizontal, .leftToRight), (.vertical, _):
viewOrigin += distanceToMoveOrigin
leadingEdgePosition += distanceToMoveOrigin
case (.horizontal, .rightToLeft):
viewOrigin -= distanceToMoveOrigin
leadingEdgePosition -= distanceToMoveOrigin
@unknown default:
fatalError("Unknown user interface layout direction")
}
Expand Down

0 comments on commit 2de2b82

Please sign in to comment.