Skip to content

Commit

Permalink
fix(Sheet): IOS-7720 Fix asset size
Browse files Browse the repository at this point in the history
  • Loading branch information
amegias committed Sep 23, 2022
1 parent 7e26a8b commit 5b957c7
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ private enum Section: Int, CaseIterable {
case description
case numberOfElements
case hasAsset
case assetSize
case showSheet
}

Expand Down Expand Up @@ -67,6 +68,16 @@ class UICatalogSheetViewController: UIViewController {
return cell
}()

private lazy var assetSizeCell: UISegmentedControlTableViewCell = {
let cell = UISegmentedControlTableViewCell(reuseIdentifier: "assetSize")

cell.segmentedControl.insertSegment(withTitle: "Small", at: 0, animated: false)
cell.segmentedControl.insertSegment(withTitle: "Large", at: 1, animated: false)

cell.segmentedControl.selectedSegmentIndex = 1
return cell
}()

private lazy var showSheetCell: UITableViewCell = {
let cell = UITableViewCell(style: .default, reuseIdentifier: "showSheet")
cell.textLabel?.textColor = .textLink
Expand All @@ -80,6 +91,7 @@ class UICatalogSheetViewController: UIViewController {
[descriptionCell],
[numberOfElementsCell],
[assetCell],
[assetSizeCell],
[showSheetCell]
]

Expand Down Expand Up @@ -147,7 +159,13 @@ extension UICatalogSheetViewController: UITableViewDataSource, UITableViewDelega
id: index.description,
title: "Element \(index)",
description: "Description",
icon: assetCell.segmentedControl.selectedSegmentIndex == 0 ? SheetListRowIcon(url: "https://img.icons8.com/ios-glyphs/344/bookmark.png", urlDark: "https://img.icons8.com/ios/344/bookmark--v1.png") : nil
icon: assetCell.segmentedControl.selectedSegmentIndex == 0
? SheetListRowIcon(
url: "https://img.icons8.com/ios-glyphs/344/bookmark.png",
urlDark: "https://img.icons8.com/ios/344/bookmark--v1.png",
size: assetSizeCell.segmentedControl.selectedSegmentIndex == 0 ? .small : .large
)
: nil
)
rows.append(item)
}
Expand Down Expand Up @@ -205,6 +223,7 @@ private extension Section {
case .description: return "Description"
case .numberOfElements: return "Configuration"
case .hasAsset: return "Has asset"
case .assetSize: return "Asset size"
case .showSheet: return nil
}
}
Expand Down
55 changes: 36 additions & 19 deletions Sources/Mistica/Components/Sheet/Model/SheetConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import Foundation
import UIKit

public struct SheetConfiguration {
let header: SheetHeader
let content: [SheetList]
public let header: SheetHeader
public let content: [SheetList]

public init(header: SheetHeader,
content: [SheetList]) {
Expand All @@ -21,9 +21,9 @@ public struct SheetConfiguration {
}

public struct SheetHeader {
let title: String?
let subtitle: String?
let description: String?
public let title: String?
public let subtitle: String?
public let description: String?

public init(title: String? = nil,
subtitle: String? = nil,
Expand All @@ -35,12 +35,12 @@ public struct SheetHeader {
}

public struct SheetList {
let id: String
let type: String
let listType: String?
let autoSubmit: Bool?
let selectedId: String?
let items: [SheetListRow]
public let id: String
public let type: String
public let listType: String?
public let autoSubmit: Bool?
public let selectedId: String?
public let items: [SheetListRow]

public init(id: String,
type: String,
Expand All @@ -58,11 +58,11 @@ public struct SheetList {
}

public struct SheetListRow {
let id: String
let title: String?
let description: String?
let icon: SheetListRowIcon?
let isSelected: Bool
public let id: String
public let title: String?
public let description: String?
public let icon: SheetListRowIcon?
public let isSelected: Bool

public init(id: String,
title: String? = nil,
Expand All @@ -78,12 +78,29 @@ public struct SheetListRow {
}

public struct SheetListRowIcon {
let url: String
let urlDark: String?
public enum Size {
case small
case large

var value: CGFloat {
switch self {
case .small:
return 24
case .large:
return 40
}
}
}

public let url: String
public let urlDark: String?
public let size: Size

public init(url: String,
urlDark: String? = nil) {
urlDark: String? = nil,
size: Size = .large) {
self.url = url
self.urlDark = urlDark
self.size = size
}
}
4 changes: 2 additions & 2 deletions Sources/Mistica/Components/Sheet/View/SheetView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ private extension SheetView {

if let icon = item.icon {
let imageView = UIImageView()
imageView.heightAnchor.constraint(equalToConstant: 24.0).isActive = true
imageView.widthAnchor.constraint(equalToConstant: 24.0).isActive = true
imageView.heightAnchor.constraint(equalToConstant: icon.size.value).isActive = true
imageView.widthAnchor.constraint(equalToConstant: icon.size.value).isActive = true
imageView.contentMode = .scaleAspectFit
if let url = URL(string: icon.url),
let data = try? Data(contentsOf: url) {
Expand Down

0 comments on commit 5b957c7

Please sign in to comment.