Skip to content

Commit 0c4346b

Browse files
committed
Added mimicrated tool bars.
1 parent 2c6c271 commit 0c4346b

15 files changed

+357
-85
lines changed

Example App/NativeUIKit.xcodeproj/xcshareddata/xcschemes/watchOS Example.xcscheme

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -54,46 +54,33 @@
5454
debugDocumentVersioning = "YES"
5555
debugServiceExtension = "internal"
5656
allowLocationSimulation = "YES">
57-
<RemoteRunnable
58-
runnableDebuggingMode = "2"
59-
BundleIdentifier = "com.apple.Carousel"
60-
RemotePath = "/(null)">
57+
<BuildableProductRunnable
58+
runnableDebuggingMode = "0">
6159
<BuildableReference
6260
BuildableIdentifier = "primary"
6361
BlueprintIdentifier = "F4C33E2F26C932C8001A28B1"
6462
BuildableName = "watchOS Example.app"
6563
BlueprintName = "watchOS Example"
6664
ReferencedContainer = "container:NativeUIKit.xcodeproj">
6765
</BuildableReference>
68-
</RemoteRunnable>
66+
</BuildableProductRunnable>
6967
</LaunchAction>
7068
<ProfileAction
7169
buildConfiguration = "Release"
7270
shouldUseLaunchSchemeArgsEnv = "YES"
7371
savedToolIdentifier = ""
7472
useCustomWorkingDirectory = "NO"
7573
debugDocumentVersioning = "YES">
76-
<RemoteRunnable
77-
runnableDebuggingMode = "2"
78-
BundleIdentifier = "com.apple.Carousel"
79-
RemotePath = "/(null)">
74+
<BuildableProductRunnable
75+
runnableDebuggingMode = "0">
8076
<BuildableReference
8177
BuildableIdentifier = "primary"
8278
BlueprintIdentifier = "F4C33E2F26C932C8001A28B1"
8379
BuildableName = "watchOS Example.app"
8480
BlueprintName = "watchOS Example"
8581
ReferencedContainer = "container:NativeUIKit.xcodeproj">
8682
</BuildableReference>
87-
</RemoteRunnable>
88-
<MacroExpansion>
89-
<BuildableReference
90-
BuildableIdentifier = "primary"
91-
BlueprintIdentifier = "F4C33E2F26C932C8001A28B1"
92-
BuildableName = "watchOS Example.app"
93-
BlueprintName = "watchOS Example"
94-
ReferencedContainer = "container:NativeUIKit.xcodeproj">
95-
</BuildableReference>
96-
</MacroExpansion>
83+
</BuildableProductRunnable>
9784
</ProfileAction>
9885
<AnalyzeAction
9986
buildConfiguration = "Debug">

Example App/iOS Example/Scenes/RootController.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,17 @@ class RootController: SPController {
3434
largeButton.applyDefaultAppearance(with: .init(content: .custom(.white), background: .tint))
3535
largeButton.setTitle("Title")
3636

37+
largeButton.addAction(.init(handler: { _ in
38+
let controller = Native2HeaderController(image: nil, title: "Title", subtitle: "Subtitle")
39+
let toolBarView = NativeSkipableLargeActionToolBarView()
40+
toolBarView.actionButton.setTitle("Action Button")
41+
toolBarView.skipButton.setTitle("Skip")
42+
controller.toolBarView = toolBarView
43+
let navController = controller.wrapToNavigationController(prefersLargeTitles: false)
44+
controller.navigationItem.title = "Navigation Item"
45+
self.present(navController)
46+
}), for: .touchUpInside)
47+
3748
}
3849

