Created
March 6, 2022 03:24
-
-
Save oozoofrog/26e3864dd0a0adeb326ef5254b89768c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final class PreviewView: UIView, LayoutBuilding { | |
var capTop = true { | |
didSet { | |
UIView.animate(withDuration: 1.0) { | |
self.updateLayout() | |
} | |
} | |
} | |
let cap = UIButton() | |
let shoe = UIButton() | |
let title = UILabel() | |
var top: UIButton { capTop ? cap : shoe } | |
var bottom: UIButton { capTop ? shoe : cap } | |
var deactivable: Deactivable? | |
var layout: some Layout { | |
self { | |
top.anchors { | |
Anchors.cap() | |
} | |
bottom.anchors { | |
Anchors(.top).equalTo(top.bottomAnchor) | |
Anchors(.height).equalTo(top) | |
Anchors.shoe() | |
} | |
title.config { label in | |
label.text = "Top Title" | |
UIView.transition(with: label, duration: 1.0, options: [.beginFromCurrentState, .transitionCrossDissolve], animations: { | |
label.textColor = self.capTop ? .black : .yellow | |
}, completion: nil) | |
}.anchors { | |
Anchors(.centerX, .centerY).equalTo(top) | |
} | |
UILabel().config { label in | |
label.text = "Bottom Title" | |
label.textColor = capTop ? .yellow : .black | |
}.identifying("title.bottom").anchors { | |
Anchors(.centerX, .centerY).equalTo(bottom) | |
} | |
} | |
} | |
override init(frame: CGRect) { | |
super.init(frame: frame) | |
initViews() | |
} | |
required init?(coder: NSCoder) { | |
super.init(coder: coder) | |
initViews() | |
} | |
func initViews() { | |
cap.backgroundColor = .yellow | |
shoe.backgroundColor = .black | |
cap.addAction(.init(handler: { [weak self] _ in | |
self?.capTop.toggle() | |
}), for: .touchUpInside) | |
shoe.addAction(.init(handler: { [weak self] _ in | |
self?.capTop.toggle() | |
}), for: .touchUpInside) | |
self.accessibilityIdentifier = "root" | |
updateIdentifiers(rootObject: self) | |
updateLayout() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment