Skip to content

Commit a0a958c

Browse files
committed
Added more to views.
1 parent bf31c7b commit a0a958c

File tree

12 files changed

+284
-13
lines changed

12 files changed

+284
-13
lines changed

Example App/NativeUIKit.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ let package = Package(
1414
)
1515
],
1616
dependencies: [
17-
Package.Dependency.package(
18-
name: "SparrowKit", url: "https://github.com/ivanvorobei/SparrowKit", .upToNextMajor(from: "3.2.2")
19-
)
17+
.package(name: "SparrowKit", url: "https://github.com/ivanvorobei/SparrowKit", .upToNextMajor(from: "3.2.2")),
18+
.package(name: "SPPerspective", url: "https://github.com/ivanvorobei/SPPerspective", .upToNextMajor(from: "1.3.5")),
2019
],
2120
targets: [
2221
.target(
2322
name: "NativeUIKit",
2423
dependencies: [
25-
.product(name: "SparrowKit", package: "SparrowKit")
24+
.product(name: "SparrowKit", package: "SparrowKit"),
25+
.product(name: "SPPerspective", package: "SPPerspective")
2626
],
2727
swiftSettings: [
2828
.define("NATIVEUIKIT_SPM")

Sources/NativeUIKit/Bars/Tool/NativeMimicrateNavigationToolBarView.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ open class NativeMimicrateToolBarView: NativeMimicrateBarView {
3838
open override func commonInit() {
3939
super.commonInit()
4040
insetsLayoutMarginsFromSafeArea = false
41+
layoutMargins.top = 16
4142
}
4243

4344
// MARK: - Layout
@@ -46,7 +47,9 @@ open class NativeMimicrateToolBarView: NativeMimicrateBarView {
4647
super.layoutSubviews()
4748
guard let superview = superview else { return }
4849
let contentWidth = min(440, superview.readableWidth)
49-
layoutMargins = .init(horizontal: (frame.width - contentWidth) / 2, vertical: 16)
50+
let horizontalMargin = (frame.width - contentWidth) / 2
51+
layoutMargins.left = horizontalMargin
52+
layoutMargins.right = horizontalMargin
5053
}
5154
}
5255
#endif
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
// The MIT License (MIT)
2+
// Copyright © 2021 Ivan Vorobei ([email protected])
3+
//
4+
// Permission is hereby granted, free of charge, to any person obtaining a copy
5+
// of this software and associated documentation files (the "Software"), to deal
6+
// in the Software without restriction, including without limitation the rights
7+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
// copies of the Software, and to permit persons to whom the Software is
9+
// furnished to do so, subject to the following conditions:
10+
//
11+
// The above copyright notice and this permission notice shall be included in all
12+
// copies or substantial portions of the Software.
13+
//
14+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20+
// SOFTWARE.
21+
22+
#if canImport(UIKit) && (os(iOS))
23+
import UIKit
24+
import SparrowKit
25+
26+
open class NativeLargeTitleCollectionViewCell: SPCollectionViewCell {
27+
28+
// MARK: - Views
29+
30+
public let titleLabel = SPLabel().do {
31+
$0.font = UIFont.preferredFont(forTextStyle: .title1, weight: .bold, addPoints: .zero)
32+
if #available(iOS 13.0, *) {
33+
$0.textColor = .label
34+
} else {
35+
$0.textColor = .black
36+
}
37+
}
38+
39+
// MARK: - Init
40+
41+
open override func commonInit() {
42+
super.commonInit()
43+
contentView.layoutMargins = .init(top: 32, left: .zero, bottom: 8, right: .zero)
44+
insetsLayoutMarginsFromSafeArea = false
45+
contentView.insetsLayoutMarginsFromSafeArea = false
46+
preservesSuperviewLayoutMargins = false
47+
contentView.preservesSuperviewLayoutMargins = false
48+
addSubview(titleLabel)
49+
}
50+
51+
// MARK: - Layout
52+
53+
open override func layoutSubviews() {
54+
super.layoutSubviews()
55+
var collectionView: UICollectionView?
56+
if let view = superview as? UICollectionView {
57+
collectionView = view
58+
}
59+
if let view = superview?.superview as? UICollectionView {
60+
collectionView = view
61+
}
62+
if let parent = collectionView {
63+
contentView.layoutMargins.left = parent.layoutMargins.left
64+
contentView.layoutMargins.right = parent.layoutMargins.right
65+
}
66+
titleLabel.layoutDynamicHeight(
67+
x: contentView.layoutMargins.left,
68+
y: contentView.layoutMargins.top,
69+
width: contentView.layoutWidth
70+
)
71+
}
72+
73+
open override func sizeThatFits(_ size: CGSize) -> CGSize {
74+
let superSize = super.sizeThatFits(size)
75+
layoutSubviews()
76+
return .init(width: superSize.width, height: titleLabel.frame.maxY + contentView.layoutMargins.bottom)
77+
}
78+
}
79+
#endif
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// The MIT License (MIT)
2+
// Copyright © 2021 Ivan Vorobei ([email protected])
3+
//
4+
// Permission is hereby granted, free of charge, to any person obtaining a copy
5+
// of this software and associated documentation files (the "Software"), to deal
6+
// in the Software without restriction, including without limitation the rights
7+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
// copies of the Software, and to permit persons to whom the Software is
9+
// furnished to do so, subject to the following conditions:
10+
//
11+
// The above copyright notice and this permission notice shall be included in all
12+
// copies or substantial portions of the Software.
13+
//
14+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20+
// SOFTWARE.
21+
22+
#if canImport(UIKit) && (os(iOS))
23+
import UIKit
24+
import SparrowKit
25+
import SPPerspective
26+
27+
open class NativePromoCollectionViewCell: SPCollectionViewCell {
28+
29+
// MARK: - Views
30+
31+
public let promoView = NativePromoView()
32+
33+
// MARK: - Init
34+
35+
open override func commonInit() {
36+
super.commonInit()
37+
layoutMargins = .zero
38+
contentView.addSubview(promoView)
39+
}
40+
41+
open override func prepareForReuse() {
42+
super.prepareForReuse()
43+
promoView.iconView.resetPerspective()
44+
}
45+
46+
// MARK: - Layout
47+
48+
open override func layoutSubviews() {
49+
super.layoutSubviews()
50+
promoView.layout(y: contentView.layoutMargins.top)
51+
}
52+
53+
open override func sizeThatFits(_ size: CGSize) -> CGSize {
54+
let superSize = super.sizeThatFits(size)
55+
layoutSubviews()
56+
return .init(width: superSize.width, height: promoView.frame.maxY + contentView.layoutMargins.bottom)
57+
}
58+
}
59+
#endif

Sources/NativeUIKit/Controllers/NativeScrollController.swift

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,16 +100,13 @@ open class NativeScrollController: SPScrollController {
100100
open override func viewDidLayoutSubviews() {
101101
super.viewDidLayoutSubviews()
102102
if let toolBarView = toolBarView {
103+
toolBarView.layoutMargins.bottom = systemSafeAreaInsets.bottom + 16
103104
toolBarView.setWidthAndFit(width: view.frame.width)
104-
let toolBarFrameFitHeight: CGFloat = toolBarView.frame.height
105-
toolBarView.frame.setHeight(toolBarFrameFitHeight + systemSafeAreaInsets.bottom)
106105
toolBarView.frame.setMaxY(view.frame.height)
107-
additionalSafeAreaInsets = .init(
108-
top: .zero,
109-
left: .zero,
110-
bottom: toolBarFrameFitHeight,
111-
right: .zero
112-
)
106+
let toolBarFrameFitHeight = toolBarView.frame.height - systemSafeAreaInsets.bottom
107+
if additionalSafeAreaInsets.bottom != toolBarFrameFitHeight {
108+
additionalSafeAreaInsets.bottom = toolBarFrameFitHeight
109+
}
113110
}
114111

115112
}

0 commit comments

Comments
 (0)