fluentui-apple icon indicating copy to clipboard operation
fluentui-apple copied to clipboard

UIScreen.main issue

Open li-bei opened this issue 5 years ago • 1 comments

I saw a lot of UIScreen.main in the codebase. As a UI framework, I don't think this is a good implementation.

iOS devices can use external screens, it means your view will not alway in the main screen, we should get screen form window:

extension UIView {
   var screen: UIScreen { window?.screen ?? .main }
}

And screen should be accessed from methods like layoutSubviews, sizeThatFits. For example, Separator should access screen in sizeThatFits:

class Separator: UIView {
  ...

  override func sizeThatFits(_ size: CGSize) -> CGSize {
    switch orientation {
      case .horizontal:
        return CGSize(width: size.width, height: screen.devicePixel)
      case .vertical:
        return CGSize(width: screen.devicePixel, height: size.height)
    }
  }

Environment Information

  • Platform:
    • [x] iOS
    • [ ] macOS

Priorities and help requested:

Are you willing to submit a PR to fix? Neutral

Requested priority: Normal

li-bei avatar May 27 '20 13:05 li-bei

@harrieshin can you take a look at this and help triage the issue?

markavitale avatar May 27 '20 16:05 markavitale