-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Skeletons): added Mistica Skeletons components for SwiftUI and U…
…IKit
- Loading branch information
1 parent
93b62bb
commit e99d295
Showing
25 changed files
with
675 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
MisticaCatalog/Source/Assets.xcassets/Rows/Skeleton.imageset/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"filename" : "Skeleton.svg", | ||
"idiom" : "universal" | ||
}, | ||
{ | ||
"appearances" : [ | ||
{ | ||
"appearance" : "luminosity", | ||
"value" : "dark" | ||
} | ||
], | ||
"filename" : "Skeleton_Dark.svg", | ||
"idiom" : "universal" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
MisticaCatalog/Source/Assets.xcassets/Rows/Skeleton.imageset/Skeleton.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions
5
MisticaCatalog/Source/Assets.xcassets/Rows/Skeleton.imageset/Skeleton_Dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
MisticaCatalog/Source/Catalog/Mistica/Components/UICatalogSkeletonsViewController.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
// | ||
// UICatalogSkeletonsViewController.swift | ||
// | ||
// Made with ❤️ by Novum | ||
// | ||
// Copyright © Telefonica. All rights reserved. | ||
// | ||
|
||
import Mistica | ||
import UIKit | ||
|
||
class UICatalogSkeletonsViewController: UIViewController { | ||
private let scrollView: UIScrollView = { | ||
let scrollView = UIScrollView() | ||
scrollView.translatesAutoresizingMaskIntoConstraints = false | ||
return scrollView | ||
}() | ||
|
||
private let contentView: UIView = { | ||
let view = UIView() | ||
view.translatesAutoresizingMaskIntoConstraints = false | ||
return view | ||
}() | ||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
setupUI() | ||
} | ||
|
||
private func setupUI() { | ||
view.addSubview(scrollView) | ||
scrollView.addSubview(contentView) | ||
|
||
NSLayoutConstraint.activate([ | ||
scrollView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor), | ||
scrollView.leadingAnchor.constraint(equalTo: view.leadingAnchor), | ||
scrollView.trailingAnchor.constraint(equalTo: view.trailingAnchor), | ||
scrollView.bottomAnchor.constraint(equalTo: view.bottomAnchor), | ||
|
||
contentView.topAnchor.constraint(equalTo: scrollView.topAnchor), | ||
contentView.leadingAnchor.constraint(equalTo: scrollView.leadingAnchor), | ||
contentView.trailingAnchor.constraint(equalTo: scrollView.trailingAnchor), | ||
contentView.bottomAnchor.constraint(equalTo: scrollView.bottomAnchor), | ||
contentView.widthAnchor.constraint(equalTo: scrollView.widthAnchor) | ||
]) | ||
|
||
addSkeletons() | ||
} | ||
|
||
private func addSkeletons() { | ||
let mainStackView = UIStackView() | ||
mainStackView.axis = .vertical | ||
mainStackView.alignment = .fill | ||
mainStackView.spacing = 40 | ||
mainStackView.translatesAutoresizingMaskIntoConstraints = false | ||
contentView.addSubview(mainStackView) | ||
|
||
NSLayoutConstraint.activate([ | ||
mainStackView.topAnchor.constraint(equalTo: contentView.topAnchor, constant: 16), | ||
mainStackView.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: 16), | ||
mainStackView.trailingAnchor.constraint(equalTo: contentView.trailingAnchor, constant: -16), | ||
mainStackView.bottomAnchor.constraint(equalTo: contentView.bottomAnchor, constant: -16) | ||
]) | ||
|
||
addSkeletonWithLabel(to: mainStackView, label: "Line", skeleton: Skeleton(type: .line(width: 360))) | ||
|
||
addSkeletonWithLabel(to: mainStackView, label: "Text", skeleton: Skeleton(type: .text())) | ||
|
||
addSkeletonWithLabel(to: mainStackView, label: "Circle", skeleton: Skeleton(type: .circle(size: 40))) | ||
|
||
addSkeletonWithLabel(to: mainStackView, label: "Row", skeleton: Skeleton(type: .row)) | ||
|
||
addSkeletonWithLabel(to: mainStackView, label: "Rectangle", skeleton: Skeleton(type: .rectangle(size: CGSize(width: 360, height: 180), isRounded: true))) | ||
|
||
contentView.heightAnchor.constraint(equalTo: mainStackView.heightAnchor, constant: 32).isActive = true | ||
} | ||
|
||
private func addSkeletonWithLabel(to mainStackView: UIStackView, label: String, skeleton: Skeleton) { | ||
let individualStackView = UIStackView() | ||
individualStackView.axis = .vertical | ||
individualStackView.alignment = .fill | ||
individualStackView.spacing = 16 | ||
individualStackView.translatesAutoresizingMaskIntoConstraints = false | ||
|
||
let titleLabel = UILabel() | ||
titleLabel.text = label | ||
titleLabel.font = UIFont.systemFont(ofSize: 16, weight: .bold) | ||
|
||
individualStackView.addArrangedSubview(titleLabel) | ||
individualStackView.addArrangedSubview(skeleton) | ||
|
||
mainStackView.addArrangedSubview(individualStackView) | ||
|
||
individualStackView.widthAnchor.constraint(equalTo: mainStackView.widthAnchor).isActive = true | ||
|
||
if case .text = skeleton.type { | ||
skeleton.widthAnchor.constraint(equalTo: individualStackView.widthAnchor).isActive = true | ||
} | ||
if case .row = skeleton.type { | ||
skeleton.widthAnchor.constraint(equalTo: individualStackView.widthAnchor).isActive = true | ||
} | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
MisticaCatalog/Source/Catalog/MisticaSwiftUI/Components/SkeletonsCatalogView.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// | ||
// SkeletonsCatalogView.swift | ||
// | ||
// Made with ❤️ by Novum | ||
// | ||
// Copyright © Telefonica. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import MisticaSwiftUI | ||
import SwiftUI | ||
|
||
struct SkeletonsCatalogView: View { | ||
@State var inverseStyle = false | ||
|
||
var body: some View { | ||
ScrollView(.vertical, showsIndicators: false) { | ||
VStack(alignment: .leading, spacing: 40.0) { | ||
skeletonSection(title: "Line", skeleton: Skeleton(type: .line(width: 360))) | ||
|
||
skeletonSection(title: "Text", skeleton: Skeleton(type: .text())) | ||
|
||
skeletonSection(title: "Circle", skeleton: Skeleton(type: .circle(size: .init(width: 40, height: 40)))) | ||
|
||
skeletonSection(title: "Row", skeleton: Skeleton(type: .row)) | ||
|
||
skeletonSection(title: "Rectangle", skeleton: Skeleton(type: .rectangle(width: 360, height: 180, isRounded: true))) | ||
|
||
Spacer() | ||
} | ||
.padding() | ||
.background(inverseStyle ? Color.brand : Color.background) | ||
} | ||
} | ||
|
||
private func skeletonSection(title: String, skeleton: Skeleton) -> some View { | ||
VStack(alignment: .leading, spacing: 16) { | ||
Text(title) | ||
.font(.system(size: 16, weight: .bold)) | ||
skeleton | ||
} | ||
} | ||
} | ||
|
||
#if DEBUG | ||
struct SkeletonCatalogView_Previews: PreviewProvider { | ||
static var previews: some View { | ||
NavigationView { | ||
SkeletonsCatalogView() | ||
} | ||
.misticaNavigationViewStyle() | ||
} | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.