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

Commit 30916ff

Browse files
author
Amir Khorsandi
committed
Add sections, fix cell not keeping changed value
1 parent 8845958 commit 30916ff

File tree

6 files changed

+279
-39
lines changed

6 files changed

+279
-39
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"colors" : [
3+
{
4+
"color" : {
5+
"color-space" : "srgb",
6+
"components" : {
7+
"alpha" : "1.000",
8+
"blue" : "0xD7",
9+
"green" : "0x45",
10+
"red" : "0x29"
11+
}
12+
},
13+
"idiom" : "universal"
14+
}
15+
],
16+
"info" : {
17+
"author" : "xcode",
18+
"version" : 1
19+
}
20+
}

Samples/PagingLayoutSamples/Modules/LayoutDesigner/LayoutDesignerViewController.xib

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="16096" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="16097" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
33
<device id="retina6_1" orientation="portrait" appearance="light"/>
44
<dependencies>
5-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="16086"/>
5+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="16087"/>
6+
<capability name="Named colors" minToolsVersion="9.0"/>
67
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
78
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
89
</dependencies>
@@ -220,28 +221,20 @@
220221
</view>
221222
</subviews>
222223
</stackView>
223-
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Options" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="JIJ-FO-Jan">
224-
<rect key="frame" x="24" y="188" width="115.5" height="39.5"/>
225-
<fontDescription key="fontDescription" type="system" weight="medium" pointSize="33"/>
226-
<color key="textColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
227-
<nil key="highlightedColor"/>
228-
</label>
229224
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" style="plain" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="28" sectionFooterHeight="28" translatesAutoresizingMaskIntoConstraints="NO" id="dmm-bK-wwh" customClass="LayoutDesignerOptionsTableView" customModule="Paging_Layout" customModuleProvider="target">
230-
<rect key="frame" x="0.0" y="252.5" width="494" height="505.5"/>
225+
<rect key="frame" x="0.0" y="188" width="494" height="570"/>
231226
<color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
232227
</tableView>
233228
</subviews>
234-
<color key="backgroundColor" red="0.16006854179999999" green="0.27162900569999998" blue="0.84318453069999999" alpha="1" colorSpace="custom" customColorSpace="displayP3"/>
229+
<color key="backgroundColor" name="DesignerBackground"/>
235230
<constraints>
236-
<constraint firstItem="dmm-bK-wwh" firstAttribute="top" secondItem="JIJ-FO-Jan" secondAttribute="bottom" constant="25" id="BCl-LA-ovu"/>
237231
<constraint firstItem="NyD-R7-l0J" firstAttribute="leading" secondItem="nl2-ey-EcQ" secondAttribute="leading" constant="22" id="EBD-hI-uBV"/>
238232
<constraint firstItem="dmm-bK-wwh" firstAttribute="leading" secondItem="nl2-ey-EcQ" secondAttribute="leading" id="Eko-sH-H04"/>
239233
<constraint firstAttribute="trailing" secondItem="NyD-R7-l0J" secondAttribute="trailing" constant="22" id="FxT-KW-h7C"/>
240234
<constraint firstAttribute="trailing" secondItem="dmm-bK-wwh" secondAttribute="trailing" id="G13-Js-ic1"/>
235+
<constraint firstItem="dmm-bK-wwh" firstAttribute="top" secondItem="NyD-R7-l0J" secondAttribute="bottom" constant="37" id="Jyu-fX-wo8"/>
241236
<constraint firstAttribute="bottom" secondItem="dmm-bK-wwh" secondAttribute="bottom" id="WEg-wb-pcQ"/>
242237
<constraint firstAttribute="width" relation="lessThanOrEqual" constant="500" id="qxy-3u-1M3"/>
243-
<constraint firstItem="JIJ-FO-Jan" firstAttribute="top" secondItem="NyD-R7-l0J" secondAttribute="bottom" constant="37" id="rMR-Ji-0gf"/>
244-
<constraint firstItem="JIJ-FO-Jan" firstAttribute="leading" secondItem="nl2-ey-EcQ" secondAttribute="leading" constant="24" id="rQF-HR-vOj"/>
245238
</constraints>
246239
</view>
247240
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="h51-4z-wO0" userLabel="previewContainerView">
@@ -280,5 +273,8 @@
280273
<image name="scaleWhite" width="48" height="43"/>
281274
<image name="snapshotWhite" width="44" height="51"/>
282275
<image name="stackWhite" width="41" height="43"/>
276+
<namedColor name="DesignerBackground">
277+
<color red="0.16078431372549021" green="0.27058823529411763" blue="0.84313725490196079" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
278+
</namedColor>
283279
</resources>
284280
</document>

