react-native-sheet2 1.1.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +20 -0
- package/README.md +79 -0
- package/android/build.gradle +83 -0
- package/android/gradle.properties +6 -0
- package/android/src/main/AndroidManifest.xml +12 -0
- package/android/src/main/java/com/behavior/BottomSheetBehavior.java +2329 -0
- package/android/src/main/java/com/behavior/InsetsAnimationCallback.java +83 -0
- package/android/src/main/java/com/modal/FullScreenDialog.kt +100 -0
- package/android/src/main/java/com/modal/TopModalView.kt +77 -0
- package/android/src/main/java/com/modal/TopModalViewManager.kt +83 -0
- package/android/src/main/java/com/modal/TopModalViewModule.kt +36 -0
- package/android/src/main/java/com/sheet/AppFittedSheet.kt +149 -0
- package/android/src/main/java/com/sheet/BaseRNView.kt +73 -0
- package/android/src/main/java/com/sheet/CustomBottomSheetDialog.java +238 -0
- package/android/src/main/java/com/sheet/DialogRootViewGroup.kt +159 -0
- package/android/src/main/java/com/sheet/FragmentModalBottomSheet.kt +54 -0
- package/android/src/main/java/com/sheet/ReactNativeReflection.java +24 -0
- package/android/src/main/java/com/sheet/SheetPackage.kt +20 -0
- package/android/src/main/java/com/sheet/SheetViewManager.kt +144 -0
- package/android/src/main/java/com/sheet/SheetViewModule.kt +43 -0
- package/android/src/main/java/com/sheet/utils.kt +71 -0
- package/android/src/main/java/com/transparent/activity/ActivityModalView.kt +71 -0
- package/android/src/main/java/com/transparent/activity/TransparentActivity.kt +48 -0
- package/android/src/main/java/com/transparent/activity/TransparentActivityManager.kt +63 -0
- package/android/src/main/java/com/transparent/activity/TransparentActivityModule.kt +28 -0
- package/android/src/main/res/anim/fade_in.xml +8 -0
- package/android/src/main/res/anim/fade_out.xml +11 -0
- package/android/src/main/res/anim/slide_down.xml +8 -0
- package/android/src/main/res/anim/slide_up.xml +8 -0
- package/android/src/main/res/layout/dialog_bottom_sheet.xml +64 -0
- package/android/src/main/res/layout/item_full.xml +14 -0
- package/android/src/main/res/values/colors.xml +15 -0
- package/android/src/main/res/values/styles.xml +75 -0
- package/ios/FittedSheets/Compatible.swift +55 -0
- package/ios/FittedSheets/InitialTouchPanGestureRecognizer.swift +19 -0
- package/ios/FittedSheets/SheetContentViewController.swift +326 -0
- package/ios/FittedSheets/SheetContentViewDelegate.swift +17 -0
- package/ios/FittedSheets/SheetOptions.swift +100 -0
- package/ios/FittedSheets/SheetSize.swift +20 -0
- package/ios/FittedSheets/SheetTransition.swift +153 -0
- package/ios/FittedSheets/SheetView.swift +21 -0
- package/ios/FittedSheets/SheetViewController.swift +761 -0
- package/ios/FittedSheets/SheetViewDelegate.swift +16 -0
- package/ios/FittedSheets/UIColorExtension.swift +59 -0
- package/ios/FittedSheets/UIViewControllerExtension.swift +27 -0
- package/ios/FittedSheets/Yalta.swift +420 -0
- package/ios/LBBottomSheet/BottomSheetConstant.swift +48 -0
- package/ios/LBBottomSheet/Model/BottomSheetController+Behavior.swift +262 -0
- package/ios/LBBottomSheet/Model/BottomSheetController+Theme.swift +156 -0
- package/ios/LBBottomSheet/Protocols/BottomSheetInteractionDelegate.swift +29 -0
- package/ios/LBBottomSheet/Protocols/BottomSheetPositionDelegate.swift +31 -0
- package/ios/LBBottomSheet/UI/BottomSheet.storyboard +105 -0
- package/ios/LBBottomSheet/UI/BottomSheetController.swift +601 -0
- package/ios/LBBottomSheet/Utils/Components/ForwardingEventsView.swift +60 -0
- package/ios/LBBottomSheet/Utils/Extensions/CACornerMask+Extension.swift +33 -0
- package/ios/LBBottomSheet/Utils/Extensions/Mirror+Extension.swift +47 -0
- package/ios/LBBottomSheet/Utils/Extensions/UIApplication+Extension.swift +35 -0
- package/ios/LBBottomSheet/Utils/Extensions/UIColor+Extension.swift +61 -0
- package/ios/LBBottomSheet/Utils/Extensions/UIGestureRecognizer+Extensions.swift +28 -0
- package/ios/LBBottomSheet/Utils/Extensions/UIScreen+Extension.swift +28 -0
- package/ios/LBBottomSheet/Utils/Extensions/UIScrollView+Extension.swift +25 -0
- package/ios/LBBottomSheet/Utils/Extensions/UIView+Extension.swift +52 -0
- package/ios/LBBottomSheet/Utils/Extensions/UIViewController+Extension.swift +104 -0
- package/ios/Sheet-Bridging-Header.h +1 -0
- package/ios/Sheet.xcodeproj/project.pbxproj +377 -0
- package/ios/SheetViewManager.m +27 -0
- package/ios/SheetViewManager.swift +351 -0
- package/ios/TopModalViewManager.swift +196 -0
- package/package.json +103 -0
- package/react-native-sheet.podspec +21 -0
- package/src/FittedSheet.tsx +177 -0
- package/src/TopModal.tsx +94 -0
- package/src/TransparentActivity.tsx +98 -0
- package/src/index.tsx +16 -0
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
//
|
|
2
|
+
// SheetContentViewController.swift
|
|
3
|
+
// FittedSheetsPod
|
|
4
|
+
//
|
|
5
|
+
// Created by Gordon Tucker on 7/29/20.
|
|
6
|
+
// Copyright © 2020 Gordon Tucker. All rights reserved.
|
|
7
|
+
//
|
|
8
|
+
|
|
9
|
+
#if os(iOS) || os(tvOS) || os(watchOS)
|
|
10
|
+
import UIKit
|
|
11
|
+
|
|
12
|
+
public class SheetContentViewController: UIViewController {
|
|
13
|
+
|
|
14
|
+
public private(set) var childViewController: UIViewController
|
|
15
|
+
|
|
16
|
+
private var options: SheetOptions
|
|
17
|
+
private (set) var size: CGFloat = 0
|
|
18
|
+
private (set) var preferredHeight: CGFloat
|
|
19
|
+
|
|
20
|
+
public var contentBackgroundColor: UIColor? {
|
|
21
|
+
get { self.childContainerView.backgroundColor }
|
|
22
|
+
set { self.childContainerView.backgroundColor = newValue }
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
private var _cornerCurve: Any? = nil
|
|
26
|
+
@available(iOS 13.0, *)
|
|
27
|
+
public var cornerCurve: CALayerCornerCurve {
|
|
28
|
+
get {
|
|
29
|
+
return _cornerCurve as? CALayerCornerCurve ?? CALayerCornerCurve.circular }
|
|
30
|
+
set {
|
|
31
|
+
_cornerCurve = newValue
|
|
32
|
+
self.updateCornerCurve()
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
public var cornerRadius: CGFloat = 0 {
|
|
37
|
+
didSet {
|
|
38
|
+
self.updateCornerRadius()
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
public var gripSize: CGSize = CGSize(width: 50, height: 6) {
|
|
43
|
+
didSet {
|
|
44
|
+
self.gripSizeConstraints.forEach({ $0.isActive = false })
|
|
45
|
+
Constraints(for: self.gripView) {
|
|
46
|
+
self.gripSizeConstraints = $0.size.set(self.gripSize)
|
|
47
|
+
}
|
|
48
|
+
self.gripView.layer.cornerRadius = self.gripSize.height / 2
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
public var gripColor: UIColor? {
|
|
53
|
+
get { return self.gripView.backgroundColor }
|
|
54
|
+
set { self.gripView.backgroundColor = newValue }
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
public var pullBarBackgroundColor: UIColor? {
|
|
58
|
+
get { return self.pullBarView.backgroundColor }
|
|
59
|
+
set { self.pullBarView.backgroundColor = newValue }
|
|
60
|
+
}
|
|
61
|
+
public var treatPullBarAsClear: Bool = SheetViewController.treatPullBarAsClear {
|
|
62
|
+
didSet {
|
|
63
|
+
if self.isViewLoaded {
|
|
64
|
+
self.updateCornerRadius()
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
weak var delegate: SheetContentViewDelegate?
|
|
70
|
+
|
|
71
|
+
public var contentWrapperView = UIView()
|
|
72
|
+
public var contentView = UIView()
|
|
73
|
+
private var contentTopConstraint: NSLayoutConstraint?
|
|
74
|
+
private var contentBottomConstraint: NSLayoutConstraint?
|
|
75
|
+
private var navigationHeightConstraint: NSLayoutConstraint?
|
|
76
|
+
private var gripSizeConstraints: [NSLayoutConstraint] = []
|
|
77
|
+
public var childContainerView = UIView()
|
|
78
|
+
public var pullBarView = UIView()
|
|
79
|
+
public var gripView = UIView()
|
|
80
|
+
private let overflowView = UIView()
|
|
81
|
+
|
|
82
|
+
public init(childViewController: UIViewController, options: SheetOptions) {
|
|
83
|
+
self.options = options
|
|
84
|
+
self.childViewController = childViewController
|
|
85
|
+
self.preferredHeight = 0
|
|
86
|
+
super.init(nibName: nil, bundle: nil)
|
|
87
|
+
|
|
88
|
+
if options.setIntrinsicHeightOnNavigationControllers, let navigationController = self.childViewController as? UINavigationController {
|
|
89
|
+
navigationController.delegate = self
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
public required init?(coder: NSCoder) {
|
|
94
|
+
fatalError("init(coder:) has not been implemented")
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
public override func viewDidLoad() {
|
|
98
|
+
super.viewDidLoad()
|
|
99
|
+
|
|
100
|
+
self.setupContentView()
|
|
101
|
+
self.setupChildContainerView()
|
|
102
|
+
self.setupPullBarView()
|
|
103
|
+
self.setupChildViewController()
|
|
104
|
+
self.updatePreferredHeight()
|
|
105
|
+
if #available(iOS 13.0, *) {
|
|
106
|
+
self.updateCornerCurve()
|
|
107
|
+
}
|
|
108
|
+
self.updateCornerRadius()
|
|
109
|
+
self.setupOverflowView()
|
|
110
|
+
|
|
111
|
+
NotificationCenter.default.addObserver(self, selector: #selector(contentSizeDidChange), name: UIContentSizeCategory.didChangeNotification, object: nil)
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
public override func viewWillAppear(_ animated: Bool) {
|
|
115
|
+
super.viewWillAppear(animated)
|
|
116
|
+
UIView.performWithoutAnimation {
|
|
117
|
+
self.view.layoutIfNeeded()
|
|
118
|
+
}
|
|
119
|
+
self.updatePreferredHeight()
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
public override func viewDidAppear(_ animated: Bool) {
|
|
123
|
+
super.viewDidAppear(animated)
|
|
124
|
+
self.updatePreferredHeight()
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
public override func viewDidLayoutSubviews() {
|
|
128
|
+
super.viewDidLayoutSubviews()
|
|
129
|
+
self.updateAfterLayout()
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
func updateAfterLayout() {
|
|
133
|
+
self.size = self.childViewController.view.bounds.height
|
|
134
|
+
//self.updatePreferredHeight()
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
func adjustForKeyboard(height: CGFloat) {
|
|
138
|
+
self.updateChildViewControllerBottomConstraint(adjustment: -height)
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
@available(iOS 13.0, *)
|
|
142
|
+
private func updateCornerCurve() {
|
|
143
|
+
self.contentWrapperView.layer.cornerCurve = self.cornerCurve
|
|
144
|
+
self.childContainerView.layer.cornerCurve = self.cornerCurve
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
private func updateCornerRadius() {
|
|
148
|
+
self.contentWrapperView.layer.cornerRadius = self.treatPullBarAsClear ? 0 : self.cornerRadius
|
|
149
|
+
self.childContainerView.layer.cornerRadius = self.treatPullBarAsClear ? self.cornerRadius : 0
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
private func setupOverflowView() {
|
|
153
|
+
switch (self.options.transitionOverflowType) {
|
|
154
|
+
case .view(view: let view):
|
|
155
|
+
overflowView.backgroundColor = .clear
|
|
156
|
+
overflowView.addSubview(view) {
|
|
157
|
+
$0.edges.pinToSuperview()
|
|
158
|
+
}
|
|
159
|
+
case .automatic:
|
|
160
|
+
overflowView.backgroundColor = self.childViewController.view.backgroundColor
|
|
161
|
+
case .color(color: let color):
|
|
162
|
+
overflowView.backgroundColor = color
|
|
163
|
+
case .none:
|
|
164
|
+
overflowView.backgroundColor = .clear
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
private func updateNavigationControllerHeight() {
|
|
169
|
+
// UINavigationControllers don't set intrinsic size, this is a workaround to fix that
|
|
170
|
+
guard self.options.setIntrinsicHeightOnNavigationControllers, let navigationController = self.childViewController as? UINavigationController else { return }
|
|
171
|
+
self.navigationHeightConstraint?.isActive = false
|
|
172
|
+
self.contentTopConstraint?.isActive = false
|
|
173
|
+
|
|
174
|
+
if let viewController = navigationController.visibleViewController {
|
|
175
|
+
let size = viewController.view.systemLayoutSizeFitting(CGSize(width: view.bounds.width, height: 0))
|
|
176
|
+
|
|
177
|
+
if self.navigationHeightConstraint == nil {
|
|
178
|
+
self.navigationHeightConstraint = navigationController.view.heightAnchor.constraint(equalToConstant: size.height)
|
|
179
|
+
} else {
|
|
180
|
+
self.navigationHeightConstraint?.constant = size.height
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
self.navigationHeightConstraint?.isActive = true
|
|
184
|
+
self.contentTopConstraint?.isActive = true
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
func updatePreferredHeight() {
|
|
188
|
+
self.updateNavigationControllerHeight()
|
|
189
|
+
let width = self.view.bounds.width > 0 ? self.view.bounds.width : UIScreen.main.bounds.width
|
|
190
|
+
let oldPreferredHeight = self.preferredHeight
|
|
191
|
+
var fittingSize = UIView.layoutFittingCompressedSize;
|
|
192
|
+
fittingSize.width = width;
|
|
193
|
+
|
|
194
|
+
self.contentTopConstraint?.isActive = false
|
|
195
|
+
UIView.performWithoutAnimation {
|
|
196
|
+
self.contentView.layoutSubviews()
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
self.preferredHeight = self.contentView.systemLayoutSizeFitting(fittingSize, withHorizontalFittingPriority: .required, verticalFittingPriority: .defaultLow).height
|
|
200
|
+
self.contentTopConstraint?.isActive = true
|
|
201
|
+
UIView.performWithoutAnimation {
|
|
202
|
+
self.contentView.layoutSubviews()
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
self.delegate?.preferredHeightChanged(oldHeight: oldPreferredHeight, newSize: self.preferredHeight)
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
private func updateChildViewControllerBottomConstraint(adjustment: CGFloat) {
|
|
209
|
+
self.contentBottomConstraint?.constant = adjustment
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
private func setupChildViewController() {
|
|
213
|
+
self.childViewController.willMove(toParent: self)
|
|
214
|
+
self.addChild(self.childViewController)
|
|
215
|
+
self.childContainerView.addSubview(self.childViewController.view)
|
|
216
|
+
Constraints(for: self.childViewController.view) { view in
|
|
217
|
+
view.left.pinToSuperview()
|
|
218
|
+
view.right.pinToSuperview()
|
|
219
|
+
self.contentBottomConstraint = view.bottom.pinToSuperview()
|
|
220
|
+
view.top.pinToSuperview()
|
|
221
|
+
}
|
|
222
|
+
if self.options.shouldExtendBackground, self.options.pullBarHeight > 0 {
|
|
223
|
+
self.childViewController.compatibleAdditionalSafeAreaInsets = UIEdgeInsets(top: self.options.pullBarHeight, left: 0, bottom: 0, right: 0)
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
self.childViewController.didMove(toParent: self)
|
|
227
|
+
|
|
228
|
+
self.childContainerView.layer.masksToBounds = true
|
|
229
|
+
self.childContainerView.layer.compatibleMaskedCorners = [.layerMaxXMinYCorner, .layerMinXMinYCorner]
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
private func setupContentView() {
|
|
233
|
+
self.view.addSubview(self.contentView)
|
|
234
|
+
Constraints(for: self.contentView) {
|
|
235
|
+
$0.left.pinToSuperview()
|
|
236
|
+
$0.right.pinToSuperview()
|
|
237
|
+
$0.bottom.pinToSuperview()
|
|
238
|
+
self.contentTopConstraint = $0.top.pinToSuperview()
|
|
239
|
+
}
|
|
240
|
+
self.contentView.addSubview(self.contentWrapperView) {
|
|
241
|
+
$0.edges.pinToSuperview()
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
self.contentWrapperView.layer.masksToBounds = true
|
|
245
|
+
self.contentWrapperView.layer.compatibleMaskedCorners = [.layerMaxXMinYCorner, .layerMinXMinYCorner]
|
|
246
|
+
|
|
247
|
+
self.contentView.addSubview(overflowView) {
|
|
248
|
+
$0.edges(.left, .right).pinToSuperview()
|
|
249
|
+
$0.height.set(200)
|
|
250
|
+
$0.top.align(with: self.contentView.al.bottom - 1)
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
private func setupChildContainerView() {
|
|
255
|
+
self.contentWrapperView.addSubview(self.childContainerView)
|
|
256
|
+
|
|
257
|
+
Constraints(for: self.childContainerView) { view in
|
|
258
|
+
|
|
259
|
+
if self.options.shouldExtendBackground {
|
|
260
|
+
view.top.pinToSuperview()
|
|
261
|
+
} else {
|
|
262
|
+
view.top.pinToSuperview(inset: self.options.pullBarHeight)
|
|
263
|
+
}
|
|
264
|
+
view.left.pinToSuperview()
|
|
265
|
+
view.right.pinToSuperview()
|
|
266
|
+
view.bottom.pinToSuperview()
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
private func setupPullBarView() {
|
|
271
|
+
// If they didn't specify pull bar options, they don't want a pull bar
|
|
272
|
+
guard self.options.pullBarHeight > 0 else { return }
|
|
273
|
+
let pullBarView = self.pullBarView
|
|
274
|
+
pullBarView.isUserInteractionEnabled = true
|
|
275
|
+
pullBarView.backgroundColor = self.pullBarBackgroundColor
|
|
276
|
+
self.contentWrapperView.addSubview(pullBarView)
|
|
277
|
+
Constraints(for: pullBarView) {
|
|
278
|
+
$0.top.pinToSuperview()
|
|
279
|
+
$0.left.pinToSuperview()
|
|
280
|
+
$0.right.pinToSuperview()
|
|
281
|
+
$0.height.set(options.pullBarHeight)
|
|
282
|
+
}
|
|
283
|
+
self.pullBarView = pullBarView
|
|
284
|
+
|
|
285
|
+
let gripView = self.gripView
|
|
286
|
+
gripView.backgroundColor = self.gripColor
|
|
287
|
+
gripView.layer.cornerRadius = self.gripSize.height / 2
|
|
288
|
+
gripView.layer.masksToBounds = true
|
|
289
|
+
pullBarView.addSubview(gripView)
|
|
290
|
+
self.gripSizeConstraints.forEach({ $0.isActive = false })
|
|
291
|
+
Constraints(for: gripView) {
|
|
292
|
+
$0.centerY.alignWithSuperview()
|
|
293
|
+
$0.centerX.alignWithSuperview()
|
|
294
|
+
self.gripSizeConstraints = $0.size.set(self.gripSize)
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
pullBarView.isAccessibilityElement = true
|
|
298
|
+
pullBarView.accessibilityIdentifier = "pull-bar"
|
|
299
|
+
// This will be overriden whenever the sizes property is changed on SheetViewController
|
|
300
|
+
pullBarView.accessibilityTraits = [.button]
|
|
301
|
+
|
|
302
|
+
let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(pullBarTapped))
|
|
303
|
+
pullBarView.addGestureRecognizer(tapGestureRecognizer)
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
@objc func pullBarTapped(_ gesture: UITapGestureRecognizer) {
|
|
307
|
+
self.delegate?.pullBarTapped()
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
@objc func contentSizeDidChange() {
|
|
311
|
+
self.updatePreferredHeight()
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
extension SheetContentViewController: UINavigationControllerDelegate {
|
|
316
|
+
public func navigationController(_ navigationController: UINavigationController, willShow viewController: UIViewController, animated: Bool) {
|
|
317
|
+
navigationController.view.endEditing(true)
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
public func navigationController(_ navigationController: UINavigationController, didShow viewController: UIViewController, animated: Bool) {
|
|
321
|
+
self.navigationHeightConstraint?.isActive = true
|
|
322
|
+
self.updatePreferredHeight()
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
#endif // os(iOS) || os(tvOS) || os(watchOS)
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
//
|
|
2
|
+
// SheetContentViewDelegate.swift
|
|
3
|
+
// FittedSheetsPod
|
|
4
|
+
//
|
|
5
|
+
// Created by Gordon Tucker on 7/29/20.
|
|
6
|
+
// Copyright © 2020 Gordon Tucker. All rights reserved.
|
|
7
|
+
//
|
|
8
|
+
|
|
9
|
+
#if os(iOS) || os(tvOS) || os(watchOS)
|
|
10
|
+
import UIKit
|
|
11
|
+
|
|
12
|
+
protocol SheetContentViewDelegate: AnyObject {
|
|
13
|
+
func preferredHeightChanged(oldHeight: CGFloat, newSize: CGFloat)
|
|
14
|
+
func pullBarTapped()
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
#endif // os(iOS) || os(tvOS) || os(watchOS)
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
//
|
|
2
|
+
// HandleOptions.swift
|
|
3
|
+
// FittedSheetsPod
|
|
4
|
+
//
|
|
5
|
+
// Created by Gordon Tucker on 7/29/20.
|
|
6
|
+
// Copyright © 2020 Gordon Tucker. All rights reserved.
|
|
7
|
+
//
|
|
8
|
+
|
|
9
|
+
#if os(iOS) || os(tvOS) || os(watchOS)
|
|
10
|
+
import UIKit
|
|
11
|
+
|
|
12
|
+
public struct SheetOptions {
|
|
13
|
+
public static var `default` = SheetOptions()
|
|
14
|
+
|
|
15
|
+
public enum TransitionOverflowType {
|
|
16
|
+
case color(color: UIColor)
|
|
17
|
+
case view(view: UIView)
|
|
18
|
+
case none
|
|
19
|
+
case automatic
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
public var pullBarHeight: CGFloat = 24
|
|
23
|
+
|
|
24
|
+
public var presentingViewCornerRadius: CGFloat = 12
|
|
25
|
+
public var shouldExtendBackground = true
|
|
26
|
+
public var setIntrinsicHeightOnNavigationControllers = true
|
|
27
|
+
|
|
28
|
+
public var transitionAnimationOptions: UIView.AnimationOptions = [.curveEaseOut]
|
|
29
|
+
public var transitionDampening: CGFloat = 0.7
|
|
30
|
+
public var transitionDuration: TimeInterval = 0.4
|
|
31
|
+
/// Transition velocity base value. Automatically adjusts based on the initial size of the sheet.
|
|
32
|
+
public var transitionVelocity: CGFloat = 0.8
|
|
33
|
+
public var transitionOverflowType: TransitionOverflowType = .automatic
|
|
34
|
+
|
|
35
|
+
/// Default value 500, greater value will require more velocity to dismiss. Lesser values will do opposite.
|
|
36
|
+
public var pullDismissThreshod: CGFloat = 500.0
|
|
37
|
+
|
|
38
|
+
/// Allow the sheet to become full screen if pulled all the way to the top and not larger than the maximum size specified in sizes. Defaults to false.
|
|
39
|
+
public var useFullScreenMode = true
|
|
40
|
+
public var shrinkPresentingViewController = true
|
|
41
|
+
/// Set true to be able to use the sheet view controller as a subview instead of a modal. Defaults to false.
|
|
42
|
+
public var useInlineMode = false
|
|
43
|
+
|
|
44
|
+
public var horizontalPadding: CGFloat = 0
|
|
45
|
+
public var maxWidth: CGFloat?
|
|
46
|
+
|
|
47
|
+
public var isRubberBandEnabled: Bool = false
|
|
48
|
+
|
|
49
|
+
/// Experimental flag that attempts to shrink the nested presentations more each time a new sheet is presented. This must be set before any sheet is presented.
|
|
50
|
+
public static var shrinkingNestedPresentingViewControllers = false
|
|
51
|
+
|
|
52
|
+
public init() { }
|
|
53
|
+
public init(pullBarHeight: CGFloat? = nil,
|
|
54
|
+
presentingViewCornerRadius: CGFloat? = nil,
|
|
55
|
+
shouldExtendBackground: Bool? = nil,
|
|
56
|
+
setIntrinsicHeightOnNavigationControllers: Bool? = nil,
|
|
57
|
+
useFullScreenMode: Bool? = nil,
|
|
58
|
+
shrinkPresentingViewController: Bool? = nil,
|
|
59
|
+
useInlineMode: Bool? = nil,
|
|
60
|
+
horizontalPadding: CGFloat? = nil,
|
|
61
|
+
maxWidth: CGFloat? = nil,
|
|
62
|
+
isRubberBandEnabled: Bool? = nil) {
|
|
63
|
+
let defaultOptions = SheetOptions.default
|
|
64
|
+
self.pullBarHeight = pullBarHeight ?? defaultOptions.pullBarHeight
|
|
65
|
+
self.presentingViewCornerRadius = presentingViewCornerRadius ?? defaultOptions.presentingViewCornerRadius
|
|
66
|
+
self.shouldExtendBackground = shouldExtendBackground ?? defaultOptions.shouldExtendBackground
|
|
67
|
+
self.setIntrinsicHeightOnNavigationControllers = setIntrinsicHeightOnNavigationControllers ?? defaultOptions.setIntrinsicHeightOnNavigationControllers
|
|
68
|
+
self.useFullScreenMode = useFullScreenMode ?? defaultOptions.useFullScreenMode
|
|
69
|
+
self.shrinkPresentingViewController = shrinkPresentingViewController ?? defaultOptions.shrinkPresentingViewController
|
|
70
|
+
self.useInlineMode = useInlineMode ?? defaultOptions.useInlineMode
|
|
71
|
+
self.horizontalPadding = horizontalPadding ?? defaultOptions.horizontalPadding
|
|
72
|
+
let maxWidth = maxWidth ?? defaultOptions.maxWidth
|
|
73
|
+
self.maxWidth = maxWidth == 0 ? nil : maxWidth
|
|
74
|
+
self.isRubberBandEnabled = isRubberBandEnabled ?? false
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
@available(*, unavailable, message: "cornerRadius, minimumSpaceAbovePullBar, gripSize and gripColor are now properties on SheetViewController. Use them instead.")
|
|
78
|
+
public init(pullBarHeight: CGFloat? = nil,
|
|
79
|
+
gripSize: CGSize? = nil,
|
|
80
|
+
gripColor: UIColor? = nil,
|
|
81
|
+
cornerRadius: CGFloat? = nil,
|
|
82
|
+
presentingViewCornerRadius: CGFloat? = nil,
|
|
83
|
+
shouldExtendBackground: Bool? = nil,
|
|
84
|
+
setIntrinsicHeightOnNavigationControllers: Bool? = nil,
|
|
85
|
+
useFullScreenMode: Bool? = nil,
|
|
86
|
+
shrinkPresentingViewController: Bool? = nil,
|
|
87
|
+
useInlineMode: Bool? = nil,
|
|
88
|
+
minimumSpaceAbovePullBar: CGFloat? = nil) {
|
|
89
|
+
let defaultOptions = SheetOptions.default
|
|
90
|
+
self.pullBarHeight = pullBarHeight ?? defaultOptions.pullBarHeight
|
|
91
|
+
self.presentingViewCornerRadius = presentingViewCornerRadius ?? defaultOptions.presentingViewCornerRadius
|
|
92
|
+
self.shouldExtendBackground = shouldExtendBackground ?? defaultOptions.shouldExtendBackground
|
|
93
|
+
self.setIntrinsicHeightOnNavigationControllers = setIntrinsicHeightOnNavigationControllers ?? defaultOptions.setIntrinsicHeightOnNavigationControllers
|
|
94
|
+
self.useFullScreenMode = useFullScreenMode ?? defaultOptions.useFullScreenMode
|
|
95
|
+
self.shrinkPresentingViewController = shrinkPresentingViewController ?? defaultOptions.shrinkPresentingViewController
|
|
96
|
+
self.useInlineMode = useInlineMode ?? defaultOptions.useInlineMode
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
#endif // os(iOS) || os(tvOS) || os(watchOS)
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
//
|
|
2
|
+
// SheetDockSize.swift
|
|
3
|
+
// FittedSheets
|
|
4
|
+
//
|
|
5
|
+
// Created by Gordon Tucker on 8/27/18.
|
|
6
|
+
// Copyright © 2018 Gordon Tucker. All rights reserved.
|
|
7
|
+
//
|
|
8
|
+
|
|
9
|
+
#if os(iOS) || os(tvOS) || os(watchOS)
|
|
10
|
+
import CoreGraphics
|
|
11
|
+
|
|
12
|
+
public enum SheetSize: Equatable {
|
|
13
|
+
case intrinsic
|
|
14
|
+
case fixed(CGFloat)
|
|
15
|
+
case fullscreen
|
|
16
|
+
case percent(Float)
|
|
17
|
+
case marginFromTop(CGFloat)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
#endif // os(iOS) || os(tvOS) || os(watchOS)
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
//
|
|
2
|
+
// SheetTransitioningDelegate.swift
|
|
3
|
+
// FittedSheetsPod
|
|
4
|
+
//
|
|
5
|
+
// Created by Gordon Tucker on 8/4/20.
|
|
6
|
+
// Copyright © 2020 Gordon Tucker. All rights reserved.
|
|
7
|
+
//
|
|
8
|
+
|
|
9
|
+
#if os(iOS) || os(tvOS) || os(watchOS)
|
|
10
|
+
import UIKit
|
|
11
|
+
|
|
12
|
+
public class SheetTransition: NSObject, UIViewControllerAnimatedTransitioning {
|
|
13
|
+
var presenting = true
|
|
14
|
+
weak var presenter: UIViewController?
|
|
15
|
+
var options: SheetOptions
|
|
16
|
+
|
|
17
|
+
/// Cache of presenters so we can do the experimental shrinkingNestedPresentingViewControllers behavior
|
|
18
|
+
static var currentPresenters: [UIViewController] = []
|
|
19
|
+
|
|
20
|
+
init(options: SheetOptions) {
|
|
21
|
+
self.options = options
|
|
22
|
+
super.init()
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
public func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
|
|
26
|
+
return self.options.transitionDuration
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
public func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
|
|
30
|
+
let containerView = transitionContext.containerView
|
|
31
|
+
if self.presenting {
|
|
32
|
+
guard let presenter = transitionContext.viewController(forKey: .from), let sheet = transitionContext.viewController(forKey: .to) as? SheetViewController else {
|
|
33
|
+
transitionContext.completeTransition(true)
|
|
34
|
+
return
|
|
35
|
+
}
|
|
36
|
+
self.presenter = presenter
|
|
37
|
+
|
|
38
|
+
if SheetOptions.shrinkingNestedPresentingViewControllers {
|
|
39
|
+
SheetTransition.currentPresenters.append(presenter)
|
|
40
|
+
}
|
|
41
|
+
sheet.contentViewController.view.transform = .identity
|
|
42
|
+
containerView.addSubview(sheet.view)
|
|
43
|
+
//sheet.view.frame = containerView.frame
|
|
44
|
+
Constraints(for: sheet.view) {
|
|
45
|
+
$0.edges.pinToSuperview()
|
|
46
|
+
}
|
|
47
|
+
UIView.performWithoutAnimation {
|
|
48
|
+
sheet.view.layoutIfNeeded()
|
|
49
|
+
}
|
|
50
|
+
sheet.contentViewController.updatePreferredHeight()
|
|
51
|
+
sheet.resize(to: sheet.currentSize, animated: false)
|
|
52
|
+
let contentView = sheet.contentViewController.contentView
|
|
53
|
+
contentView.transform = CGAffineTransform(translationX: 0, y: contentView.bounds.height)
|
|
54
|
+
sheet.overlayView.alpha = 0
|
|
55
|
+
|
|
56
|
+
let heightPercent = contentView.bounds.height / UIScreen.main.bounds.height
|
|
57
|
+
|
|
58
|
+
UIView.performWithoutAnimation {
|
|
59
|
+
sheet.view.layoutIfNeeded()
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Use a normal animation to animate the shadown and background view
|
|
63
|
+
UIView.animate(withDuration: self.options.transitionDuration * 0.6, delay: 0, options: [.curveEaseOut], animations: {
|
|
64
|
+
if self.options.shrinkPresentingViewController {
|
|
65
|
+
self.setPresentor(percentComplete: 0)
|
|
66
|
+
}
|
|
67
|
+
sheet.overlayView.alpha = 1
|
|
68
|
+
}, completion: nil)
|
|
69
|
+
|
|
70
|
+
// Use a bounce effect to animate the view in
|
|
71
|
+
UIView.animate(
|
|
72
|
+
withDuration: self.options.transitionDuration,
|
|
73
|
+
delay: 0,
|
|
74
|
+
usingSpringWithDamping: self.options.transitionDampening + ((heightPercent - 0.2) * 1.25 * 0.17),
|
|
75
|
+
initialSpringVelocity: self.options.transitionVelocity * heightPercent,
|
|
76
|
+
options: self.options.transitionAnimationOptions,
|
|
77
|
+
animations: {
|
|
78
|
+
contentView.transform = .identity
|
|
79
|
+
},
|
|
80
|
+
completion: { _ in
|
|
81
|
+
transitionContext.completeTransition(!transitionContext.transitionWasCancelled)
|
|
82
|
+
}
|
|
83
|
+
)
|
|
84
|
+
} else {
|
|
85
|
+
guard let presenter = transitionContext.viewController(forKey: .to),
|
|
86
|
+
let sheet = transitionContext.viewController(forKey: .from) as? SheetViewController else {
|
|
87
|
+
transitionContext.completeTransition(true)
|
|
88
|
+
return
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
containerView.addSubview(sheet.view)
|
|
92
|
+
let contentView = sheet.contentViewController.contentView
|
|
93
|
+
|
|
94
|
+
self.restorePresentor(
|
|
95
|
+
presenter,
|
|
96
|
+
animations: {
|
|
97
|
+
contentView.transform = CGAffineTransform(translationX: 0, y: contentView.bounds.height)
|
|
98
|
+
sheet.overlayView.alpha = 0
|
|
99
|
+
}, completion: { _ in
|
|
100
|
+
transitionContext.completeTransition(!transitionContext.transitionWasCancelled)
|
|
101
|
+
}
|
|
102
|
+
)
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
func restorePresentor(_ presenter: UIViewController, animated: Bool = true, animations: (() -> Void)? = nil, completion: ((Bool) -> Void)? = nil) {
|
|
107
|
+
SheetTransition.currentPresenters.removeAll(where: { $0 == presenter })
|
|
108
|
+
let topSafeArea = UIApplication.shared.windows.filter {$0.isKeyWindow}.first?.compatibleSafeAreaInsets.top ?? 0
|
|
109
|
+
UIView.animate(
|
|
110
|
+
withDuration: self.options.transitionDuration,
|
|
111
|
+
animations: {
|
|
112
|
+
if self.options.shrinkPresentingViewController {
|
|
113
|
+
presenter.view.layer.transform = CATransform3DMakeScale(1, 1, 1)
|
|
114
|
+
presenter.view.layer.cornerRadius = 0
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
if SheetOptions.shrinkingNestedPresentingViewControllers {
|
|
118
|
+
var scale: CGFloat = 1.0
|
|
119
|
+
let presenters = SheetTransition.currentPresenters.reversed()
|
|
120
|
+
for lowerPresenter in presenters {
|
|
121
|
+
scale *= 0.92
|
|
122
|
+
lowerPresenter.view.layer.transform = CATransform3DConcat(CATransform3DMakeTranslation(0, topSafeArea/2, 0), CATransform3DMakeScale(scale, scale, 1))
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
animations?()
|
|
126
|
+
},
|
|
127
|
+
completion: {
|
|
128
|
+
completion?($0)
|
|
129
|
+
}
|
|
130
|
+
)
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
func setPresentor(percentComplete: CGFloat) {
|
|
134
|
+
guard self.options.shrinkPresentingViewController, let presenter = self.presenter else { return }
|
|
135
|
+
|
|
136
|
+
var scale: CGFloat = min(1, 0.92 + (0.08 * percentComplete))
|
|
137
|
+
|
|
138
|
+
let topSafeArea = UIApplication.shared.windows.filter {$0.isKeyWindow}.first?.compatibleSafeAreaInsets.top ?? 0
|
|
139
|
+
|
|
140
|
+
presenter.view.layer.transform = CATransform3DConcat(CATransform3DMakeTranslation(0, (1 - percentComplete) * topSafeArea/2, 0), CATransform3DMakeScale(scale, scale, 1))
|
|
141
|
+
presenter.view.layer.cornerRadius = self.options.presentingViewCornerRadius * (1 - percentComplete)
|
|
142
|
+
|
|
143
|
+
if SheetOptions.shrinkingNestedPresentingViewControllers {
|
|
144
|
+
let presenters = SheetTransition.currentPresenters.reversed().dropFirst()
|
|
145
|
+
for lowerPresenter in presenters {
|
|
146
|
+
scale *= 0.92
|
|
147
|
+
lowerPresenter.view.layer.transform = CATransform3DConcat(CATransform3DMakeTranslation(0, (1 - percentComplete) * topSafeArea/2, 0), CATransform3DMakeScale(scale, scale, 1))
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
#endif // os(iOS) || os(tvOS) || os(watchOS)
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
//
|
|
2
|
+
// SheetView.swift
|
|
3
|
+
// FittedSheetsPod
|
|
4
|
+
//
|
|
5
|
+
// Created by Gordon Tucker on 8/5/20.
|
|
6
|
+
// Copyright © 2020 Gordon Tucker. All rights reserved.
|
|
7
|
+
//
|
|
8
|
+
|
|
9
|
+
#if os(iOS) || os(tvOS) || os(watchOS)
|
|
10
|
+
import UIKit
|
|
11
|
+
|
|
12
|
+
class SheetView: UIView {
|
|
13
|
+
|
|
14
|
+
weak var delegate: SheetViewDelegate?
|
|
15
|
+
|
|
16
|
+
override func point(inside point: CGPoint, with event: UIEvent?) -> Bool {
|
|
17
|
+
return self.delegate?.sheetPoint(inside: point, with: event) ?? true
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
#endif // os(iOS) || os(tvOS) || os(watchOS)
|