in AzureCommunicationUI/sdk/AzureCommunicationUICalling/Sources/Presentation/SwiftUI/Calling/Grid/Cell/ZoomableVideoRenderView.swift [125:166]
func scrollViewDidZoom(_ scrollView: UIScrollView) {
let initialMinZoomScale = InitialZoomScaleConstants.minScale
let boundedZoomScale = min(scrollView.zoomScale, scrollView.maximumZoomScale) * (1 / initialMinZoomScale)
if boundedZoomScale > 1 {
let aspectRatioVideoStream = self.streamSize != .zero ?
self.streamSize.width / self.streamSize.height : GeneralScreenConstants.defaultAspectRatio
let spectRatioScrollView = scrollView.bounds.width / scrollView.bounds.height
let scrollViewHasNarrowAspectRatio = spectRatioScrollView < aspectRatioVideoStream
var videoContentWidth = scrollView.bounds.width
var videoContentHeight = videoContentWidth / aspectRatioVideoStream
if !scrollViewHasNarrowAspectRatio {
videoContentHeight = scrollView.bounds.height
videoContentWidth = videoContentHeight * aspectRatioVideoStream
}
let ratioW = scrollView.frame.width / videoContentWidth
let ratioH = scrollView.frame.height / videoContentHeight
let ratio = ratioW < ratioH ? ratioW : ratioH
let newWidth = videoContentWidth * ratio
let newHeight = videoContentHeight * ratio
let left = 0.5 * (newWidth * boundedZoomScale > scrollView.frame.width ?
(newWidth - scrollView.frame.width)
: (scrollView.frame.width - scrollView.contentSize.width))
let top = 0.5 * (newHeight * boundedZoomScale > scrollView.frame.height ?
(!scrollViewHasNarrowAspectRatio ?
(newHeight - scrollView.frame.height) :
(scrollView.frame.height - scrollView.contentSize.height
+ (newHeight * boundedZoomScale - scrollView.frame.height)))
: (scrollView.frame.height - scrollView.contentSize.height))
scrollView.contentInset = UIEdgeInsets(top: top, left: left, bottom: top, right: left)
} else {
scrollView.contentInset = .zero
}
}