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
176 lines
4.6 KiB
Swift
176 lines
4.6 KiB
Swift
//
|
|
// Copyright 2020 Signal Messenger, LLC
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
//
|
|
|
|
import Foundation
|
|
|
|
open class OWSStackView: UIStackView {
|
|
|
|
public struct Config {
|
|
public let axis: NSLayoutConstraint.Axis
|
|
public let alignment: UIStackView.Alignment
|
|
public let spacing: CGFloat
|
|
public let layoutMargins: UIEdgeInsets
|
|
|
|
public init(axis: NSLayoutConstraint.Axis,
|
|
alignment: UIStackView.Alignment,
|
|
spacing: CGFloat,
|
|
layoutMargins: UIEdgeInsets) {
|
|
self.axis = axis
|
|
self.alignment = alignment
|
|
self.spacing = spacing
|
|
self.layoutMargins = layoutMargins
|
|
}
|
|
|
|
public func withSpacing(_ spacing: CGFloat) -> Config {
|
|
Config(axis: self.axis,
|
|
alignment: self.alignment,
|
|
spacing: spacing,
|
|
layoutMargins: self.layoutMargins)
|
|
}
|
|
|
|
public var debugDescription: String {
|
|
let components: [String] = [
|
|
"axis: \(axis)",
|
|
"alignment: \(alignment)",
|
|
"spacing: \(spacing)",
|
|
"layoutMargins: \(layoutMargins)"
|
|
]
|
|
return "[" + components.joined(separator: ", ") + "]"
|
|
}
|
|
}
|
|
|
|
// MARK: -
|
|
|
|
public typealias LayoutBlock = (UIView) -> Void
|
|
|
|
public var layoutBlock: LayoutBlock?
|
|
|
|
@objc
|
|
public required init(name: String, arrangedSubviews: [UIView] = []) {
|
|
super.init(frame: .zero)
|
|
|
|
for subview in arrangedSubviews {
|
|
addArrangedSubview(subview)
|
|
}
|
|
|
|
#if TESTABLE_BUILD
|
|
self.accessibilityLabel = name
|
|
#endif
|
|
}
|
|
|
|
@available(*, unavailable, message: "use other constructor instead.")
|
|
@objc
|
|
public required init(coder aDecoder: NSCoder) {
|
|
fatalError("init(coder:) has not been implemented")
|
|
}
|
|
|
|
@objc
|
|
public override func layoutSubviews() {
|
|
AssertIsOnMainThread()
|
|
|
|
super.layoutSubviews()
|
|
|
|
layoutBlock?(self)
|
|
}
|
|
|
|
open func reset() {
|
|
alignment = .fill
|
|
axis = .vertical
|
|
spacing = 0
|
|
isLayoutMarginsRelativeArrangement = false
|
|
|
|
removeAllSubviews()
|
|
|
|
layoutBlock = nil
|
|
|
|
invalidateIntrinsicContentSize()
|
|
setNeedsLayout()
|
|
}
|
|
|
|
public func apply(config: Config) {
|
|
if self.axis != config.axis {
|
|
self.axis = config.axis
|
|
}
|
|
if self.alignment != config.alignment {
|
|
self.alignment = config.alignment
|
|
}
|
|
if self.spacing != config.spacing {
|
|
self.spacing = config.spacing
|
|
}
|
|
if self.layoutMargins != config.layoutMargins {
|
|
self.layoutMargins = config.layoutMargins
|
|
}
|
|
let isLayoutMarginsRelativeArrangement = layoutMargins != .zero
|
|
if self.isLayoutMarginsRelativeArrangement != isLayoutMarginsRelativeArrangement {
|
|
self.isLayoutMarginsRelativeArrangement = isLayoutMarginsRelativeArrangement
|
|
}
|
|
}
|
|
|
|
public var asConfig: Config {
|
|
Config(axis: self.axis,
|
|
alignment: self.alignment,
|
|
spacing: self.spacing,
|
|
layoutMargins: self.layoutMargins)
|
|
}
|
|
|
|
public typealias TapBlock = () -> Void
|
|
private var tapBlock: TapBlock?
|
|
|
|
public func addTapGesture(_ tapBlock: @escaping TapBlock) {
|
|
owsAssertDebug(self.tapBlock == nil)
|
|
|
|
isUserInteractionEnabled = true
|
|
addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(didTap)))
|
|
self.tapBlock = tapBlock
|
|
}
|
|
|
|
@objc
|
|
private func didTap() {
|
|
owsAssertDebug(tapBlock != nil)
|
|
|
|
tapBlock?()
|
|
}
|
|
}
|
|
|
|
// MARK: -
|
|
|
|
extension NSLayoutConstraint.Axis: CustomStringConvertible {
|
|
public var description: String {
|
|
switch self {
|
|
case .horizontal:
|
|
return "horizontal"
|
|
case .vertical:
|
|
return "vertical"
|
|
@unknown default:
|
|
owsFailDebug("unexpected value: \(self.rawValue)")
|
|
return "unknown"
|
|
}
|
|
}
|
|
}
|
|
|
|
// MARK: -
|
|
|
|
extension UIStackView.Alignment: CustomStringConvertible {
|
|
public var description: String {
|
|
switch self {
|
|
case .fill:
|
|
return "fill"
|
|
case .leading:
|
|
return "leading"
|
|
case .firstBaseline:
|
|
return "firstBaseline"
|
|
case .center:
|
|
return "center"
|
|
case .trailing:
|
|
return "trailing"
|
|
case .lastBaseline:
|
|
return "lastBaseline"
|
|
@unknown default:
|
|
owsFailDebug("unexpected value: \(self.rawValue)")
|
|
return "unknown"
|
|
}
|
|
}
|
|
}
|