From e951326f7cbf45037d01a7345173c3c6efb3c655 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Thu, 25 Aug 2022 08:53:53 -0500 Subject: [PATCH] updated for orientation Signed-off-by: Matt Bruce --- VDS/Components/RadioBox/RadioBoxGroup.swift | 33 +++++++++++++-------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/VDS/Components/RadioBox/RadioBoxGroup.swift b/VDS/Components/RadioBox/RadioBoxGroup.swift index e8ac2eb1..94a58650 100644 --- a/VDS/Components/RadioBox/RadioBoxGroup.swift +++ b/VDS/Components/RadioBox/RadioBoxGroup.swift @@ -10,7 +10,7 @@ import UIKit public class RadioBoxGroup: Control, SelectorGroupSelectedHandlerable, Changable { public typealias ModelHandlerType = RadioBox - + //-------------------------------------------------- // MARK: - Public Properties //-------------------------------------------------- @@ -24,7 +24,7 @@ public class RadioBoxGroup: Control, SelectorGroupSel } } } - + public var hasError: Bool { get { model.hasError } set { @@ -50,9 +50,7 @@ public class RadioBoxGroup: Control, SelectorGroupSel private var mainStackView: UIStackView = { return UIStackView().with { $0.translatesAutoresizingMaskIntoConstraints = false - $0.axis = .vertical $0.alignment = .fill - $0.distribution = .fill $0.spacing = 12 } }() @@ -72,13 +70,28 @@ public class RadioBoxGroup: Control, SelectorGroupSel } } + private func ensureDevice() { + if UIDevice.isIPad { + mainStackView.axis = .horizontal + mainStackView.distribution = .fillEqually + } else { + if UIDevice.current.orientation.isPortrait || UIDevice.current.orientation == .unknown { + mainStackView.axis = .vertical + mainStackView.distribution = .fill + + } else { + mainStackView.axis = .horizontal + mainStackView.distribution = .fillEqually + } + } + } + open override func setup() { super.setup() - isAccessibilityElement = true accessibilityTraits = .button addSubview(mainStackView) - + ensureDevice() mainStackView.topAnchor.constraint(equalTo: topAnchor).isActive = true mainStackView.leadingAnchor.constraint(equalTo: leadingAnchor).isActive = true mainStackView.trailingAnchor.constraint(equalTo: trailingAnchor).isActive = true @@ -88,13 +101,7 @@ public class RadioBoxGroup: Control, SelectorGroupSel .publisher(for: UIDevice.orientationDidChangeNotification) .sink() { [weak self] _ in UIView.animate(withDuration: 1.0) { - if UIDevice.current.orientation.isPortrait { - self?.mainStackView.axis = .vertical - self?.mainStackView.distribution = .fill - } else { - self?.mainStackView.axis = .horizontal - self?.mainStackView.distribution = .fillEqually - } + self?.ensureDevice() } }.store(in: &subscribers) }