Change license to AGPL
This commit:
- Updates the `LICENSE` file
- Start every file with something like:
// Copyright YEAR_FIRST_PUBLISHED Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
---
First, I removed existing license headers with this Ruby 3.1.2 script:
require 'set'
EXTENSIONS_TO_CHECK = Set['.h', '.hpp', '.cpp', '.m', '.mm', '.pch', '.swift']
same = 0
different = 0
all_files = `git ls-files`.lines.map { |line| line.strip }
all_files.each do |relative_path|
if relative_path == 'Pods'
next
end
unless EXTENSIONS_TO_CHECK.include? File.extname(relative_path)
next
end
path = File.expand_path(relative_path)
contents = File.read(path)
new_contents = contents.sub(/\/\/\n\/\/ Copyright .*\n\/\/\n\n/, '')
if contents == new_contents
same += 1
else
different += 1
end
File.write(path, new_contents)
end
puts "updated #{different} file(s), left #{same} untouched"
I'm sure this script could be improved, but it worked well enough.
Then, I created `Scripts/lint/lint-license-headers` and ran it to auto-
fix a lot of files. This changed the mode of some files, but I think
that's actually desirable. For example,
`SignalServiceKit/src/Util/AppContext.m` previously had a mode of
`0755/-rwxr-xr-x`, and it's now `0644/-rw-r--r--`.
Then I fixed some stragglers and updated the precommit script.
See [a similar change in the Desktop app][0].
[0]: 8bfaf598af
163 lines
3.9 KiB
Swift
163 lines
3.9 KiB
Swift
//
|
|
// Copyright 2018 Signal Messenger, LLC
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
//
|
|
|
|
import Foundation
|
|
|
|
@objc
|
|
open class OWSLayerView: UIView {
|
|
@objc
|
|
public var shouldAnimate = true
|
|
|
|
@objc
|
|
public var layoutCallback: (UIView) -> Void
|
|
|
|
@objc
|
|
public init() {
|
|
self.layoutCallback = { (_) in
|
|
}
|
|
super.init(frame: .zero)
|
|
}
|
|
|
|
@objc
|
|
public init(frame: CGRect, layoutCallback: @escaping (UIView) -> Void) {
|
|
self.layoutCallback = layoutCallback
|
|
super.init(frame: frame)
|
|
}
|
|
|
|
public required init?(coder aDecoder: NSCoder) {
|
|
self.layoutCallback = { _ in
|
|
}
|
|
super.init(coder: aDecoder)
|
|
}
|
|
|
|
@objc
|
|
public static func circleView() -> OWSLayerView {
|
|
circleView(size: nil)
|
|
}
|
|
|
|
public static func circleView(size: CGFloat? = nil) -> OWSLayerView {
|
|
let result = OWSLayerView(frame: .zero) { view in
|
|
view.layer.cornerRadius = min(view.width, view.height) * 0.5
|
|
}
|
|
if let size = size {
|
|
result.autoSetDimensions(to: CGSize.square(size))
|
|
}
|
|
return result
|
|
}
|
|
|
|
@objc
|
|
public static func pillView() -> OWSLayerView {
|
|
pillView(height: nil)
|
|
}
|
|
|
|
public static func pillView(height: CGFloat? = nil) -> OWSLayerView {
|
|
let result = OWSLayerView(frame: .zero) { view in
|
|
view.layer.cornerRadius = min(view.width, view.height) * 0.5
|
|
}
|
|
if let height = height {
|
|
result.autoSetDimension(.height, toSize: height)
|
|
}
|
|
return result
|
|
}
|
|
|
|
public override var bounds: CGRect {
|
|
didSet {
|
|
if oldValue != bounds {
|
|
layoutSubviews()
|
|
}
|
|
}
|
|
}
|
|
|
|
public override var frame: CGRect {
|
|
didSet {
|
|
if oldValue != frame {
|
|
layoutSubviews()
|
|
}
|
|
}
|
|
}
|
|
|
|
public override var center: CGPoint {
|
|
didSet {
|
|
if oldValue != center {
|
|
layoutSubviews()
|
|
}
|
|
}
|
|
}
|
|
|
|
public override func layoutSubviews() {
|
|
super.layoutSubviews()
|
|
|
|
layoutCallback(self)
|
|
}
|
|
|
|
public func updateContent() {
|
|
if shouldAnimate {
|
|
layoutSubviews()
|
|
} else {
|
|
CATransaction.begin()
|
|
CATransaction.setDisableActions(true)
|
|
layoutSubviews()
|
|
CATransaction.commit()
|
|
}
|
|
}
|
|
|
|
// MARK: - Tap
|
|
|
|
public typealias TapBlock = () -> Void
|
|
private var tapBlock: TapBlock?
|
|
|
|
public func addTapGesture(_ tapBlock: @escaping TapBlock) {
|
|
self.tapBlock = tapBlock
|
|
isUserInteractionEnabled = true
|
|
addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(didTap)))
|
|
}
|
|
|
|
@objc
|
|
private func didTap() {
|
|
guard let tapBlock = tapBlock else {
|
|
owsFailDebug("Missing tapBlock.")
|
|
return
|
|
}
|
|
tapBlock()
|
|
}
|
|
|
|
// MARK: - Long Press
|
|
|
|
public typealias LongPressBlock = () -> Void
|
|
private var longPressBlock: LongPressBlock?
|
|
|
|
public func addLongPressGesture(_ longPressBlock: @escaping LongPressBlock) {
|
|
self.longPressBlock = longPressBlock
|
|
isUserInteractionEnabled = true
|
|
addGestureRecognizer(UILongPressGestureRecognizer(target: self, action: #selector(didLongPress)))
|
|
}
|
|
|
|
@objc
|
|
private func didLongPress() {
|
|
guard let longPressBlock = longPressBlock else {
|
|
owsFailDebug("Missing longPressBlock.")
|
|
return
|
|
}
|
|
longPressBlock()
|
|
}
|
|
|
|
// MARK: -
|
|
|
|
public func reset() {
|
|
removeAllSubviews()
|
|
|
|
self.layoutCallback = { _ in }
|
|
|
|
self.tapBlock = nil
|
|
self.longPressBlock = nil
|
|
|
|
if let gestureRecognizers = self.gestureRecognizers {
|
|
for gestureRecognizer in gestureRecognizers {
|
|
removeGestureRecognizer(gestureRecognizer)
|
|
}
|
|
}
|
|
}
|
|
}
|