//
//  LayoutLatch.swift
//  App
//
//  Created by James Magahern on 8/10/23.
//

import Foundation

class LayoutLatch {
    public weak var view: UIView?
    public private(set) var latched: Bool = false
    
    init(_ view: UIView) {
        self.view = view
    }
    
    public func activate() {
        latched = true
        
        DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(100)) { [weak self] in
            self?.deactivate()
        }
    }
    
    public func deactivate() {
        latched = false
        view?.setNeedsLayout()
    }
}
