Skip to content

Commit a1f0be7

Browse files
authored
Merge pull request #110 from square/entin/scale-from-traits
Get scale factor for view from trait collection instead of screen
2 parents 3fce4c7 + 1f443b9 commit a1f0be7

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

Paralayout/PixelRounding.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,17 @@ extension UIScreen: ScaleFactorProviding {
3434
extension UIView: ScaleFactorProviding {
3535

3636
public var pixelsPerPoint: CGFloat {
37+
let scaleFromTraits = traitCollection.displayScale
38+
39+
// The trait collection is the authority for display scale, but sometimes the trait collection does not have a
40+
// value for the scale, in which case it will return 0, breaking all the things.
41+
if scaleFromTraits > 0 {
42+
return scaleFromTraits
43+
}
44+
45+
#if os(iOS)
3746
return (window?.screen ?? UIScreen.main).pixelsPerPoint
47+
#endif
3848
}
3949

4050
}

0 commit comments

Comments
 (0)