session-ios/Signal/src/UserInterface/OWSLayerView.swift
2018-06-29 17:02:39 -04:00

50 lines
1,009 B
Swift

//
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
import Foundation
@objc
class OWSLayerView: UIView {
let layoutCallback: ((UIView) -> Void)
@objc
public required init(frame: CGRect, layoutCallback : @escaping (UIView) -> Void) {
self.layoutCallback = layoutCallback
super.init(frame: frame)
}
required init?(coder aDecoder: NSCoder) {
self.layoutCallback = { _ in
}
super.init(coder: aDecoder)
}
override var bounds: CGRect {
didSet {
updateLayer()
}
}
override var frame: CGRect {
didSet {
updateLayer()
}
}
override var center: CGPoint {
didSet {
updateLayer()
}
}
private func updateLayer() {
// Prevent the shape layer from animating changes.
CATransaction.begin()
CATransaction.setDisableActions(true)
layoutCallback(self)
CATransaction.commit()
}
}