Skip to content

Commit dd0ec01

Browse files
author
Anton Poltoratskyi
committed
Added example for alert with custom content view
1 parent bdb9454 commit dd0ec01

File tree

5 files changed

+120
-9
lines changed

5 files changed

+120
-9
lines changed

Example/NativeUIExample.xcodeproj/project.pbxproj

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
archiveVersion = 1;
44
classes = {
55
};
6-
objectVersion = 50;
6+
objectVersion = 51;
77
objects = {
88

99
/* Begin PBXBuildFile section */
@@ -12,6 +12,7 @@
1212
3AB073EB243A1D6E0092DF66 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 3AB073E9243A1D6E0092DF66 /* Main.storyboard */; };
1313
3AB073ED243A1D6F0092DF66 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 3AB073EC243A1D6F0092DF66 /* Assets.xcassets */; };
1414
3AB073F0243A1D6F0092DF66 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 3AB073EE243A1D6F0092DF66 /* LaunchScreen.storyboard */; };
15+
3AB073F8243A34630092DF66 /* CustomView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AB073F7243A34630092DF66 /* CustomView.swift */; };
1516
72F4F40FCECC507127BBF9EB /* Pods_NativeUIExample.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A6CA57C303D1BCA85495862B /* Pods_NativeUIExample.framework */; };
1617
/* End PBXBuildFile section */
1718

@@ -23,6 +24,7 @@
2324
3AB073EC243A1D6F0092DF66 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
2425
3AB073EF243A1D6F0092DF66 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
2526
3AB073F1243A1D6F0092DF66 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
27+
3AB073F7243A34630092DF66 /* CustomView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomView.swift; sourceTree = "<group>"; };
2628
A6CA57C303D1BCA85495862B /* Pods_NativeUIExample.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_NativeUIExample.framework; sourceTree = BUILT_PRODUCTS_DIR; };
2729
C3802E7F052BAEDAF473A7C9 /* Pods-NativeUIExample.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-NativeUIExample.release.xcconfig"; path = "Target Support Files/Pods-NativeUIExample/Pods-NativeUIExample.release.xcconfig"; sourceTree = "<group>"; };
2830
F9432C3CC8F8BA5AE31566B5 /* Pods-NativeUIExample.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-NativeUIExample.debug.xcconfig"; path = "Target Support Files/Pods-NativeUIExample/Pods-NativeUIExample.debug.xcconfig"; sourceTree = "<group>"; };
@@ -46,7 +48,6 @@
4648
F9432C3CC8F8BA5AE31566B5 /* Pods-NativeUIExample.debug.xcconfig */,
4749
C3802E7F052BAEDAF473A7C9 /* Pods-NativeUIExample.release.xcconfig */,
4850
);
49-
name = Pods;
5051
path = Pods;
5152
sourceTree = "<group>";
5253
};
@@ -72,6 +73,7 @@
7273
isa = PBXGroup;
7374
children = (
7475
3AB073E3243A1D6E0092DF66 /* AppDelegate.swift */,
76+
3AB073F7243A34630092DF66 /* CustomView.swift */,
7577
3AB073E7243A1D6E0092DF66 /* ViewController.swift */,
7678
3AB073E9243A1D6E0092DF66 /* Main.storyboard */,
7779
3AB073EC243A1D6F0092DF66 /* Assets.xcassets */,
@@ -204,6 +206,7 @@
204206
isa = PBXSourcesBuildPhase;
205207
buildActionMask = 2147483647;
206208
files = (
209+
3AB073F8243A34630092DF66 /* CustomView.swift in Sources */,
207210
3AB073E8243A1D6E0092DF66 /* ViewController.swift in Sources */,
208211
3AB073E4243A1D6E0092DF66 /* AppDelegate.swift in Sources */,
209212
);
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
//
2+
// CustomView.swift
3+
// NativeUIExample
4+
//
5+
// Created by Anton Poltoratskyi on 05.04.2020.
6+
// Copyright © 2020 Anton Poltoratskyi. All rights reserved.
7+
//
8+
9+
import UIKit
10+
11+
final class CustomView: UIView {
12+
13+
// MARK: - Subviews
14+
15+
private(set) lazy var imageView: UIImageView = {
16+
let imageView = UIImageView()
17+
imageView.translatesAutoresizingMaskIntoConstraints = false
18+
addSubview(imageView)
19+
return imageView
20+
}()
21+
22+
private lazy var stackView: UIStackView = {
23+
let stackView = UIStackView()
24+
stackView.translatesAutoresizingMaskIntoConstraints = false
25+
addSubview(stackView)
26+
return stackView
27+
}()
28+
29+
private(set) lazy var titleLabel: UILabel = {
30+
let label = UILabel()
31+
label.translatesAutoresizingMaskIntoConstraints = false
32+
stackView.addArrangedSubview(label)
33+
return label
34+
}()
35+
36+
private(set) lazy var subtitleLabel: UILabel = {
37+
let label = UILabel()
38+
label.translatesAutoresizingMaskIntoConstraints = false
39+
stackView.addArrangedSubview(label)
40+
return label
41+
}()
42+
43+
// MARK: - Init
44+
45+
override init(frame: CGRect) {
46+
super.init(frame: frame)
47+
initialize()
48+
}
49+
50+
required init?(coder: NSCoder) {
51+
super.init(coder: coder)
52+
initialize()
53+
}
54+
55+
// MARK: - Base Setup
56+
57+
private func initialize() {
58+
imageView.layer.cornerRadius = 16
59+
imageView.layer.masksToBounds = true
60+
61+
stackView.axis = .vertical
62+
stackView.spacing = 8
63+
64+
titleLabel.font = UIFont.systemFont(ofSize: 16, weight: .semibold)
65+
titleLabel.numberOfLines = 0
66+
titleLabel.textColor = UIColor.darkText
67+
68+
subtitleLabel.font = UIFont.systemFont(ofSize: 14, weight: .regular)
69+
subtitleLabel.numberOfLines = 0
70+
subtitleLabel.textColor = UIColor.darkGray
71+
72+
[titleLabel, subtitleLabel].forEach {
73+
$0.setContentCompressionResistancePriority(.required, for: .vertical)
74+
}
75+
76+
NSLayoutConstraint.activate([
77+
imageView.topAnchor.constraint(equalTo: topAnchor, constant: 8),
78+
imageView.widthAnchor.constraint(equalToConstant: 32),
79+
imageView.heightAnchor.constraint(equalToConstant: 32),
80+
imageView.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 8),
81+
82+
stackView.leadingAnchor.constraint(equalTo: imageView.trailingAnchor, constant: 16),
83+
stackView.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -16),
84+
stackView.topAnchor.constraint(equalTo: topAnchor, constant: 8),
85+
stackView.bottomAnchor.constraint(equalTo: bottomAnchor, constant: -8)
86+
])
87+
}
88+
}

