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

Use UIApplication and view.windowScene.screen instead of UIScreen.main on iOS 13.0 and later (#804) #805

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion Source/Configuration/YPImagePickerConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,15 @@ public struct YPImagePickerConfiguration {
public static var widthOniPad: CGFloat = -1

public static var screenWidth: CGFloat {
var screenWidth: CGFloat = UIScreen.main.bounds.width
var screenWidth: CGFloat = 0

if #available(iOS 13.0, *) {
let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene
screenWidth = windowScene?.screen.bounds.width ?? 1.0
} else {
screenWidth = UIScreen.main.bounds.width
}

if UIDevice.current.userInterfaceIdiom == .pad && YPImagePickerConfiguration.widthOniPad > 0 {
screenWidth = YPImagePickerConfiguration.widthOniPad
}
Expand Down
10 changes: 9 additions & 1 deletion Source/Filters/Photo/YPFiltersView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,15 @@ class YPFiltersView: UIView {
)
)

let isIphone4 = UIScreen.main.bounds.height == 480
var height: CGFloat = 0

if #available(iOS 13.0, *) {
height = window?.windowScene?.screen.bounds.height ?? .zero
} else {
height = UIScreen.main.bounds.height
}

let isIphone4 = height == 480
let sideMargin: CGFloat = isIphone4 ? 20 : 0

|-sideMargin-imageView.top(0)-sideMargin-|
Expand Down
10 changes: 9 additions & 1 deletion Source/Filters/Photo/YPPhotoFiltersVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,15 @@ open class YPPhotoFiltersVC: UIViewController, IsMediaFilterVC, UIGestureRecogni

fileprivate func thumbFromImage(_ img: UIImage) -> CIImage {
let k = img.size.width / img.size.height
let scale = UIScreen.main.scale

var scale: CGFloat = 0

if #available(iOS 13.0, *) {
scale = window?.windowScene?.screen.scale ?? 1.0
} else {
scale = UIScreen.main.scale
}

let thumbnailHeight: CGFloat = 300 * scale
let thumbnailWidth = thumbnailHeight * k
let thumbnailSize = CGSize(width: thumbnailWidth, height: thumbnailHeight)
Expand Down
10 changes: 9 additions & 1 deletion Source/Pages/Gallery/Album/YPAlbumsManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,15 @@ class YPAlbumsManager {
if album.numberOfItems > 0 {
let r = PHAsset.fetchKeyAssets(in: assetCollection, options: nil)
if let first = r?.firstObject {
let deviceScale = UIScreen.main.scale
var deviceScale: CGFloat = 0

if #available(iOS 13.0, *) {
let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene
deviceScale = windowScene?.screen.scale ?? 1.0
} else {
deviceScale = UIScreen.main.scale
}

let targetSize = CGSize(width: 78*deviceScale, height: 78*deviceScale)
let options = PHImageRequestOptions()
options.isSynchronous = true
Expand Down
12 changes: 11 additions & 1 deletion Source/Pages/Gallery/LibraryMediaManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,17 @@ class LibraryMediaManager {

func updateCachedAssets(in collectionView: UICollectionView) {
let screenWidth = YPImagePickerConfiguration.screenWidth
let size = screenWidth / 4 * UIScreen.main.scale

var scale: CGFloat = 0

if #available(iOS 13.0, *) {
let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene
scale = windowScene?.screen.scale ?? 1.0
} else {
scale = UIScreen.main.scale
}

let size = screenWidth / 4 * scale
let cellSize = CGSize(width: size, height: size)

var preheatRect = collectionView.bounds
Expand Down
14 changes: 12 additions & 2 deletions Source/Pages/Gallery/YPLibraryView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,21 @@ internal final class YPLibraryView: UIView {
}

func cellSize() -> CGSize {
var screenWidth: CGFloat = UIScreen.main.bounds.width
var screenWidth: CGFloat = 0
var scale: CGFloat = 0

if #available(iOS 13.0, *) {
screenWidth = window?.windowScene?.screen.bounds.width ?? 1.0
scale = window?.windowScene?.screen.scale ?? 1.0
} else {
screenWidth = UIScreen.main.bounds.width
scale = UIScreen.main.scale
}

if UIDevice.current.userInterfaceIdiom == .pad && YPImagePickerConfiguration.widthOniPad > 0 {
screenWidth = YPImagePickerConfiguration.widthOniPad
}
let size = screenWidth / 4 * UIScreen.main.scale
let size = screenWidth / 4 * scale
return CGSize(width: size, height: size)
}

Expand Down
10 changes: 9 additions & 1 deletion Source/Pages/Photo/YPCameraView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,15 @@ internal class YPCameraView: UIView, UIGestureRecognizerDelegate {
}

// Layout
let isIphone4 = UIScreen.main.bounds.height == 480
var height: CGFloat = 0

if #available(iOS 13.0, *) {
height = window?.windowScene?.screen.bounds.height ?? .zero
} else {
height = UIScreen.main.bounds.height
}

let isIphone4 = height == 480
let sideMargin: CGFloat = isIphone4 ? 20 : 0
if YPConfig.onlySquareImagesFromCamera {
layout(
Expand Down