mirror of
https://github.com/mastodon/mastodon-ios.git
synced 2025-02-03 10:47:35 +01:00
Merge pull request #624 from painhapp/issue607
#607 Use safe areas for image preview
This commit is contained in:
commit
5a5fce9744
@ -128,23 +128,14 @@ extension MediaPreviewImageView {
|
||||
// reset to normal
|
||||
zoomScale = minimumZoomScale
|
||||
|
||||
let imageViewSize = AVMakeRect(aspectRatio: image.size, insideRect: container.bounds).size
|
||||
let imageContentInset: UIEdgeInsets = {
|
||||
if imageViewSize.width == container.bounds.width {
|
||||
return UIEdgeInsets(top: 0.5 * (container.bounds.height - imageViewSize.height), left: 0, bottom: 0, right: 0)
|
||||
} else {
|
||||
return UIEdgeInsets(top: 0, left: 0.5 * (container.bounds.width - imageViewSize.width), bottom: 0, right: 0)
|
||||
}
|
||||
}()
|
||||
let imageViewSize = AVMakeRect(aspectRatio: image.size, insideRect: container.bounds.inset(by: container.safeAreaInsets)).size
|
||||
imageView.frame = CGRect(origin: .zero, size: imageViewSize)
|
||||
if imageView.image == nil {
|
||||
imageView.image = image
|
||||
}
|
||||
contentSize = imageViewSize
|
||||
contentInset = imageContentInset
|
||||
|
||||
centerScrollViewContents()
|
||||
contentOffset = CGPoint(x: -contentInset.left, y: -contentInset.top)
|
||||
|
||||
if #available(iOS 16.0, *) {
|
||||
Task.detached(priority: .userInitiated) {
|
||||
@ -224,10 +215,7 @@ extension MediaPreviewImageView {
|
||||
frame.size = realImageSize
|
||||
imageView.frame = frame
|
||||
|
||||
let screenSize = self.frame.size
|
||||
let offsetX = screenSize.width > realImageSize.width ? (screenSize.width - realImageSize.width) / 2 : 0
|
||||
let offsetY = screenSize.height > realImageSize.height ? (screenSize.height - realImageSize.height) / 2 : 0
|
||||
contentInset = UIEdgeInsets(top: offsetY, left: offsetX, bottom: offsetY, right: offsetX)
|
||||
contentInset = self.safeAreaInsets
|
||||
|
||||
// The scroll view has zoomed, so you need to re-center the contents
|
||||
let scrollViewSize = scrollViewVisibleSize
|
||||
|
@ -65,7 +65,7 @@ extension MediaHostToMediaPreviewViewControllerAnimatedTransitioning {
|
||||
let initialFrame = transitionItem.initialFrame ?? toViewEndFrame
|
||||
let transitionTargetFrame: CGRect = {
|
||||
let aspectRatio = transitionItem.aspectRatio ?? CGSize(width: initialFrame.width, height: initialFrame.height)
|
||||
return AVMakeRect(aspectRatio: aspectRatio, insideRect: toView.bounds)
|
||||
return AVMakeRect(aspectRatio: aspectRatio, insideRect: toView.bounds.inset(by: toView.safeAreaInsets))
|
||||
}()
|
||||
let transitionImageView: UIImageView = {
|
||||
let imageView = UIImageView(frame: transitionContext.containerView.convert(initialFrame, from: nil))
|
||||
|
Loading…
x
Reference in New Issue
Block a user