Example/NativeUIExample/ViewController.swift

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,23 @@ final class ViewController: UIViewController {
3636
present(alert, animated: true)
3737

3838
case .custom:
39-
break
39+
let cancelAction = Alert.Action(title: "Cancel", style: .primary)
40+
let confirmAction = Alert.Action(title: "Confirm", style: .default)
41+
42+
let customView = CustomView()
43+
customView.translatesAutoresizingMaskIntoConstraints = false
44+
customView.imageView.backgroundColor = .orange
45+
customView.titleLabel.text = "Some text"
46+
customView.subtitleLabel.text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
47+
48+
let viewModel = Alert(
49+
title: "Your Title",
50+
message: nil,
51+
contentView: customView,
52+
actions: [cancelAction, confirmAction]
53+
)
54+
let alert = AlertViewController(viewModel: viewModel)
55+
present(alert, animated: true)
4056
}
4157
}
4258
}

Example/Podfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ platform :ios, '9.0'
33
target 'NativeUIExample' do
44
use_frameworks!
55

6-
pod 'NativeUI/Alert', '0.0.3'
6+
pod 'NativeUI', :path => '../'
77
end

Example/Podfile.lock

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
PODS:
2+
- NativeUI (0.0.3):
3+
- NativeUI/Core (= 0.0.3)
24
- NativeUI/Alert (0.0.3):
35
- NativeUI/Utils
6+
- NativeUI/Core (0.0.3):
7+
- NativeUI/Alert
48
- NativeUI/Utils (0.0.3)
59

610
DEPENDENCIES:
7-
- NativeUI/Alert (= 0.0.3)
11+
- NativeUI (from `../`)
812

9-
SPEC REPOS:
10-
trunk:
11-
- NativeUI
13+
EXTERNAL SOURCES:
14+
NativeUI:
15+
:path: "../"
1216

1317
SPEC CHECKSUMS:
1418
NativeUI: d89eeb004dd445bb67bef1579be654edffdd7a2e
1519

16-
PODFILE CHECKSUM: fbc3d68420579929484e8e2c80001a8e9fd72d90
20+
PODFILE CHECKSUM: bb46d7bf1ae3b119e00a9331a12cd0a4b5cac170
1721

1822
COCOAPODS: 1.9.1

0 commit comments

Comments
 (0)