Commit 61c5852e authored by Aral Balkan's avatar Aral Balkan

Update status image alignment based on vertical trait of interface

parent 9d5ae74e
......@@ -28,19 +28,22 @@ class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
UIApplication.shared.enableAdaptiveContentSizeMonitor()
let showLayoutGuides = true
// Hide the layout guides and reset the background colours on the layout elements.
let layoutGuides = [layoutGuideBase, layoutGuideTopMargin, layoutGuideStatusBadgeLeftMargin, layoutGuideStatusBadgeRightMargin, layoutGuideBottomMargin]
let layoutElements = [layoutElementStatusBadge, layoutElementStatusText]
for layoutGuide in layoutGuides { layoutGuide!.isHidden = true }
for layoutElement in layoutElements { layoutElement!.backgroundColor = UIColor.white }
if (!showLayoutGuides) {
// Hide the layout guides and reset the background colours on the layout elements.
let layoutGuides = [layoutGuideBase, layoutGuideTopMargin, layoutGuideStatusBadgeLeftMargin, layoutGuideStatusBadgeRightMargin, layoutGuideBottomMargin]
let layoutElements = [layoutElementStatusBadge, layoutElementStatusText]
for layoutGuide in layoutGuides { layoutGuide!.isHidden = true }
for layoutElement in layoutElements { layoutElement!.backgroundColor = UIColor.white }
}
// Set the image view to align the image internally from the left while also satisfying aspect fit.
statusImageView.imageContentMode = LDImageContentModeScaleAspectFit
statusImageView.imageHorizontalAlignment = LDImageHorizontalAlignmentLeft
updateStatusImageHorizontalAlignmentBasedOnTraitCollection(self.traitCollection)
updateText(true)
}
......@@ -101,6 +104,19 @@ class ViewController: UIViewController {
}
func updateStatusImageHorizontalAlignmentBasedOnTraitCollection(_ traitCollection: UITraitCollection) {
var statusImageViewHorizontalAlignment: LDImageHorizontalAlignment
if traitCollection.verticalSizeClass == .compact {
// On compacy layouts, left-align the badge.
statusImageViewHorizontalAlignment = LDImageHorizontalAlignmentLeft
} else {
// On all other layouts, centre it.
statusImageViewHorizontalAlignment = LDImageHorizontalAlignmentCenter
}
// Set the image view to align the image internally from the left while also satisfying aspect fit.
statusImageView.imageHorizontalAlignment = statusImageViewHorizontalAlignment
}
//
// MARK: - Notification handlers
......@@ -110,15 +126,20 @@ class ViewController: UIViewController {
// Scroll the status text to the top in the next stack frame in case the text overflows the visible
// area so that the top of the message is always visible. (This can happen when the text size is set
// to a large setting via Dynamic Type (Accessibility).
print("About to transition to size: \(size).")
_ = delay(0) { self.statusTextView.setContentOffset(.zero, animated: false) }
}
override func willRotate(to toInterfaceOrientation: UIInterfaceOrientation, duration: TimeInterval)
{
// When the
override func willTransition(to newCollection: UITraitCollection, with coordinator: UIViewControllerTransitionCoordinator) {
// TODO: LEFT OFF: Set the image horizontal alignment based on the vertical size class.
// (Left for compressed, centre for all others.)
print("Will transition to new trait collection.")
updateStatusImageHorizontalAlignmentBasedOnTraitCollection(newCollection)
}
func textView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange, interaction: UITextItemInteraction) -> Bool {
guard
let launchSettingsURL = Foundation.URL(string: "better://launch-settings"),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment