880 lines
34 KiB
Swift
880 lines
34 KiB
Swift
//
|
|
// TiletViewController.swift
|
|
// VDSSample
|
|
//
|
|
// Created by Matt Bruce on 12/19/22.
|
|
//
|
|
|
|
import Foundation
|
|
import UIKit
|
|
import VDS
|
|
import VDSCoreTokens
|
|
import Combine
|
|
|
|
class TileletViewController: BaseViewController<Tilelet> {
|
|
|
|
lazy var titleStandardStylePickerSelectorView = {
|
|
PickerSelectorView(title: "",
|
|
picker: self.picker,
|
|
items: Tilelet.TitleModel.StandardStyle.allCases.sorted{ $0.rawValue < $1.rawValue })
|
|
}()
|
|
|
|
lazy var otherStandardStylePickerSelectorView = {
|
|
PickerSelectorView(title: "",
|
|
picker: self.picker,
|
|
items: Tilelet.SubTitleModel.OtherStandardStyle.allCases.sorted{ $0.rawValue < $1.rawValue })
|
|
}()
|
|
|
|
lazy var textPositionPickerSelectorView = {
|
|
PickerSelectorView(title: "",
|
|
picker: self.picker,
|
|
items: Tilelet.TextPosition.allCases.sorted{ $0.rawValue < $1.rawValue })
|
|
}()
|
|
|
|
lazy var paddingPickerSelectorView = {
|
|
PickerSelectorView(title: "small",
|
|
picker: self.picker,
|
|
items: Tilelet.Padding.allCases)
|
|
}()
|
|
lazy var badgeFillColorPickerSelectorView = {
|
|
PickerSelectorView(title: "red",
|
|
picker: self.picker,
|
|
items: BadgeViewController.FillColor.allCases)
|
|
}()
|
|
lazy var badgeNumberOfLinesPickerSelectorView = {
|
|
PickerSelectorView(title: "one",
|
|
picker: self.picker,
|
|
items: BadgeViewController.NumberOfLines.allCases)
|
|
}()
|
|
lazy var scalingTypePickerSelectorView = {
|
|
PickerSelectorView(title: "white",
|
|
picker: self.picker,
|
|
items: Tilelet.AspectRatio.allCases)
|
|
}()
|
|
lazy var imageFallbackColorPickerSelectorView = {
|
|
SurfacePickerSelectorView(picker: self.picker)
|
|
}()
|
|
|
|
lazy var backgroundEffectSelectorView = {
|
|
PickerSelectorView(title: "none",
|
|
picker: self.picker,
|
|
items: TileContainerViewController.BackgroundEffect.allCases)
|
|
}()
|
|
|
|
lazy var backgroundColorPickerSelectorView: TokenColorPickerSection = {
|
|
TokenColorPickerSection<BackgroundColor>(
|
|
rowTitle: "Background Color",
|
|
rowTooltip: .init(title:"Background Color", content: "This color takes precedence over surface and will set all children's surface property to this value."),
|
|
picker: self.picker).with {
|
|
$0.onSelected = { [weak self] item in
|
|
guard let self else { return }
|
|
switch item {
|
|
case .primary:
|
|
component.color = .primary
|
|
case .secondary:
|
|
component.color = .secondary
|
|
case .white:
|
|
component.color = .white
|
|
case .black:
|
|
component.color = .black
|
|
default: break;
|
|
}
|
|
}
|
|
$0.onTokenSelected = { [weak self] color in
|
|
guard let self else { return }
|
|
component.color = .custom(color.uiColor)
|
|
}
|
|
$0.onColorSelected = { [weak self] color in
|
|
guard let self else { return }
|
|
component.color = .custom(color)
|
|
|
|
}
|
|
}
|
|
}()
|
|
|
|
lazy var gradientColorView1: ColorPickerView = {
|
|
return .init().with {
|
|
$0.onColorSelected = { [weak self] _ in
|
|
guard let self else { return }
|
|
updateGradientColors()
|
|
}
|
|
}
|
|
}()
|
|
|
|
lazy var gradientColorView2: ColorPickerView = {
|
|
return .init().with {
|
|
$0.onColorSelected = { [weak self] _ in
|
|
guard let self else { return }
|
|
updateGradientColors()
|
|
}
|
|
}
|
|
}()
|
|
|
|
lazy var textAlignmentPickerSelectorView = {
|
|
PickerSelectorView(title: "left",
|
|
picker: self.picker,
|
|
items: TitleLockup.TextAlignment.allCases)
|
|
}()
|
|
|
|
/// Badge
|
|
enum BadgeFillColor: String, CaseIterable {
|
|
case red, yellow, green, orange, blue, black, white, token, custom
|
|
}
|
|
|
|
enum BadgeTextColor: String, CaseIterable {
|
|
case `default`, token, custom
|
|
}
|
|
|
|
var badgeFillColor: Badge.FillColor = .red { didSet { setBadgeModel() } }
|
|
lazy var badgeFillColorSection = {
|
|
TokenColorPickerSection<BadgeFillColor>(rowTitle: "Fill Color", picker: self.picker).with {
|
|
$0.onSelected = { [weak self] item in
|
|
guard let self else { return }
|
|
var fillColor: Badge.FillColor = .red
|
|
switch item {
|
|
case .red:
|
|
fillColor = .red
|
|
case .yellow:
|
|
fillColor = .yellow
|
|
case .green:
|
|
fillColor = .green
|
|
case .orange:
|
|
fillColor = .orange
|
|
case .blue:
|
|
fillColor = .blue
|
|
case .black:
|
|
fillColor = .black
|
|
case .white:
|
|
fillColor = .white
|
|
default:
|
|
break
|
|
}
|
|
badgeFillColor = fillColor
|
|
}
|
|
$0.onTokenSelected = { [weak self] color in
|
|
guard let self else { return }
|
|
badgeFillColor = .token(color)
|
|
}
|
|
$0.onColorSelected = { [weak self] color in
|
|
guard let self else { return }
|
|
badgeFillColor = .custom(color)
|
|
}
|
|
}
|
|
}()
|
|
|
|
var badgeTextColor: Badge.TextColor? { didSet { setBadgeModel() } }
|
|
lazy var badgeTextColorSection = {
|
|
TokenColorPickerSection<BadgeTextColor>(rowTitle: "Text Color", picker: self.picker).with {
|
|
$0.onSelected = { [weak self] item in
|
|
guard let self else { return }
|
|
badgeTextColor = nil
|
|
}
|
|
$0.onTokenSelected = { [weak self] color in
|
|
guard let self else { return }
|
|
badgeTextColor = .token(color)
|
|
}
|
|
$0.onColorSelected = { [weak self] color in
|
|
guard let self else { return }
|
|
badgeTextColor = .custom(color)
|
|
}
|
|
}
|
|
}()
|
|
|
|
/// titleLockup
|
|
var currentSurfaceColorType: SurfaceColorType = .title
|
|
enum SurfaceColorType {
|
|
case background, eyebrow, title, subtitle, directionalIcon, descriptionIcon
|
|
}
|
|
|
|
enum TitleTextColor: String, CaseIterable {
|
|
case primary, token, custom
|
|
}
|
|
|
|
enum TextColor: String, CaseIterable {
|
|
case primary, secondary, token, custom
|
|
}
|
|
|
|
enum IconColor: String, CaseIterable {
|
|
case `default`, token, custom
|
|
}
|
|
|
|
/// eyebrow
|
|
var eyeBrowTextColor: TitleLockup.TextColor = .primary { didSet { setEyebrowModel() } }
|
|
lazy var eyebrowTextColorFormSection = {
|
|
TokenColorPickerSection<TextColor>(rowTitle: "Text Color", picker: self.picker).with {
|
|
$0.onSelected = { [weak self] item in
|
|
guard let self else { return }
|
|
switch item {
|
|
case .primary:
|
|
eyeBrowTextColor = .primary
|
|
case .secondary:
|
|
eyeBrowTextColor = .secondary
|
|
default: break
|
|
}
|
|
}
|
|
$0.onTokenSelected = { [weak self] color in
|
|
guard let self else { return }
|
|
eyeBrowTextColor = .token(color)
|
|
}
|
|
$0.onColorSelected = { [weak self] color in
|
|
guard let self else { return }
|
|
eyeBrowTextColor = .custom(color)
|
|
}
|
|
}
|
|
}()
|
|
|
|
var subtitleTextColor: TitleLockup.TextColor = .primary { didSet { setSubTitleModel() } }
|
|
lazy var subTitleTextColorFormSection = {
|
|
TokenColorPickerSection<TextColor>(rowTitle: "Text Color", picker: self.picker).with {
|
|
$0.onSelected = { [weak self] item in
|
|
guard let self else { return }
|
|
switch item {
|
|
case .primary:
|
|
subtitleTextColor = .primary
|
|
case .secondary:
|
|
subtitleTextColor = .secondary
|
|
default: break
|
|
}
|
|
}
|
|
$0.onTokenSelected = { [weak self] color in
|
|
guard let self else { return }
|
|
subtitleTextColor = .token(color)
|
|
}
|
|
$0.onColorSelected = { [weak self] color in
|
|
guard let self else { return }
|
|
subtitleTextColor = .custom(color)
|
|
}
|
|
}
|
|
}()
|
|
|
|
var titleTextColor: TitleLockup.TitleTextColor = .primary { didSet { setTitleModel() } }
|
|
lazy var titleTextColorFormSection = {
|
|
TokenColorPickerSection<TitleTextColor>(rowTitle: "Text Color", picker: self.picker).with {
|
|
$0.onSelected = { [weak self] item in
|
|
guard let self else { return }
|
|
switch item {
|
|
case .primary:
|
|
titleTextColor = .primary
|
|
default: break
|
|
}
|
|
}
|
|
$0.onTokenSelected = { [weak self] color in
|
|
guard let self else { return }
|
|
titleTextColor = .token(color)
|
|
}
|
|
$0.onColorSelected = { [weak self] color in
|
|
guard let self else { return }
|
|
titleTextColor = .custom(color)
|
|
}
|
|
}
|
|
}()
|
|
|
|
///Icons
|
|
var descriptionIconFormStackView = FormSection().with { $0.isHidden = true }
|
|
lazy var descriptionNamePickerSelectorView = {
|
|
PickerSelectorView(title: "",
|
|
picker: self.picker,
|
|
items: Icon.Name.all.sorted{ $0.rawValue < $1.rawValue })
|
|
}()
|
|
|
|
lazy var descriptionIconSizePickerSelectorView = {
|
|
PickerSelectorView(title: "",
|
|
picker: self.picker,
|
|
items: Icon.Size.allCases)
|
|
}()
|
|
|
|
var descriptionIconColor: Tilelet.IconColor? = .token(.paletteWhite) { didSet { setDescriptiveIconModel() } }
|
|
lazy var descriptionIconColorFormSection = {
|
|
TokenColorPickerSection<IconColor>(picker: self.picker).with {
|
|
$0.onSelected = { [weak self] item in
|
|
guard let self else { return }
|
|
switch item {
|
|
case .default:
|
|
descriptionIconColor = nil
|
|
default: break
|
|
}
|
|
}
|
|
$0.onTokenSelected = { [weak self] color in
|
|
guard let self else { return }
|
|
descriptionIconColor = .token(color)
|
|
}
|
|
$0.onColorSelected = { [weak self] color in
|
|
guard let self else { return }
|
|
descriptionIconColor = .custom(color)
|
|
}
|
|
$0.isHidden = true
|
|
}
|
|
}()
|
|
|
|
|
|
var directionalIconFormStackView = FormSection().with { $0.isHidden = true }
|
|
|
|
lazy var directionIconPickerSelectorView = {
|
|
PickerSelectorView(title: "",
|
|
picker: self.picker,
|
|
items: Tilelet.DirectionalIcon.IconType.allCases.sorted{ $0.rawValue < $1.rawValue })
|
|
}()
|
|
|
|
lazy var directionIconSizePickerSelectorView = {
|
|
PickerSelectorView(title: "",
|
|
picker: self.picker,
|
|
items: Tilelet.DirectionalIcon.IconSize.allCases.sorted{ $0.rawValue < $1.rawValue })
|
|
}()
|
|
var directionIconColor: Tilelet.IconColor? = .token(.paletteWhite) { didSet { setDirectionalIconModel() } }
|
|
lazy var directionIconColorFormSection = {
|
|
TokenColorPickerSection<IconColor>(picker: self.picker).with {
|
|
$0.onSelected = { [weak self] item in
|
|
guard let self else { return }
|
|
switch item {
|
|
case .default:
|
|
directionIconColor = nil
|
|
default: break
|
|
}
|
|
}
|
|
$0.onTokenSelected = { [weak self] color in
|
|
guard let self else { return }
|
|
directionIconColor = .token(color)
|
|
}
|
|
$0.onColorSelected = { [weak self] color in
|
|
guard let self else { return }
|
|
directionIconColor = .custom(color)
|
|
}
|
|
$0.isHidden = true
|
|
}
|
|
}()
|
|
|
|
let backgroundImage = UIImage(named: "backgroundTest")!
|
|
var clickableSwitch = Toggle()
|
|
var eyebrowTextField = TextField()
|
|
var titleTextField = TextField()
|
|
var subTitleTextField = TextField()
|
|
var widthTextField = NumericField()
|
|
var heightTextField = NumericField()
|
|
var textPercentageTextField = NumericField()
|
|
var textWidthTextField = NumericField()
|
|
var showBackgroundImageSwitch = Toggle()
|
|
var showDescriptionIconSwitch = Toggle()
|
|
var showDirectionalIconSwitch = Toggle()
|
|
var badgeTextField = TextField()
|
|
var eyebrowIsBold = Toggle().with { $0.isOn = true }
|
|
var titleIsBold = Toggle().with { $0.isOn = true }
|
|
var selectedGradient1Color: String?
|
|
var selectedGradient2Color: String?
|
|
var selectedGradientColorView: UIView?
|
|
var showDropShadowSwitch = Toggle()
|
|
var backgroundColor: BackgroundColor = .black
|
|
var maxWidthTextField = NumericField()
|
|
var isLinkSwitch = Toggle()
|
|
var descriptionIconAccessibilityTextField = TextField()
|
|
|
|
var gradientColorsFormStackView = FormSection().with { $0.isHidden = true }
|
|
|
|
override func viewDidLoad() {
|
|
super.viewDidLoad()
|
|
addContentTopView(view: component)
|
|
setupPicker()
|
|
setupModel()
|
|
}
|
|
|
|
override func setupForm(){
|
|
super.setupForm()
|
|
addFormRow(label: "Surface", view: surfacePickerSelectorView)
|
|
addActionRow()
|
|
addFormRow(label: "Is Link", view: isLinkSwitch, pinTrailing: false)
|
|
addFormRow(label: "Clickable", view: clickableSwitch, pinTrailing: false)
|
|
|
|
addFormRow(label: "Aspect Ratio", view: scalingTypePickerSelectorView)
|
|
addFormRow(label: "Padding", view: paddingPickerSelectorView)
|
|
addFormRow(label: "Width", view: widthTextField)
|
|
addFormRow(label: "Height", view: heightTextField)
|
|
addFormRow(label: "Text Alignment", view: textAlignmentPickerSelectorView)
|
|
addFormRow(label: "Text Width", view: textWidthTextField)
|
|
addFormRow(label: "Text Percentage", view: textPercentageTextField)
|
|
addFormRow(label: "Text Position", tooltip: .init(title:"Text Position", content: "Minimum height is configurable"), view: textPositionPickerSelectorView)
|
|
append(section: backgroundColorPickerSelectorView)
|
|
addFormRow(label: "Background Image", view: showBackgroundImageSwitch, pinTrailing: false)
|
|
addFormRow(label: "Show Drop Shadow", view: showDropShadowSwitch, pinTrailing: false)
|
|
addFormRow(label: "Image Fallback Color", view: imageFallbackColorPickerSelectorView)
|
|
addFormRow(label: "Background Effect", view: backgroundEffectSelectorView)
|
|
//Gradient Section
|
|
gradientColorsFormStackView.addFormRow(label: "Gradient Color1", view: gradientColorView1)
|
|
gradientColorsFormStackView.addFormRow(label: "Gradient Color2", view: gradientColorView2)
|
|
append(section: gradientColorsFormStackView)
|
|
|
|
append(section: .init().with({
|
|
$0.title = "Badge"
|
|
$0.addFormRow(label: "Text", view: badgeTextField)
|
|
$0.addFormRow(label: "Number of Lines", view: badgeNumberOfLinesPickerSelectorView)
|
|
$0.addFormRow(label: "Max Width", view: maxWidthTextField)
|
|
}))
|
|
append(section: badgeFillColorSection)
|
|
append(section: badgeTextColorSection)
|
|
|
|
append(section: .init().with({
|
|
$0.title = "Text Styles"
|
|
$0.addFormRow(label: "Title", view: titleStandardStylePickerSelectorView)
|
|
$0.addFormRow(label: "Eyebrow/Subtitle", view: otherStandardStylePickerSelectorView)
|
|
}))
|
|
|
|
append(section: .init().with({
|
|
$0.title = "Eyebrow"
|
|
$0.addFormRow(label: "is Bold", view: eyebrowIsBold, pinTrailing: false)
|
|
$0.addFormRow(label: "Text", view: eyebrowTextField)
|
|
}))
|
|
append(section: eyebrowTextColorFormSection)
|
|
|
|
append(section: .init().with({
|
|
$0.title = "Title"
|
|
$0.addFormRow(label: "is Bold", view: titleIsBold, pinTrailing: false)
|
|
$0.addFormRow(label: "Text", view: titleTextField)
|
|
}))
|
|
append(section: titleTextColorFormSection)
|
|
|
|
append(section: .init().with({
|
|
$0.title = "Subtitle"
|
|
$0.addFormRow(label: "Text", view: subTitleTextField)
|
|
}))
|
|
append(section: subTitleTextColorFormSection)
|
|
|
|
append(section: .init().with({
|
|
$0.title = "Description Icon "
|
|
$0.addFormRow(label: "Show", view: showDescriptionIconSwitch, pinTrailing: false)
|
|
}))
|
|
append(section: descriptionIconFormStackView)
|
|
descriptionIconFormStackView.addFormRow(label: "Icon", view: descriptionNamePickerSelectorView)
|
|
descriptionIconFormStackView.addFormRow(label: "Accessibility", view: descriptionIconAccessibilityTextField)
|
|
descriptionIconFormStackView.addFormRow(label: "Size", view: descriptionIconSizePickerSelectorView)
|
|
append(section: descriptionIconColorFormSection)
|
|
|
|
append(section: .init().with({
|
|
$0.title = "Directional Icon"
|
|
$0.addFormRow(label: "Show", view: showDirectionalIconSwitch, pinTrailing: false)
|
|
}))
|
|
append(section: directionalIconFormStackView)
|
|
directionalIconFormStackView.addFormRow(label: "Icon", view: directionIconPickerSelectorView)
|
|
directionalIconFormStackView.addFormRow(label: "Size", view: directionIconSizePickerSelectorView)
|
|
append(section: directionIconColorFormSection)
|
|
|
|
clickableSwitch.onChange = { [weak self] sender in
|
|
guard let self else { return }
|
|
if sender.isOn {
|
|
self.component.onClickActionPublisher("Tilelet", label: actionLabel)
|
|
} else {
|
|
self.component.onClick = nil
|
|
}
|
|
}
|
|
|
|
isLinkSwitch.onChange = { [weak self] sender in
|
|
guard let self else { return }
|
|
self.component.accessibilityTraits = sender.isOn ? .link : .button
|
|
}
|
|
|
|
heightTextField
|
|
.numberPublisher
|
|
.sink { [weak self] number in
|
|
guard let self, let number = number?.cgFloatValue else {
|
|
self?.heightTextField.text = ""
|
|
return
|
|
}
|
|
if number >= 100 && number < self.view.frame.height * 0.65 {
|
|
self.component.height = number
|
|
} else {
|
|
self.component.height = nil
|
|
}
|
|
if let val = heightTextField.text, val.count > 2, number < 100 {
|
|
heightTextField.text = ""
|
|
}
|
|
}.store(in: &subscribers)
|
|
|
|
widthTextField
|
|
.numberPublisher
|
|
.sink { [weak self] number in
|
|
self?.updateComponentConstraint(pinTrailing: number == nil)
|
|
guard let self, let number = number?.cgFloatValue else {
|
|
self?.widthTextField.text = ""
|
|
return
|
|
}
|
|
if number >= 100 && number < self.view.frame.width * 0.85 {
|
|
self.component.width = number
|
|
} else {
|
|
self.component.width = nil
|
|
}
|
|
if let val = widthTextField.text, val.count > 2, number < 100 {
|
|
widthTextField.text = ""
|
|
}
|
|
}.store(in: &subscribers)
|
|
|
|
textWidthTextField
|
|
.numberPublisher
|
|
.sink { [weak self] number in
|
|
if let number {
|
|
self?.component.textWidth = .value(number.cgFloatValue)
|
|
self?.textPercentageTextField.text = ""
|
|
} else {
|
|
self?.component.textWidth = nil
|
|
}
|
|
}.store(in: &subscribers)
|
|
|
|
textPercentageTextField
|
|
.numberPublisher
|
|
.sink { [weak self] number in
|
|
if let number {
|
|
self?.component.textWidth = .percentage(number.cgFloatValue)
|
|
self?.textWidthTextField.text = ""
|
|
} else {
|
|
self?.component.textWidth = nil
|
|
}
|
|
}.store(in: &subscribers)
|
|
|
|
titleTextField
|
|
.textPublisher
|
|
.sink { [weak self] text in
|
|
self?.setTitleModel()
|
|
}.store(in: &subscribers)
|
|
|
|
subTitleTextField
|
|
.textPublisher
|
|
.sink { [weak self] text in
|
|
self?.setSubTitleModel()
|
|
}.store(in: &subscribers)
|
|
|
|
badgeTextField
|
|
.textPublisher
|
|
.sink { [weak self] text in
|
|
self?.setBadgeModel()
|
|
}.store(in: &subscribers)
|
|
|
|
showDescriptionIconSwitch.onChange = { [weak self] sender in
|
|
guard let self else { return }
|
|
self.setDescriptionIconForm()
|
|
}
|
|
|
|
descriptionIconAccessibilityTextField
|
|
.textPublisher
|
|
.sink { [weak self] text in
|
|
self?.setDescriptiveIconModel()
|
|
}.store(in: &subscribers)
|
|
|
|
showDirectionalIconSwitch.onChange = { [weak self] sender in
|
|
guard let self else { return }
|
|
self.setDirectionalIconForm()
|
|
}
|
|
|
|
eyebrowIsBold.publisher(for: .valueChanged).sink { [weak self] toggle in
|
|
self?.setEyebrowModel()
|
|
}.store(in: &subscribers)
|
|
|
|
titleIsBold.publisher(for: .valueChanged).sink { [weak self] toggle in
|
|
self?.setTitleModel()
|
|
}.store(in: &subscribers)
|
|
|
|
paddingPickerSelectorView.onPickerDidSelect = { [weak self] item in
|
|
self?.component.padding = item
|
|
}
|
|
|
|
eyebrowTextField.textPublisher
|
|
.sink { [weak self] text in
|
|
self?.setEyebrowModel()
|
|
}.store(in: &subscribers)
|
|
|
|
showBackgroundImageSwitch.onChange = { [weak self] sender in
|
|
if let image = self?.backgroundImage, sender.isOn {
|
|
self?.component.backgroundImage = image
|
|
} else {
|
|
self?.component.backgroundImage = nil
|
|
}
|
|
}
|
|
|
|
showDropShadowSwitch.onChange = { [weak self] sender in
|
|
self?.component.showDropShadow = sender.isOn
|
|
}
|
|
|
|
imageFallbackColorPickerSelectorView.onPickerDidSelect = { [weak self] item in
|
|
self?.component.imageFallbackColor = item
|
|
}
|
|
|
|
maxWidthTextField
|
|
.numberPublisher
|
|
.sink { [weak self] number in
|
|
guard let number else { return }
|
|
self?.component.badgeModel?.maxWidth = number.cgFloatValue
|
|
}.store(in: &subscribers)
|
|
}
|
|
|
|
func setupModel() {
|
|
let titleModel = Tilelet.TitleModel(text: "Save $XX on your monthly bill.")
|
|
let subTitleModel = Tilelet.SubTitleModel(text: "Enroll in Auto Pay & paper-free billing to save on your monthly bill.")
|
|
component.color = .black
|
|
component.surface = .light
|
|
component.titleModel = titleModel
|
|
component.subTitleModel = subTitleModel
|
|
component.padding = .small
|
|
//setup UI
|
|
backgroundColorPickerSelectorView.setDefault(value: backgroundColor)
|
|
textAlignmentPickerSelectorView.text = TextAlignment.left.rawValue
|
|
surfacePickerSelectorView.text = component.surface.rawValue
|
|
otherStandardStylePickerSelectorView.text = subTitleModel.otherStandardStyle.rawValue
|
|
titleStandardStylePickerSelectorView.text = titleModel.standardStyle.rawValue
|
|
titleTextField.text = titleModel.text
|
|
subTitleTextField.text = subTitleModel.text
|
|
widthTextField.text = component.width != nil ? "\(component.width!)" : ""
|
|
textPositionPickerSelectorView.text = component.textPostion.rawValue
|
|
scalingTypePickerSelectorView.text = component.aspectRatio.rawValue
|
|
updateOtherTextStyles()
|
|
|
|
descriptionNamePickerSelectorView.text = Icon.Name.multipleDocuments.rawValue
|
|
descriptionIconSizePickerSelectorView.text = Icon.Size.medium.rawValue
|
|
|
|
directionIconPickerSelectorView.text = Tilelet.DirectionalIcon.IconType.rightArrow.rawValue
|
|
directionIconSizePickerSelectorView.text = Tilelet.DirectionalIcon.IconSize.medium.rawValue
|
|
|
|
badgeFillColorSection.setDefault(value: .red)
|
|
badgeTextColorSection.setDefault(value: .default)
|
|
|
|
eyebrowTextColorFormSection.setDefault(value: .primary)
|
|
titleTextColorFormSection.setDefault(value: .primary)
|
|
subTitleTextColorFormSection.setDefault(value: .primary)
|
|
|
|
descriptionIconColorFormSection.setDefault(value: .token)
|
|
directionIconColorFormSection.setDefault(value: .token)
|
|
}
|
|
|
|
func setIconColorForms() {
|
|
setDirectionalIconColorForm()
|
|
setDescriptionIconColorForm()
|
|
}
|
|
|
|
func setDirectionalIconColorForm() {
|
|
directionIconColorFormSection.isHidden = !showDirectionalIconSwitch.isOn
|
|
}
|
|
|
|
func setDescriptionIconColorForm() {
|
|
descriptionIconColorFormSection.isHidden = !showDescriptionIconSwitch.isOn
|
|
}
|
|
|
|
func setDescriptionIconForm() {
|
|
let showForm = showDescriptionIconSwitch.isOn
|
|
descriptionIconFormStackView.isHidden = !showForm
|
|
directionalIconFormStackView.isHidden = true
|
|
if showForm {
|
|
showDirectionalIconSwitch.isOn = false
|
|
setDescriptiveIconModel()
|
|
} else {
|
|
component.descriptiveIconModel = nil
|
|
}
|
|
setIconColorForms()
|
|
}
|
|
|
|
func setDirectionalIconForm() {
|
|
let showForm = showDirectionalIconSwitch.isOn
|
|
directionalIconFormStackView.isHidden = !showForm
|
|
descriptionIconFormStackView.isHidden = true
|
|
if showForm {
|
|
showDescriptionIconSwitch.isOn = false
|
|
setDirectionalIconModel()
|
|
} else {
|
|
component.directionalIconModel = nil
|
|
}
|
|
setIconColorForms()
|
|
}
|
|
|
|
//sub models
|
|
func setBadgeModel() {
|
|
if let text = badgeTextField.text, !text.isEmpty {
|
|
component.badgeModel = Tilelet.BadgeModel(text: text, textColor: badgeTextColor, fillColor: badgeFillColor, numberOfLines: badgeNumberOfLinesPickerSelectorView.selectedItem.intValue)
|
|
} else {
|
|
component.badgeModel = nil
|
|
}
|
|
}
|
|
|
|
func setTitleModel() {
|
|
if let text = titleTextField.text, !text.isEmpty {
|
|
component.titleModel = Tilelet.TitleModel(text: text, textColor: titleTextColor, isBold: titleIsBold.isOn, standardStyle: titleStandardStylePickerSelectorView.selectedItem)
|
|
} else {
|
|
component.titleModel = nil
|
|
}
|
|
}
|
|
|
|
func setSubTitleModel() {
|
|
if let text = subTitleTextField.text, !text.isEmpty {
|
|
component.subTitleModel = Tilelet.SubTitleModel(text: text, otherStandardStyle: otherStandardStylePickerSelectorView.selectedItem, textColor: subtitleTextColor)
|
|
} else {
|
|
component.subTitleModel = nil
|
|
}
|
|
}
|
|
|
|
func setEyebrowModel() {
|
|
if let text = eyebrowTextField.text, !text.isEmpty {
|
|
component.eyebrowModel = Tilelet.EyebrowModel(text: text, textColor: eyeBrowTextColor, isBold: eyebrowIsBold.isOn, standardStyle: otherStandardStylePickerSelectorView.selectedItem)
|
|
} else {
|
|
component.eyebrowModel = nil
|
|
}
|
|
}
|
|
|
|
func setDescriptiveIconModel() {
|
|
let iconSize = descriptionIconSizePickerSelectorView.selectedItem
|
|
let iconName = descriptionNamePickerSelectorView.selectedItem
|
|
var accessibleText: String?
|
|
if let at = descriptionIconAccessibilityTextField.text, !at.isEmpty {
|
|
accessibleText = at
|
|
}
|
|
|
|
component.descriptiveIconModel = .init(name: iconName, iconColor: descriptionIconColor, size: iconSize, accessibleText: accessibleText ?? nil )
|
|
}
|
|
|
|
func setDirectionalIconModel() {
|
|
let iconType = directionIconPickerSelectorView.selectedItem
|
|
let iconSize = directionIconSizePickerSelectorView.selectedItem
|
|
|
|
component.directionalIconModel = .init(iconType: iconType, iconColor: directionIconColor, size: iconSize)
|
|
}
|
|
|
|
func updateGradientColors(){
|
|
if let selectedGradient1Color = gradientColorView1.selectedColor,
|
|
let selectedGradient2Color = gradientColorView2.selectedColor{
|
|
component.backgroundEffect = .gradient(selectedGradient1Color, selectedGradient2Color)
|
|
}
|
|
}
|
|
|
|
func updateOtherTextStyles() {
|
|
let items = component.titleLockup.standardStyleConfiguration.configuration(for: titleStandardStylePickerSelectorView.selectedItem.value)!.allOtherStandardStyles
|
|
let otheritems = items.compactMap { Tilelet.SubTitleModel.OtherStandardStyle(rawValue: $0.rawValue)! }
|
|
otherStandardStylePickerSelectorView.items = otheritems
|
|
otherStandardStylePickerSelectorView.text = otheritems.first?.rawValue ?? ""
|
|
setSubTitleModel()
|
|
}
|
|
|
|
//Picker
|
|
func setupPicker(){
|
|
surfacePickerSelectorView.onPickerDidSelect = { [weak self] item in
|
|
self?.component.surface = item
|
|
self?.contentTopView.backgroundColor = item.color
|
|
}
|
|
|
|
titleStandardStylePickerSelectorView.onPickerDidSelect = { [weak self] item in
|
|
guard let self else { return }
|
|
self.setTitleModel()
|
|
self.updateOtherTextStyles()
|
|
}
|
|
|
|
otherStandardStylePickerSelectorView.onPickerDidSelect = { [weak self] item in
|
|
self?.setSubTitleModel()
|
|
}
|
|
|
|
textPositionPickerSelectorView.onPickerDidSelect = { [weak self] item in
|
|
guard let self else { return }
|
|
self.component.textPostion = item
|
|
}
|
|
|
|
badgeNumberOfLinesPickerSelectorView.onPickerDidSelect = { [weak self] item in
|
|
self?.component.badgeModel?.numberOfLines = item.intValue
|
|
}
|
|
|
|
scalingTypePickerSelectorView.onPickerDidSelect = { [weak self] item in
|
|
self?.component.aspectRatio = item
|
|
self?.component.layoutIfNeeded()
|
|
self?.showDebug(show: self?.debugViewSwitch.isOn ?? false)
|
|
}
|
|
|
|
backgroundEffectSelectorView.onPickerDidSelect = { [weak self] item in
|
|
guard let self else { return }
|
|
if let effect = item.effect {
|
|
self.component.backgroundEffect = self.getTilelet(effect: effect)
|
|
self.gradientColorsFormStackView.isHidden = true
|
|
self.gradientColorView1.selectedColor = nil
|
|
self.gradientColorView2.selectedColor = nil
|
|
} else {
|
|
self.gradientColorsFormStackView.isHidden = false
|
|
}
|
|
}
|
|
|
|
textAlignmentPickerSelectorView.onPickerDidSelect = { [weak self] item in
|
|
self?.component.titleLockup.textAlignment = item
|
|
}
|
|
|
|
descriptionNamePickerSelectorView.onPickerDidSelect = { [weak self] item in
|
|
self?.setDescriptiveIconModel()
|
|
}
|
|
|
|
descriptionIconSizePickerSelectorView.onPickerDidSelect = { [weak self] item in
|
|
self?.setDescriptiveIconModel()
|
|
}
|
|
|
|
directionIconPickerSelectorView.onPickerDidSelect = { [weak self] item in
|
|
self?.setDirectionalIconModel()
|
|
}
|
|
|
|
directionIconSizePickerSelectorView.onPickerDidSelect = { [weak self] item in
|
|
self?.setDirectionalIconModel()
|
|
}
|
|
|
|
}
|
|
|
|
func getTilelet(effect: TileContainer.BackgroundEffect) -> Tilelet.BackgroundEffect {
|
|
switch effect {
|
|
case .transparency:
|
|
Tilelet.BackgroundEffect.transparency
|
|
case .gradient(let firstColor, let secondColor):
|
|
Tilelet.BackgroundEffect.gradient(firstColor, secondColor)
|
|
default:
|
|
Tilelet.BackgroundEffect.none
|
|
}
|
|
}
|
|
|
|
func getTilelet(backgroundColor: BackgroundColor) -> Tilelet.BackgroundColor? {
|
|
switch backgroundColor {
|
|
case .primary:
|
|
.primary
|
|
case .secondary:
|
|
.secondary
|
|
case .white:
|
|
.white
|
|
case .black:
|
|
.black
|
|
case .custom:
|
|
nil
|
|
case .token:
|
|
nil
|
|
}
|
|
}
|
|
}
|
|
|
|
extension TileletViewController: ComponentSampleable {
|
|
static func makeSample() -> ComponentSample {
|
|
let component = Self.makeComponent()
|
|
let titleModel = Tilelet.TitleModel(text: "Save $XX on your monthly bill.")
|
|
let subTitleModel = Tilelet.SubTitleModel(text: "Enroll in Auto Pay & paper-free billing to save on your monthly bill.")
|
|
|
|
component.surface = .light
|
|
component.titleModel = titleModel
|
|
component.subTitleModel = subTitleModel
|
|
component.width = 250
|
|
return ComponentSample(component: component, trailingPinningType: .lessThanOrEqual)
|
|
}
|
|
}
|
|
|
|
extension TileletViewController {
|
|
|
|
enum BackgroundColor: String, CaseIterable {
|
|
|
|
case primary, secondary, white, black, token, custom
|
|
|
|
var color: TileContainer.BackgroundColor? {
|
|
switch self {
|
|
case .primary:
|
|
.primary
|
|
case .secondary:
|
|
.secondary
|
|
case .white:
|
|
.white
|
|
case .black:
|
|
.black
|
|
case .token:
|
|
nil
|
|
case .custom:
|
|
nil
|
|
}
|
|
}
|
|
}
|
|
}
|