updated for orientation
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
4960dcf512
commit
e951326f7c
@ -10,7 +10,7 @@ import UIKit
|
||||
|
||||
public class RadioBoxGroup: Control<DefaultRadioBoxGroupModel>, SelectorGroupSelectedHandlerable, Changable {
|
||||
public typealias ModelHandlerType = RadioBox
|
||||
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Public Properties
|
||||
//--------------------------------------------------
|
||||
@ -24,7 +24,7 @@ public class RadioBoxGroup: Control<DefaultRadioBoxGroupModel>, SelectorGroupSel
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public var hasError: Bool {
|
||||
get { model.hasError }
|
||||
set {
|
||||
@ -50,9 +50,7 @@ public class RadioBoxGroup: Control<DefaultRadioBoxGroupModel>, 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<DefaultRadioBoxGroupModel>, 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<DefaultRadioBoxGroupModel>, 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)
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user