From aa0826dae9bef78afc57d91823feeaaa3a187430 Mon Sep 17 00:00:00 2001 From: Felix Mau Date: Sat, 13 Jun 2020 15:35:05 +0200 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20::=20Prefer=20`superview.b?= =?UTF-8?q?ounds.size.width`=20over=20`UIScreen.main.bounds.width`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- NotchGradientLoadingBarController.swift | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/NotchGradientLoadingBarController.swift b/NotchGradientLoadingBarController.swift index 19f2fbb..13d66f1 100644 --- a/NotchGradientLoadingBarController.swift +++ b/NotchGradientLoadingBarController.swift @@ -52,16 +52,17 @@ open class NotchGradientLoadingBarController: GradientLoadingBarController { gradientActivityIndicatorView.trailingAnchor.constraint(equalTo: superview.trailingAnchor) ]) - applyNotchMask() + // As we currently only support portrait mode (and no device rotation), + // we can safely use `bounds.size.width` here. + let screenWidth = superview.bounds.size.width + applyNotchMask(for: screenWidth) } // MARK: - Private methods - private func applyNotchMask() { - // We draw the mask of the notch in the center of the screen. - // As we currently only support portrait mode, we can safely use `UIScreen.main.bounds` here. - let screenWidth = UIScreen.main.bounds.size.width - let leftNotchPoint = (screenWidth - Config.notchWidth) / 2 + 1 + private func applyNotchMask(for screenWidth: CGFloat) { + // We always center the notch in the middle of the screen. + let leftNotchPoint = (screenWidth - Config.notchWidth) / 2 + 0.5 let rightNotchPoint = (screenWidth + Config.notchWidth) / 2 let smallCircleDiameter: CGFloat = 2 * Config.smallCircleRadius