Samples/PagingLayoutSamples/Modules/LayoutDesigner/LayoutDesignerViewModel.swift

Lines changed: 154 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class LayoutDesignerViewModel {
2424
var shapesViewModel: ShapesViewModel {
2525
ShapesViewModel(layouts: layouts, showBackButton: false)
2626
}
27-
private(set) var optionViewModels: [LayoutDesignerOptionCellViewModel] = []
27+
private(set) var optionViewModels: [LayoutDesignerOptionSectionViewModel] = []
2828
private let codeGenerator = OptionsCodeGenerator()
2929

3030

@@ -52,7 +52,7 @@ class LayoutDesignerViewModel {
5252
self?.update(options: &options, closure: $0)
5353
}
5454

55-
optionViewModels = [
55+
let generalOptions: [LayoutDesignerOptionViewModel] = [
5656
.init(title: "Min scale", kind: .singleSlider(current: options.minScale, range: 0...2) { n in
5757
update { $0.minScale = n! }
5858
}),
@@ -82,15 +82,158 @@ class LayoutDesignerViewModel {
8282
}),
8383
.init(title: "Translation curve", kind: .segmented(options: TransformCurve.all.map(\.name), current: options.translationCurve.name) { n in
8484
update { $0.translationCurve = .by(name: n)! }
85+
}),
86+
.init(title: "Shadow enabled", kind: .toggleSwitch(current: options.shadowEnabled) { n in
87+
update { $0.shadowEnabled = n }
88+
}),
89+
.init(title: "Shadow opacity", kind: .singleSlider(current: CGFloat(options.shadowOpacity)) { n in
90+
update { $0.shadowOpacity = Float(n!) }
91+
}),
92+
.init(title: "Shadow opacity min", kind: .singleSlider(current: CGFloat(options.shadowOpacityMin)) { n in
93+
update { $0.shadowOpacityMin = Float(n!) }
94+
}),
95+
.init(title: "Shadow opacity max", kind: .singleSlider(current: CGFloat(options.shadowOpacityMax)) { n in
96+
update { $0.shadowOpacityMax = Float(n!) }
97+
}),
98+
.init(title: "Shadow radius max", kind: .singleSlider(current: options.shadowRadiusMax, range: 0...15) { n in
99+
update { $0.shadowRadiusMax = n! }
100+
}),
101+
.init(title: "Shadow radius min", kind: .singleSlider(current: options.shadowRadiusMin, range: 0...15) { n in
102+
update { $0.shadowRadiusMin = n! }
103+
}),
104+
.init(title: "Shadow offset min", kind: .doubleSlider(current: options.shadowOffsetMin.pair, range: -7...7) { n in
105+
update { $0.shadowOffsetMin = .by(pair: n!) }
106+
}),
107+
.init(title: "Shadow offset max", kind: .doubleSlider(current: options.shadowOffsetMax.pair, range: -7...7) { n in
108+
update { $0.shadowOffsetMax = .by(pair: n!) }
109+
}),
110+
.init(title: "Blur effect enabled", kind: .toggleSwitch(current: options.blurEffectEnabled) { n in
111+
update { $0.blurEffectEnabled = n }
112+
}),
113+
.init(title: "Blur effect radius ratio", kind: .singleSlider(current: options.blurEffectRadiusRatio) { n in
114+
update { $0.blurEffectRadiusRatio = n! }
115+
}),
116+
.init(title: "Blur effect style", kind: .segmented(options: UIBlurEffect.Style.all.map(\.name), current: options.blurEffectStyle.name) { n in
117+
update { $0.blurEffectStyle = .by(name: n)! }
118+
})
119+
]
120+
121+
let originalRotation3dOptions = options.rotation3d ?? ScaleTransformViewOptions.Rotation3dOptions(
122+
angle: .pi / 3,
123+
minAngle: 0,
124+
maxAngle: .pi,
125+
x: 0,
126+
y: 1,
127+
z: 0,
128+
m34: -0.000_1
129+
)
130+
131+
let rotation3dOptions: [LayoutDesignerOptionViewModel] = [
132+
.init(title: "Enabled", kind: .toggleSwitch(current: options.rotation3d != nil) { n in
133+
update { $0.rotation3d = !n ? nil : originalRotation3dOptions }
134+
}),
135+
.init(title: "Angle", kind: .singleSlider(current: options.rotation3d?.angle, range: -.pi...CGFloat.pi) { n in
136+
update { $0.rotation3d?.angle = n! }
137+
}),
138+
.init(title: "Min angle", kind: .singleSlider(current: options.rotation3d?.minAngle, range: -.pi...CGFloat.pi) { n in
139+
update { $0.rotation3d?.minAngle = n! }
140+
}),
141+
.init(title: "Max angle", kind: .singleSlider(current: options.rotation3d?.maxAngle, range: -.pi...CGFloat.pi) { n in
142+
update { $0.rotation3d?.maxAngle = n! }
143+
}),
144+
.init(title: "X", kind: .singleSlider(current: options.rotation3d?.x, range: -1...1) { n in
145+
update { $0.rotation3d?.x = n! }
146+
}),
147+
.init(title: "Y", kind: .singleSlider(current: options.rotation3d?.y, range: -1...1) { n in
148+
update { $0.rotation3d?.y = n! }
149+
}),
150+
.init(title: "Z", kind: .singleSlider(current: options.rotation3d?.z, range: -1...1) { n in
151+
update { $0.rotation3d?.z = n! }
152+
}),
153+
.init(title: "m34", kind: .singleSlider(current: options.rotation3d.map { $0.m34 * 1_000 }, range: -2...2) { n in
154+
update { $0.rotation3d?.m34 = n! / 1_000 }
155+
})
156+
]
157+
158+
let originalTranslation3dOptions = options.translation3d ?? ScaleTransformViewOptions.Translation3dOptions(
159+
translateRatios: (30, 0, -375 * 0.42),
160+
minTranslates: (-30, 0, -1_000),
161+
maxTranslates: (30, 0, 0)
162+
)
163+
164+
let translation3dOptions: [LayoutDesignerOptionViewModel] = [
165+
.init(title: "Enabled", kind: .toggleSwitch(current: options.translation3d != nil) { n in
166+
update { $0.translation3d = !n ? nil : originalTranslation3dOptions }
167+
}),
168+
.init(title: "X ratio", kind: .singleSlider(current: options.translation3d?.translateRatios.0, range: -500...500) { n in
169+
update {
170+
guard let current = $0.translation3d?.translateRatios else { return }
171+
$0.translation3d?.translateRatios = (n!, current.1, current.2)
172+
}
173+
}),
174+
.init(title: "Y ratio", kind: .singleSlider(current: options.translation3d?.translateRatios.1, range: -500...500) { n in
175+
update {
176+
guard let current = $0.translation3d?.translateRatios else { return }
177+
$0.translation3d?.translateRatios = (current.0, n!, current.2)
178+
}
179+
}),
180+
.init(title: "Z ratio", kind: .singleSlider(current: options.translation3d?.translateRatios.2, range: -500...500) { n in
181+
update {
182+
guard let current = $0.translation3d?.translateRatios else { return }
183+
$0.translation3d?.translateRatios = (current.0, current.1, n!)
184+
}
185+
}),
186+
.init(title: "X min", kind: .singleSlider(current: options.translation3d?.minTranslates.0, range: -2_000...2_000) { n in
187+
update {
188+
guard let current = $0.translation3d?.minTranslates else { return }
189+
$0.translation3d?.minTranslates = (n!, current.1, current.2)
190+
}
191+
}),
192+
.init(title: "X max", kind: .singleSlider(current: options.translation3d?.maxTranslates.0, range: -2_000...2_000) { n in
193+
update {
194+
guard let current = $0.translation3d?.maxTranslates else { return }
195+
$0.translation3d?.maxTranslates = (n!, current.1, current.2)
196+
}
197+
}),
198+
.init(title: "Y min", kind: .singleSlider(current: options.translation3d?.minTranslates.1, range: -2_000...2_000) { n in
199+
update {
200+
guard let current = $0.translation3d?.minTranslates else { return }
201+
$0.translation3d?.minTranslates = (current.0, n!, current.2)
202+
}
203+
}),
204+
.init(title: "Y max", kind: .singleSlider(current: options.translation3d?.maxTranslates.1, range: -2_000...2_000) { n in
205+
update {
206+
guard let current = $0.translation3d?.maxTranslates else { return }
207+
$0.translation3d?.maxTranslates = (current.0, n!, current.2)
208+
}
209+
}),
210+
.init(title: "Z min", kind: .singleSlider(current: options.translation3d?.minTranslates.2, range: -2_000...2_000) { n in
211+
update {
212+
guard let current = $0.translation3d?.minTranslates else { return }
213+
$0.translation3d?.minTranslates = (current.0, current.1, n!)
214+
}
215+
}),
216+
.init(title: "Z max", kind: .singleSlider(current: options.translation3d?.maxTranslates.2, range: -2_000...2_000) { n in
217+
update {
218+
guard let current = $0.translation3d?.maxTranslates else { return }
219+
$0.translation3d?.maxTranslates = (current.0, current.1, n!)
220+
}
85221
})
86222
]
223+
224+
225+
optionViewModels = [
226+
.init(title: "Options", items: generalOptions),
227+
.init(title: "Rotation 3D options", items: rotation3dOptions),
228+
.init(title: "Translation 3D options", items: translation3dOptions)
229+
]
87230
} else if var options = selectedLayout.stackOptions {
88231
updateCodePreview(options: options)
89232
let update: ((inout StackTransformViewOptions) -> Void) -> Void = { [weak self] in
90233
self?.update(options: &options, closure: $0)
91234
}
92235

93-
optionViewModels = [
236+
let options: [LayoutDesignerOptionViewModel] = [
94237
.init(title: "Scale factor", kind: .singleSlider(current: options.scaleFactor, range: -1...1) { n in
95238
update { $0.scaleFactor = n! }
96239
}),
@@ -155,12 +298,16 @@ class LayoutDesignerViewModel {
155298
update { $0.blurEffectStyle = .by(name: n)! }
156299
})
157300
]
301+
302+
optionViewModels = [
303+
.init(title: "Options", items: options)
304+
]
158305
} else if var options = selectedLayout.snapshotOptions {
159306
updateCodePreview(options: options)
160307
let update: ((inout SnapshotTransformViewOptions) -> Void) -> Void = { [weak self] in
161308
self?.update(options: &options, closure: $0)
162309
}
163-
optionViewModels = [
310+
let options: [LayoutDesignerOptionViewModel] = [
164311
.init(title: "Piece size ratio", kind: .doubleSlider(current: options.pieceSizeRatio.pair, range: 0.01...1) { n in
165312
update { $0.pieceSizeRatio = .by(pair: n!) }
166313
}),
@@ -177,6 +324,9 @@ class LayoutDesignerViewModel {
177324
update { $0.containerMaxTranslationRatio = n.map { .by(pair: $0) } }
178325
})
179326
]
327+
optionViewModels = [
328+
.init(title: "Options", items: options)
329+
]
180330
}
181331
}
182332