3950
override func viewDidLayoutSubviews() {
@@ -42,5 +53,14 @@ class RootController: SPController {
4253
largeButton.frame.setWidth(view.layoutWidth)
4354
largeButton.setXCenter()
4455
largeButton.frame.origin.y = 200
56+
57+
}
58+
}
59+
60+
class Native2HeaderController: NativeHeaderController {
61+
62+
override func viewDidLayoutSubviews() {
63+
super.viewDidLayoutSubviews()
64+
scrollView.contentSize = .init(width: view.frame.width, height: 1400)
4565
}
4666
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// The MIT License (MIT)
2+
// Copyright © 2021 Ivan Vorobei (hello@ivanvorobei.by)
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 NativeLargeActionToolBarView: NativeMimicrateToolBarView {
27+
28+
// MARK: - Views
29+
30+
public let actionButton = NativeLargeActionButton().do {
31+
$0.applyDefaultAppearance(with: .init(content: .white, background: .tint))
32+
}
33+
34+
// MARK: - Init
35+
36+
open override func commonInit() {
37+
super.commonInit()
38+
addSubview(actionButton)
39+
}
40+
41+
// MARK: - Layout
42+
43+
open override func layoutSubviews() {
44+
super.layoutSubviews()
45+
actionButton.layout(y: layoutMargins.top)
46+
}
47+
48+
open override func sizeThatFits(_ size: CGSize) -> CGSize {
49+
layoutSubviews()
50+
return .init(width: size.width, height: actionButton.frame.maxY + layoutMargins.bottom)
51+
}
52+
}
53+
#endif

Sources/NativeUIKit/Bars/NativeMimicrateNavigationToolBarView.swift renamed to Sources/NativeUIKit/Bars/Tool/NativeMimicrateNavigationToolBarView.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,19 @@ open class NativeMimicrateToolBarView: NativeMimicrateBarView {
3434
public required init?(coder aDecoder: NSCoder) {
3535
fatalError("init(coder:) has not been implemented")
3636
}
37+
38+
open override func commonInit() {
39+
super.commonInit()
40+
insetsLayoutMarginsFromSafeArea = false
41+
}
42+
43+
// MARK: - Layout
44+
45+
open override func layoutSubviews() {
46+
super.layoutSubviews()
47+
guard let superview = superview else { return }
48+
let contentWidth = min(440, superview.readableWidth)
49+
layoutMargins = .init(horizontal: (frame.width - contentWidth) / 2, vertical: 16)
50+
}
3751
}
3852
#endif
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// The MIT License (MIT)
2+
// Copyright © 2021 Ivan Vorobei (hello@ivanvorobei.by)
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 NativeSkipableLargeActionToolBarView: NativeMimicrateToolBarView {
27+
28+
// MARK: - Views
29+
30+
public let actionButton = NativeLargeActionButton().do {
31+
$0.applyDefaultAppearance(with: .init(content: .white, background: .tint))
32+
}
33+
34+
public let skipButton = SPDimmedButton().do {
35+
if #available(iOS 13.0, *) {
36+
$0.applyDefaultAppearance(with: .init(content: .tertiaryLabel, background: .clear))
37+
}
38+
$0.titleLabel?.font = UIFont.preferredFont(forTextStyle: .body, weight: .semibold)
39+
}
40+
41+
// MARK: - Init
42+
43+
open override func commonInit() {
44+
super.commonInit()
45+
addSubview(actionButton)
46+
addSubview(skipButton)
47+
}
48+
49+
// MARK: - Layout
50+
51+
open override func layoutSubviews() {
52+
super.layoutSubviews()
53+
actionButton.layout(y: layoutMargins.top)
54+
55+
skipButton.setWidthAndFit(width: layoutWidth)
56+
skipButton.frame.origin.y = actionButton.frame.maxY + 12
57+
skipButton.setXCenter()
58+
}
59+
60+
open override func sizeThatFits(_ size: CGSize) -> CGSize {
61+
layoutSubviews()
62+
return .init(width: size.width, height: skipButton.frame.maxY + layoutMargins.bottom)
63+
}
64+
}
65+
#endif
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// The MIT License (MIT)
2+
// Copyright © 2021 Ivan Vorobei (hello@ivanvorobei.by)
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 NativeSmallActionToolBarView: NativeMimicrateToolBarView {
27+
28+
public let actionButton = SPDimmedButton().do {
29+
$0.applyDefaultAppearance(with: .init(content: .tint, background: .clear))
30+
$0.titleLabel?.font = UIFont.preferredFont(forTextStyle: .title3, weight: .semibold)
31+
}
32+
33+
// MARK: - Init
34+
35+
open override func commonInit() {
36+
super.commonInit()
37+
addSubview(actionButton)
38+
}
39+
40+
// MARK: - Layout
41+
42+
open override func layoutSubviews() {
43+
super.layoutSubviews()
44+
actionButton.setWidthAndFit(width: layoutWidth)
45+
actionButton.frame.origin.y = layoutMargins.top + 16
46+
actionButton.setXCenter()
47+
}
48+
49+
open override func sizeThatFits(_ size: CGSize) -> CGSize {
50+
layoutSubviews()
51+
return .init(width: size.width, height: actionButton.frame.maxY + layoutMargins.bottom)
52+
}
53+
}
54+
#endif

Sources/NativeUIKit/Controls/NativeLargeActionButton.swift renamed to Sources/NativeUIKit/Controllers/Controls/NativeLargeActionButton.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ open class NativeLargeActionButton: SPDimmedButton {
7777
sizeToFit()
7878
let width = min(superview.readableWidth, NativeLayout.Sizes.actionable_area_maximum_width)
7979
frame.setWidth(width)
80-
superview.setXCenter()
80+
setXCenter()
8181
frame.origin.y = y
8282
}
8383

@@ -89,7 +89,7 @@ open class NativeLargeActionButton: SPDimmedButton {
8989
sizeToFit()
9090
let width = min(superview.readableWidth, NativeLayout.Sizes.actionable_area_maximum_width)
9191
frame.setWidth(width)
92-
superview.setXCenter()
92+
setXCenter()
9393
frame.setMaxY(maxY)
9494
}
9595

0 commit comments

Comments
 (0)