Skip to content
This repository was archived by the owner on Jun 17, 2023. It is now read-only.

Commit ea38d51

Browse files
committed
Add new buttons to code preview, add comments to the generated code
1 parent 4d74e59 commit ea38d51

File tree

11 files changed

+173
-48
lines changed

11 files changed

+173
-48
lines changed

Samples/PagingLayoutSamples.xcodeproj/project.pbxproj

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
2977657E2474531D00835DBD /* LayoutDesignerOptionCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 2977657D2474531D00835DBD /* LayoutDesignerOptionCell.xib */; };
2020
29776580247454BC00835DBD /* LayoutDesignerOptionCellViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2977657F247454BC00835DBD /* LayoutDesignerOptionCellViewModel.swift */; };
2121
2993722324A79A9C0026D52F /* ShapeLayout+ScaleOptions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2993722224A79A9C0026D52F /* ShapeLayout+ScaleOptions.swift */; };
22+
29A2D3AA24B72895005A0F6B /* LayoutDesignerCodePreviewViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 29A2D3A924B72895005A0F6B /* LayoutDesignerCodePreviewViewController.xib */; };
2223
29B5A72024A7B02900C9843E /* ShapeLayout+StackOptions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29B5A71F24A7B02900C9843E /* ShapeLayout+StackOptions.swift */; };
2324
29B5A72224A7B06300C9843E /* ShapeLayout+SnapshotOptions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29B5A72124A7B06300C9843E /* ShapeLayout+SnapshotOptions.swift */; };
2425
29B5A72424A8CC4B00C9843E /* CGFloat+String.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29B5A72324A8CC4B00C9843E /* CGFloat+String.swift */; };
@@ -122,6 +123,7 @@
122123
2977657D2474531D00835DBD /* LayoutDesignerOptionCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = LayoutDesignerOptionCell.xib; sourceTree = "<group>"; };
123124
2977657F247454BC00835DBD /* LayoutDesignerOptionCellViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LayoutDesignerOptionCellViewModel.swift; sourceTree = "<group>"; };
124125
2993722224A79A9C0026D52F /* ShapeLayout+ScaleOptions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ShapeLayout+ScaleOptions.swift"; sourceTree = "<group>"; };
126+
29A2D3A924B72895005A0F6B /* LayoutDesignerCodePreviewViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = LayoutDesignerCodePreviewViewController.xib; sourceTree = "<group>"; };
125127
29B5A71F24A7B02900C9843E /* ShapeLayout+StackOptions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ShapeLayout+StackOptions.swift"; sourceTree = "<group>"; };
126128
29B5A72124A7B06300C9843E /* ShapeLayout+SnapshotOptions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ShapeLayout+SnapshotOptions.swift"; sourceTree = "<group>"; };
127129
29B5A72324A8CC4B00C9843E /* CGFloat+String.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CGFloat+String.swift"; sourceTree = "<group>"; };
@@ -152,7 +154,7 @@
152154
AB1BBA9923CA5178004E5C3B /* CardCollectionViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CardCollectionViewCell.swift; sourceTree = "<group>"; };
153155
AB1BBA9A23CA5179004E5C3B /* CardCollectionViewCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = CardCollectionViewCell.xib; sourceTree = "<group>"; };
154156
AB1E03AE23B25CE70087F904 /* PageControlView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PageControlView.swift; sourceTree = "<group>"; };
155-
AB500A2F23B104E20056BE37 /* Paging Layout.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Paging Layout.app"; sourceTree = BUILT_PRODUCTS_DIR; };
157+
AB500A2F23B104E20056BE37 /* Layout Designer.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Layout Designer.app"; sourceTree = BUILT_PRODUCTS_DIR; };
156158
AB500A3223B104E20056BE37 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
157159
AB500A3B23B104E60056BE37 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
158160
AB500A3E23B104E60056BE37 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
@@ -295,6 +297,7 @@
295297
isa = PBXGroup;
296298
children = (
297299
29FF296124A6321100C83DF9 /* LayoutDesignerCodePreviewViewController.swift */,
300+
29A2D3A924B72895005A0F6B /* LayoutDesignerCodePreviewViewController.xib */,
298301
29FF296324A6321B00C83DF9 /* LayoutDesignerCodePreviewViewModel.swift */,
299302
);
300303
path = Code;
@@ -355,7 +358,7 @@
355358
AB500A3023B104E20056BE37 /* Products */ = {
356359
isa = PBXGroup;
357360
children = (
358-
AB500A2F23B104E20056BE37 /* Paging Layout.app */,
361+
AB500A2F23B104E20056BE37 /* Layout Designer.app */,
359362
292489B72461F07D00A316B0 /* AppKitGlue.bundle */,
360363
);
361364
name = Products;
@@ -539,7 +542,7 @@
539542
);
540543
name = PagingLayoutSamples;
541544
productName = CollectionViewPagingLayout;
542-
productReference = AB500A2F23B104E20056BE37 /* Paging Layout.app */;
545+
productReference = AB500A2F23B104E20056BE37 /* Layout Designer.app */;
543546
productType = "com.apple.product-type.application";
544547
};
545548
/* End PBXNativeTarget section */
@@ -607,6 +610,7 @@
607610
AB1BBA9D23CA5179004E5C3B /* CardCollectionViewCell.xib in Resources */,
608611
AB7C1E0823B4E2C0006441DE /* MainViewController.xib in Resources */,
609612
ABA1A72E23B42247006A46A3 /* PriceTagView.xib in Resources */,
613+
29A2D3AA24B72895005A0F6B /* LayoutDesignerCodePreviewViewController.xib in Resources */,
610614
ABA1A73323B422B9006A46A3 /* QuantityControllerView.xib in Resources */,
611615
);
612616
runOnlyForDeploymentPostprocessing = 0;
@@ -946,7 +950,7 @@
946950
"@executable_path/Frameworks",
947951
);
948952
PRODUCT_BUNDLE_IDENTIFIER = app.amir.paginglayout;
949-
PRODUCT_NAME = "Paging Layout";
953+
PRODUCT_NAME = "Layout Designer";
950954
SUPPORTS_MACCATALYST = YES;
951955
SWIFT_OBJC_BRIDGING_HEADER = "PagingLayoutSamples/PagingLayoutSamples-Bridging-Header.h";
952956
SWIFT_VERSION = 5.0;
@@ -969,7 +973,7 @@
969973
"@executable_path/Frameworks",
970974
);
971975
PRODUCT_BUNDLE_IDENTIFIER = app.amir.paginglayout;
972-
PRODUCT_NAME = "Paging Layout";
976+
PRODUCT_NAME = "Layout Designer";
973977
SUPPORTS_MACCATALYST = YES;
974978
SWIFT_OBJC_BRIDGING_HEADER = "PagingLayoutSamples/PagingLayoutSamples-Bridging-Header.h";
975979
SWIFT_VERSION = 5.0;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"images" : [
3+
{
4+
"filename" : "downloadButton.pdf",
5+
"idiom" : "universal"
6+
}
7+
],
8+
"info" : {
9+
"author" : "xcode",
10+
"version" : 1
11+
}
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"images" : [
3+
{
4+
"filename" : "helpButton.pdf",
5+
"idiom" : "universal"
6+
}
7+
],
8+
"info" : {
9+
"author" : "xcode",
10+
"version" : 1
11+
}
12+
}

Samples/PagingLayoutSamples/Modules/LayoutDesigner/Code/LayoutDesignerCodePreviewViewController.swift

Lines changed: 27 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,20 @@ import Foundation
1010
import UIKit
1111
import Splash
1212

13-
class LayoutDesignerCodePreviewViewController: UIViewController {
13+
class LayoutDesignerCodePreviewViewController: UIViewController, NibBased, ViewModelBased {
1414

1515
// MARK: Properties
1616

17-
var viewModel: LayoutDesignerCodePreviewViewModel? {
17+
var viewModel: LayoutDesignerCodePreviewViewModel! {
1818
didSet {
1919
refreshViews()
2020
}
2121
}
22-
private weak var codeTextView: UITextView!
23-
private weak var copyButton: UIButton!
24-
private weak var codeModeSegmentedControl: UISegmentedControl!
22+
@IBOutlet private weak var codeTextView: UITextView!
23+
@IBOutlet private weak var copyButton: UIButton!
24+
@IBOutlet private weak var saveButton: UIButton!
25+
@IBOutlet private weak var helpButton: UIButton!
26+
@IBOutlet private weak var codeModeSegmentedControl: UISegmentedControl!
2527

2628

2729
// MARK: UIViewController
@@ -34,12 +36,19 @@ class LayoutDesignerCodePreviewViewController: UIViewController {
3436

3537
// MARK: Listener
3638

37-
@objc private func copyButtonTouched() {
39+
@IBAction private func copyButtonTouched() {
3840
let pasteBoard = UIPasteboard.general
3941
pasteBoard.string = codeTextView.text
4042
}
4143

42-
@objc private func codeTypeChanged() {
44+
@IBAction private func saveButtonTouched() {
45+
refreshViews()
46+
}
47+
48+
@IBAction private func onHelpButtonTouched() {
49+
}
50+
51+
@IBAction private func codeTypeChanged() {
4352
refreshViews()
4453
}
4554

@@ -48,53 +57,33 @@ class LayoutDesignerCodePreviewViewController: UIViewController {
4857

4958
private func configureViews() {
5059
configureTextView()
51-
configureCopyButton()
60+
configureButtons()
5261
configureCodeTypeSegmentedControl()
5362
}
5463

55-
private func configureCopyButton() {
56-
let button = UIButton()
57-
button.setImage(UIImage(named: "copyButton"), for: .normal)
58-
button.addTarget(self, action: #selector(copyButtonTouched), for: .touchUpInside)
59-
button.translatesAutoresizingMaskIntoConstraints = false
60-
view.addSubview(button)
61-
copyButton = button
62-
button.topAnchor.constraint(equalTo: view.topAnchor, constant: 40).isActive = true
63-
button.rightAnchor.constraint(equalTo: view.rightAnchor, constant: -25).isActive = true
64-
button.setContentCompressionResistancePriority(.required, for: .vertical)
64+
private func configureButtons() {
65+
[saveButton, copyButton, helpButton].forEach {
66+
$0?.layer.cornerRadius = 8
67+
}
6568
}
6669

6770
private func configureCodeTypeSegmentedControl() {
68-
let segmentedControl = UISegmentedControl()
69-
segmentedControl.insertSegment(withTitle: "ViewController", at: 0, animated: false)
70-
segmentedControl.insertSegment(withTitle: "Options variable", at: 0, animated: false)
71-
segmentedControl.translatesAutoresizingMaskIntoConstraints = false
72-
view.addSubview(segmentedControl)
73-
codeModeSegmentedControl = segmentedControl
74-
segmentedControl.topAnchor.constraint(equalTo: copyButton.topAnchor).isActive = true
75-
segmentedControl.rightAnchor.constraint(equalTo: copyButton.leftAnchor, constant: -10).isActive = true
76-
segmentedControl.leftAnchor.constraint(greaterThanOrEqualTo: view.leftAnchor, constant: 20).isActive = true
77-
segmentedControl.heightAnchor.constraint(equalTo: copyButton.heightAnchor).isActive = true
78-
segmentedControl.backgroundColor = UIColor.black.withAlphaComponent(0.4)
79-
segmentedControl.selectedSegmentTintColor = UIColor.white.withAlphaComponent(0.4)
80-
segmentedControl.setTitleTextAttributes([.foregroundColor: UIColor.white], for: .normal)
81-
segmentedControl.setTitleTextAttributes([.foregroundColor: UIColor.black.withAlphaComponent(0.6)], for: .selected)
82-
segmentedControl.selectedSegmentIndex = 0
83-
segmentedControl.addTarget(self, action: #selector(codeTypeChanged), for: .valueChanged)
71+
codeModeSegmentedControl.backgroundColor = UIColor.black.withAlphaComponent(0.4)
72+
codeModeSegmentedControl.selectedSegmentTintColor = UIColor.white.withAlphaComponent(0.4)
73+
codeModeSegmentedControl.setTitleTextAttributes([.foregroundColor: UIColor.white], for: .normal)
74+
codeModeSegmentedControl.setTitleTextAttributes([.foregroundColor: UIColor.black.withAlphaComponent(0.6)], for: .selected)
75+
codeModeSegmentedControl.selectedSegmentIndex = 0
8476

8577
}
8678

8779
private func configureTextView() {
88-
let codeTextView = UITextView()
8980
codeTextView.backgroundColor = .clear
9081
codeTextView.isEditable = false
91-
view.fill(with: codeTextView, edges: .init(top: 100, left: 20, bottom: -20, right: -20))
92-
self.codeTextView = codeTextView
9382
}
9483

9584
private func refreshViews() {
9685
codeTextView.attributedText = viewModel?.getHighlightedText(
97-
addViewControllerInCode: codeModeSegmentedControl.selectedSegmentIndex != 0
86+
addViewControllerInCode: codeModeSegmentedControl.selectedSegmentIndex == 0
9887
)
9988
}
10089

0 commit comments

Comments
 (0)