UICollectionViewCell+convertFrameToScreenCoordinates.swift 861 Bytes
//
//  UIView+convertFrameToScreenCoordinates.swift
//  browser
//
//  Created by Artem Talko on 30.10.2023.
//

import UIKit

extension UICollectionViewCell {
    func convertFrameToScreenCoordinates() -> CGRect? {
        guard let rootView = UIApplication.shared.keyWindow?.rootViewController?.view else {
            return nil
        }
        
        let convertedOrigin = convert(bounds.origin, to: rootView)
        return CGRect(origin: convertedOrigin, size: bounds.size)
    }
    
    func convertRectToFullScreen(_ rect: CGRect) -> CGRect? {
        guard let window = UIApplication.shared.windows.first else {
            return nil
        }
        
        let rectInWindow = convert(rect, to: window)
        let fullScreenRect = window.convert(rectInWindow, to: UIScreen.main.coordinateSpace)
        
        return fullScreenRect
    }
}