Samples/PagingLayoutSamples/Modules/LayoutDesigner/Options/LayoutDesignerOptionsTableView.swift

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class LayoutDesignerOptionsTableView: UITableView {
1212

1313
// MARK: Properties
1414

15-
var optionViewModels: [LayoutDesignerOptionCellViewModel] = [] {
15+
var optionViewModels: [LayoutDesignerOptionSectionViewModel] = [] {
1616
didSet {
1717
reloadData()
1818
}
@@ -31,24 +31,44 @@ class LayoutDesignerOptionsTableView: UITableView {
3131

3232
private func configure() {
3333
dataSource = self
34+
delegate = self
3435
register(LayoutDesignerOptionCell.self)
3536
backgroundColor = .clear
3637
separatorStyle = .none
3738
allowsSelection = false
39+
sectionHeaderHeight = 60
3840
}
3941

4042
}
4143

4244

4345
extension LayoutDesignerOptionsTableView: UITableViewDataSource {
4446

45-
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
47+
func numberOfSections(in tableView: UITableView) -> Int {
4648
optionViewModels.count
4749
}
4850

51+
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
52+
optionViewModels[section].items.count
53+
}
54+
4955
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
5056
let cell: LayoutDesignerOptionCell = tableView.dequeueReusableCell(for: indexPath)
51-
cell.viewModel = optionViewModels[indexPath.row]
57+
cell.viewModel = optionViewModels[indexPath.section].items[indexPath.row]
5258
return cell
5359
}
5460
}
61+
62+
extension LayoutDesignerOptionsTableView: UITableViewDelegate {
63+
64+
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
65+
let header = UIView()
66+
let label = UILabel()
67+
label.textColor = .white
68+
label.font = .systemFont(ofSize: 33, weight: .medium)
69+
label.text = optionViewModels[section].title
70+
header.fill(with: label, edges: .init(top: 10, left: 24, bottom: -10, right: -24))
71+
header.backgroundColor = #colorLiteral(red: 0.1607843137, green: 0.2705882353, blue: 0.8431372549, alpha: 1)
72+
return header
73+
}
74+
}

0 commit comments

Comments
 (0)