Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sizeInches is innacurate when device is in landscape mode #94

Open
dylanhand opened this issue Oct 3, 2023 · 0 comments
Open

sizeInches is innacurate when device is in landscape mode #94

dylanhand opened this issue Oct 3, 2023 · 0 comments

Comments

@dylanhand
Copy link

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
        }
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant