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 class RadioBoxGroup: Control<DefaultRadioBoxGroupModel>, SelectorGroupSelectedHandlerable, Changable {
|
||||||
public typealias ModelHandlerType = RadioBox
|
public typealias ModelHandlerType = RadioBox
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Public Properties
|
// MARK: - Public Properties
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -24,7 +24,7 @@ public class RadioBoxGroup: Control<DefaultRadioBoxGroupModel>, SelectorGroupSel
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public var hasError: Bool {
|
public var hasError: Bool {
|
||||||
get { model.hasError }
|
get { model.hasError }
|
||||||
set {
|
set {
|
||||||
@ -50,9 +50,7 @@ public class RadioBoxGroup: Control<DefaultRadioBoxGroupModel>, SelectorGroupSel
|
|||||||
private var mainStackView: UIStackView = {
|
private var mainStackView: UIStackView = {
|
||||||
return UIStackView().with {
|
return UIStackView().with {
|
||||||
$0.translatesAutoresizingMaskIntoConstraints = false
|
$0.translatesAutoresizingMaskIntoConstraints = false
|
||||||
$0.axis = .vertical
|
|
||||||
$0.alignment = .fill
|
$0.alignment = .fill
|
||||||
$0.distribution = .fill
|
|
||||||
$0.spacing = 12
|
$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() {
|
open override func setup() {
|
||||||
super.setup()
|
super.setup()
|
||||||
|
|
||||||
isAccessibilityElement = true
|
isAccessibilityElement = true
|
||||||
accessibilityTraits = .button
|
accessibilityTraits = .button
|
||||||
addSubview(mainStackView)
|
addSubview(mainStackView)
|
||||||
|
ensureDevice()
|
||||||
mainStackView.topAnchor.constraint(equalTo: topAnchor).isActive = true
|
mainStackView.topAnchor.constraint(equalTo: topAnchor).isActive = true
|
||||||
mainStackView.leadingAnchor.constraint(equalTo: leadingAnchor).isActive = true
|
mainStackView.leadingAnchor.constraint(equalTo: leadingAnchor).isActive = true
|
||||||
mainStackView.trailingAnchor.constraint(equalTo: trailingAnchor).isActive = true
|
mainStackView.trailingAnchor.constraint(equalTo: trailingAnchor).isActive = true
|
||||||
@ -88,13 +101,7 @@ public class RadioBoxGroup: Control<DefaultRadioBoxGroupModel>, SelectorGroupSel
|
|||||||
.publisher(for: UIDevice.orientationDidChangeNotification)
|
.publisher(for: UIDevice.orientationDidChangeNotification)
|
||||||
.sink() { [weak self] _ in
|
.sink() { [weak self] _ in
|
||||||
UIView.animate(withDuration: 1.0) {
|
UIView.animate(withDuration: 1.0) {
|
||||||
if UIDevice.current.orientation.isPortrait {
|
self?.ensureDevice()
|
||||||
self?.mainStackView.axis = .vertical
|
|
||||||
self?.mainStackView.distribution = .fill
|
|
||||||
} else {
|
|
||||||
self?.mainStackView.axis = .horizontal
|
|
||||||
self?.mainStackView.distribution = .fillEqually
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}.store(in: &subscribers)
|
}.store(in: &subscribers)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user