Skip to content

sizeInches is innacurate when device is in landscape mode #94

Description

@dylanhand

First of all thanks for your work on this library :)

If I'm not mistaken, since sizeInches only looks at the screen's height, it can be wrong about the device's size in some situations.

For example, a 12.9" iPad Pro in landscape mode happens to have a "height" of 1024, which results in sizeInches returning 9.7.

As another example, a 9.7" iPad in landscape mode has a "height" of 768, which results in sizeInches returning nil.

Is this known or by design? Maybe there's a way of correctly getting device size in landscape mode?

For reference, here's the code computing sizeInches:

extension Screen {
    public var sizeInches: Double? {
        switch (height, scale) {
        case (480, _): return 3.5
        case (568, _): return 4.0
        case (667, 3.0), (736, _): return 5.5
        case (667, 1.0), (667, 2.0): return 4.7
        case (812, 3.0): return 5.8
        case (896, 2.0): return 6.1
        case (896, 3.0): return 6.5
        case (1024, _): return ipadSize1024()
        case (1080, _): return 10.2
        case (1112, _): return 10.5
        case (1133, _): return 8.3
        case (1180, _): return 10.9
        case (1194, _): return 11.0
        case (1366, _): return 12.9
        default: return nil
        }
    }

    func ipadSize1024() -> Double {
        let deviceModel = UIDevice().dc.deviceModel
        switch deviceModel {
        case .iPadMini, .iPadMini2, .iPadMini3, .iPadMini4, .iPadMini5: return 7.9
        case .iPadPro10_5Inch: return 10.5
        default: return 9.7
        }
    }
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions