updated carousel
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
db6b8eb39a
commit
d72cd1e2da
@ -10,15 +10,15 @@ import VDS
|
||||
import UIKit
|
||||
|
||||
extension UIView {
|
||||
public func makeWrapper(edgeSpacing: CGFloat = 0.0, isTrailing: Bool = true) -> View {
|
||||
UIView.makeWrapper(for: self, edgeSpacing: edgeSpacing, isTrailing: isTrailing)
|
||||
public func makeWrapper(edgeSpacing: CGFloat = 0.0, isTrailing: Bool = true, isBottom: Bool = false) -> View {
|
||||
UIView.makeWrapper(for: self, edgeSpacing: edgeSpacing, isTrailing: isTrailing, isBottom: isBottom)
|
||||
}
|
||||
|
||||
public static func makeWrapper(for view: UIView, edgeSpacing: CGFloat = 0.0, isTrailing: Bool = true) -> View {
|
||||
makeWrapperWithConstraints(for: view, edgeSpacing: edgeSpacing, isTrailing: isTrailing).view
|
||||
public static func makeWrapper(for view: UIView, edgeSpacing: CGFloat = 0.0, isTrailing: Bool = true, isBottom: Bool = false) -> View {
|
||||
makeWrapperWithConstraints(for: view, edgeSpacing: edgeSpacing, isTrailing: isTrailing, isBottom: isBottom).view
|
||||
}
|
||||
|
||||
public static func makeWrapperWithConstraints(for view: UIView, edgeSpacing: CGFloat = 0.0, isTrailing: Bool = true) -> (view: View, container: NSLayoutConstraint.Container) {
|
||||
public static func makeWrapperWithConstraints(for view: UIView, edgeSpacing: CGFloat = 0.0, isTrailing: Bool = true, isBottom: Bool = false) -> (view: View, container: NSLayoutConstraint.Container) {
|
||||
let container = NSLayoutConstraint.Container()
|
||||
let wrapper = View().with {
|
||||
$0.translatesAutoresizingMaskIntoConstraints = false
|
||||
@ -26,7 +26,11 @@ extension UIView {
|
||||
wrapper.addSubview(view)
|
||||
|
||||
container.topConstraint = view.pinTop(anchor: wrapper.topAnchor, constant: edgeSpacing)
|
||||
container.bottomConstraint = view.pinBottom(anchor: wrapper.bottomAnchor, constant: edgeSpacing)
|
||||
if isBottom {
|
||||
container.bottomConstraint = view.pinBottomLessThanOrEqualTo(anchor: wrapper.bottomAnchor, constant: edgeSpacing)
|
||||
} else {
|
||||
container.bottomConstraint = view.pinBottom(anchor: wrapper.bottomAnchor, constant: edgeSpacing)
|
||||
}
|
||||
container.leadingConstraint = view.pinLeading(anchor: wrapper.leadingAnchor, constant: edgeSpacing)
|
||||
if isTrailing {
|
||||
container.trailingConstraint = view.pinTrailingLessThanOrEqualTo(anchor: wrapper.trailingAnchor, constant: edgeSpacing)
|
||||
|
||||
@ -132,18 +132,13 @@ class CarouselViewController: BaseViewController<Carousel> {
|
||||
rows.append(Button().with{ $0.use = .secondary; $0.text = "Shop"; $0.onClick = onClick})
|
||||
rows.append(Button().with{ $0.use = .secondary; $0.text = "Buy"; $0.onClick = onClick})
|
||||
rows.append(Button().with{ $0.use = .secondary; $0.text = "Offer"; $0.onClick = onClick})
|
||||
component.views = rows.compactMap({ view in
|
||||
return TileContainer().with { instance in
|
||||
instance.aspectRatio = .none
|
||||
instance.addContentView(view)
|
||||
instance.color = .custom(.lightGray)
|
||||
}
|
||||
})
|
||||
|
||||
label.text = "0"
|
||||
|
||||
component.slotAlignment = .init(vertical: Carousel.Vertical.top, horizontal: Carousel.Horizontal.left)
|
||||
horizAlignmtPickerSelectorView.text = Carousel.Horizontal.left.rawValue
|
||||
vertAlignmtPickerSelectorView.text = Carousel.Vertical.top.rawValue
|
||||
|
||||
updateCarousel()
|
||||
|
||||
// Callback when moving the carousel. Returns selectedGroupIndex.
|
||||
component.onChange = { [weak self] selectedGroupIndex in
|
||||
@ -152,6 +147,16 @@ class CarouselViewController: BaseViewController<Carousel> {
|
||||
}
|
||||
}
|
||||
|
||||
func updateCarousel() {
|
||||
component.views = rows.compactMap({ view in
|
||||
return TileContainer().with { instance in
|
||||
instance.aspectRatio = .none
|
||||
instance.addContentView(view)
|
||||
instance.color = .custom(.lightGray)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func setupPicker() {
|
||||
surfacePickerSelectorView.onPickerDidSelect = { [weak self] item in
|
||||
self?.component.surface = item
|
||||
@ -184,6 +189,7 @@ class CarouselViewController: BaseViewController<Carousel> {
|
||||
|
||||
gutterPickerSelectorView.onPickerDidSelect = { [weak self] item in
|
||||
self?.component.gutter = item
|
||||
self?.updateCarousel()
|
||||
}
|
||||
|
||||
layoutPickerSelectorView.onPickerDidSelect = { [weak self] item in
|
||||
@ -194,6 +200,7 @@ class CarouselViewController: BaseViewController<Carousel> {
|
||||
}
|
||||
self?.component.layout = item
|
||||
self?.label.text = "0"
|
||||
self?.updateCarousel()
|
||||
}
|
||||
|
||||
paginationKindPickerSelectorView.onPickerDidSelect = { [weak self] item in
|
||||
|
||||
Loading…
Reference in New Issue
Block a user