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,16 @@
|
|
|
1
|
+
//
|
|
2
|
+
// SheetViewDelegate.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
|
+
protocol SheetViewDelegate: AnyObject {
|
|
13
|
+
func sheetPoint(inside point: CGPoint, with event: UIEvent?) -> Bool
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
#endif // os(iOS) || os(tvOS) || os(watchOS)
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
//
|
|
2
|
+
// UIColorExtension.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
|
+
extension UIColor {
|
|
13
|
+
convenience init(red: CGFloat, green: CGFloat, blue: CGFloat, alpha: CGFloat = 1, darkRed: CGFloat, darkGreen: CGFloat, darkBlue: CGFloat, darkAlpha: CGFloat = 1) {
|
|
14
|
+
if #available(iOS 13.0, *) {
|
|
15
|
+
self.init { (traits) -> UIColor in
|
|
16
|
+
switch traits.userInterfaceStyle {
|
|
17
|
+
case .dark:
|
|
18
|
+
return UIColor(red: darkRed, green: darkGreen, blue: darkBlue, alpha: darkAlpha)
|
|
19
|
+
default:
|
|
20
|
+
return UIColor(red: red, green: green, blue: blue, alpha: alpha)
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
} else {
|
|
24
|
+
self.init(red: red, green: green, blue: blue, alpha: alpha)
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
convenience init(white: CGFloat, alpha: CGFloat = 1, black: CGFloat, darkAlpha: CGFloat = 1) {
|
|
29
|
+
if #available(iOS 13.0, *) {
|
|
30
|
+
self.init { (traits) -> UIColor in
|
|
31
|
+
switch traits.userInterfaceStyle {
|
|
32
|
+
case .dark:
|
|
33
|
+
return UIColor(white: black, alpha: darkAlpha)
|
|
34
|
+
default:
|
|
35
|
+
return UIColor(white: white, alpha: alpha)
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
} else {
|
|
39
|
+
self.init(white: white, alpha: alpha)
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
convenience init(light: UIColor, dark: UIColor) {
|
|
44
|
+
if #available(iOS 13.0, *) {
|
|
45
|
+
self.init { (traits) -> UIColor in
|
|
46
|
+
switch traits.userInterfaceStyle {
|
|
47
|
+
case .dark:
|
|
48
|
+
return light
|
|
49
|
+
default:
|
|
50
|
+
return dark
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
} else {
|
|
54
|
+
self.init(cgColor: light.cgColor)
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
#endif // os(iOS) || os(tvOS) || os(watchOS)
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
//
|
|
2
|
+
// UIViewControllerExtension.swift
|
|
3
|
+
// FittedSheets
|
|
4
|
+
//
|
|
5
|
+
// Created by Gordon Tucker on 8/28/18.
|
|
6
|
+
// Copyright © 2018 Gordon Tucker. All rights reserved.
|
|
7
|
+
//
|
|
8
|
+
|
|
9
|
+
#if os(iOS) || os(tvOS) || os(watchOS)
|
|
10
|
+
import UIKit
|
|
11
|
+
|
|
12
|
+
extension UIViewController {
|
|
13
|
+
/// The sheet view controller presenting the current view controller heiarchy (if any)
|
|
14
|
+
public var sheetViewController: SheetViewController? {
|
|
15
|
+
var parent = self.parent
|
|
16
|
+
while let currentParent = parent {
|
|
17
|
+
if let sheetViewController = currentParent as? SheetViewController {
|
|
18
|
+
return sheetViewController
|
|
19
|
+
} else {
|
|
20
|
+
parent = currentParent.parent
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return nil
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
#endif // os(iOS) || os(tvOS) || os(watchOS)
|
|
@@ -0,0 +1,420 @@
|
|
|
1
|
+
// The MIT License (MIT)
|
|
2
|
+
//
|
|
3
|
+
// Copyright (c) 2017-2018 Alexander Grebenyuk (github.com/kean).
|
|
4
|
+
//
|
|
5
|
+
// August 2018 version, to update copy all code from https://raw.githubusercontent.com/kean/Yalta/master/Sources/Yalta.swift (leaving this header instead of the updated one)
|
|
6
|
+
// Make sure to remove all `public` from this class so we don't cause issues with anyone using this library in their own code already
|
|
7
|
+
|
|
8
|
+
#if os(iOS) || os(tvOS) || os(watchOS)
|
|
9
|
+
import UIKit
|
|
10
|
+
|
|
11
|
+
protocol LayoutItem { // `UIView`, `UILayoutGuide`
|
|
12
|
+
var superview: UIView? { get }
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
extension UIView: LayoutItem {}
|
|
16
|
+
extension UILayoutGuide: LayoutItem {
|
|
17
|
+
var superview: UIView? { return self.owningView }
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
extension LayoutItem { // Yalta methods available via `LayoutProxy`
|
|
21
|
+
@nonobjc var al: LayoutProxy<Self> { return LayoutProxy(base: self) }
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// MARK: - LayoutProxy
|
|
25
|
+
|
|
26
|
+
struct LayoutProxy<Base> {
|
|
27
|
+
let base: Base
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
extension LayoutProxy where Base: LayoutItem {
|
|
31
|
+
|
|
32
|
+
// MARK: Anchors
|
|
33
|
+
|
|
34
|
+
var top: Anchor<AnchorType.Edge, AnchorAxis.Vertical> { return Anchor(base, .top) }
|
|
35
|
+
var bottom: Anchor<AnchorType.Edge, AnchorAxis.Vertical> { return Anchor(base, .bottom) }
|
|
36
|
+
var left: Anchor<AnchorType.Edge, AnchorAxis.Horizontal> { return Anchor(base, .left) }
|
|
37
|
+
var right: Anchor<AnchorType.Edge, AnchorAxis.Horizontal> { return Anchor(base, .right) }
|
|
38
|
+
var leading: Anchor<AnchorType.Edge, AnchorAxis.Horizontal> { return Anchor(base, .leading) }
|
|
39
|
+
var trailing: Anchor<AnchorType.Edge, AnchorAxis.Horizontal> { return Anchor(base, .trailing) }
|
|
40
|
+
|
|
41
|
+
var centerX: Anchor<AnchorType.Center, AnchorAxis.Horizontal> { return Anchor(base, .centerX) }
|
|
42
|
+
var centerY: Anchor<AnchorType.Center, AnchorAxis.Vertical> { return Anchor(base, .centerY) }
|
|
43
|
+
|
|
44
|
+
var firstBaseline: Anchor<AnchorType.Baseline, AnchorAxis.Vertical> { return Anchor(base, .firstBaseline) }
|
|
45
|
+
var lastBaseline: Anchor<AnchorType.Baseline, AnchorAxis.Vertical> { return Anchor(base, .lastBaseline) }
|
|
46
|
+
|
|
47
|
+
var width: Anchor<AnchorType.Dimension, AnchorAxis.Horizontal> { return Anchor(base, .width) }
|
|
48
|
+
var height: Anchor<AnchorType.Dimension, AnchorAxis.Vertical> { return Anchor(base, .height) }
|
|
49
|
+
|
|
50
|
+
// MARK: Anchor Collections
|
|
51
|
+
|
|
52
|
+
func edges(_ edges: LayoutEdge...) -> AnchorCollectionEdges { return AnchorCollectionEdges(item: base, edges: edges) }
|
|
53
|
+
var edges: AnchorCollectionEdges { return AnchorCollectionEdges(item: base, edges: [.left, .right, .bottom, .top]) }
|
|
54
|
+
var center: AnchorCollectionCenter { return AnchorCollectionCenter(x: centerX, y: centerY) }
|
|
55
|
+
var size: AnchorCollectionSize { return AnchorCollectionSize(width: width, height: height) }
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
extension LayoutProxy where Base: UIView {
|
|
59
|
+
var margins: LayoutProxy<UILayoutGuide> { return base.layoutMarginsGuide.al }
|
|
60
|
+
|
|
61
|
+
@available(iOS 11.0, tvOS 11.0, *)
|
|
62
|
+
var safeArea: LayoutProxy<UILayoutGuide> { return base.safeAreaLayoutGuide.al }
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// MARK: - Anchors
|
|
66
|
+
|
|
67
|
+
// phantom types
|
|
68
|
+
enum AnchorAxis {
|
|
69
|
+
class Horizontal {}
|
|
70
|
+
class Vertical {}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
enum AnchorType {
|
|
74
|
+
class Dimension {}
|
|
75
|
+
/// Includes `center`, `edge` and `baselines` anchors.
|
|
76
|
+
class Alignment {}
|
|
77
|
+
class Center: Alignment {}
|
|
78
|
+
class Edge: Alignment {}
|
|
79
|
+
class Baseline: Alignment {}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/// An anchor represents one of the view's layout attributes (e.g. `left`,
|
|
83
|
+
/// `centerX`, `width`, etc). Use the anchor’s methods to construct constraints.
|
|
84
|
+
struct Anchor<Type, Axis> { // type and axis are phantom types
|
|
85
|
+
internal let item: LayoutItem
|
|
86
|
+
internal let attribute: NSLayoutConstraint.Attribute
|
|
87
|
+
internal let offset: CGFloat
|
|
88
|
+
internal let multiplier: CGFloat
|
|
89
|
+
|
|
90
|
+
init(_ item: LayoutItem, _ attribute: NSLayoutConstraint.Attribute, offset: CGFloat = 0, multiplier: CGFloat = 1) {
|
|
91
|
+
self.item = item; self.attribute = attribute; self.offset = offset; self.multiplier = multiplier
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/// Returns a new anchor offset by a given amount.
|
|
95
|
+
internal func offsetting(by offset: CGFloat) -> Anchor<Type, Axis> {
|
|
96
|
+
return Anchor<Type, Axis>(item, attribute, offset: self.offset + offset, multiplier: self.multiplier)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/// Returns a new anchor with a given multiplier.
|
|
100
|
+
internal func multiplied(by multiplier: CGFloat) -> Anchor<Type, Axis> {
|
|
101
|
+
return Anchor<Type, Axis>(item, attribute, offset: self.offset * multiplier, multiplier: self.multiplier * multiplier)
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
func + <Type, Axis>(anchor: Anchor<Type, Axis>, offset: CGFloat) -> Anchor<Type, Axis> {
|
|
106
|
+
return anchor.offsetting(by: offset)
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
func - <Type, Axis>(anchor: Anchor<Type, Axis>, offset: CGFloat) -> Anchor<Type, Axis> {
|
|
110
|
+
return anchor.offsetting(by: -offset)
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
func * <Type, Axis>(anchor: Anchor<Type, Axis>, multiplier: CGFloat) -> Anchor<Type, Axis> {
|
|
114
|
+
return anchor.multiplied(by: multiplier)
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// MARK: - Anchors (AnchorType.Alignment)
|
|
118
|
+
|
|
119
|
+
extension Anchor where Type: AnchorType.Alignment {
|
|
120
|
+
/// Aligns two anchors.
|
|
121
|
+
@discardableResult func align<Type: AnchorType.Alignment>(with anchor: Anchor<Type, Axis>, relation: NSLayoutConstraint.Relation = .equal) -> NSLayoutConstraint {
|
|
122
|
+
return Constraints.constrain(self, anchor, relation: relation)
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// MARK: - Anchors (AnchorType.Edge)
|
|
127
|
+
|
|
128
|
+
extension Anchor where Type: AnchorType.Edge {
|
|
129
|
+
/// Pins the edge to the same edge of the superview.
|
|
130
|
+
@discardableResult func pinToSuperview(inset: CGFloat = 0, relation: NSLayoutConstraint.Relation = .equal) -> NSLayoutConstraint {
|
|
131
|
+
return _pin(to: item.superview!, attribute: attribute, inset: inset, relation: relation)
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/// Pins the edge to the respected margin of the superview.
|
|
135
|
+
@discardableResult func pinToSuperviewMargin(inset: CGFloat = 0, relation: NSLayoutConstraint.Relation = .equal) -> NSLayoutConstraint {
|
|
136
|
+
return _pin(to: item.superview!, attribute: attribute.toMargin, inset: inset, relation: relation)
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/// Pins the edge to the respected edges of the given container.
|
|
140
|
+
@discardableResult func pin(to container: LayoutItem, inset: CGFloat = 0, relation: NSLayoutConstraint.Relation = .equal) -> NSLayoutConstraint {
|
|
141
|
+
return _pin(to: container, attribute: attribute, inset: inset, relation: relation)
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/// Pins the edge to the safe area of the view controller. Falls back to
|
|
145
|
+
/// layout guides (`.topLayoutGuide` and `.bottomLayoutGuide` on iOS 10.
|
|
146
|
+
@discardableResult func pinToSafeArea(of vc: UIViewController, inset: CGFloat = 0, relation: NSLayoutConstraint.Relation = .equal) -> NSLayoutConstraint {
|
|
147
|
+
let item2: Any, attr2: NSLayoutConstraint.Attribute
|
|
148
|
+
if #available(iOS 11, tvOS 11, *) {
|
|
149
|
+
// Pin to `safeAreaLayoutGuide` on iOS 11
|
|
150
|
+
(item2, attr2) = (vc.view.safeAreaLayoutGuide, self.attribute)
|
|
151
|
+
} else {
|
|
152
|
+
switch self.attribute {
|
|
153
|
+
// Fall back to .topLayoutGuide and pin to it's .bottom.
|
|
154
|
+
case .top: (item2, attr2) = (vc.topLayoutGuide, .bottom)
|
|
155
|
+
// Fall back to .bottomLayoutGuide and pin to it's .top.
|
|
156
|
+
case .bottom: (item2, attr2) = (vc.bottomLayoutGuide, .top)
|
|
157
|
+
// There are no layout guides for .left and .right, so just pin
|
|
158
|
+
// to the superview instead.
|
|
159
|
+
default: (item2, attr2) = (vc.view!, self.attribute)
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return _pin(to: item2, attribute: attr2, inset: inset, relation: relation)
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// Pin the anchor to another layout item.
|
|
166
|
+
private func _pin(to item2: Any, attribute attr2: NSLayoutConstraint.Attribute, inset: CGFloat, relation: NSLayoutConstraint.Relation) -> NSLayoutConstraint {
|
|
167
|
+
// Invert attribute and relation in certain cases. The `pin` semantics
|
|
168
|
+
// are inspired by https://github.com/PureLayout/PureLayout
|
|
169
|
+
let isInverted = [.trailing, .right, .bottom].contains(attribute)
|
|
170
|
+
return Constraints.constrain(self, toItem: item2, attribute: attr2, offset: (isInverted ? -inset : inset), relation: (isInverted ? relation.inverted : relation))
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// MARK: - Anchors (AnchorType.Center)
|
|
175
|
+
|
|
176
|
+
extension Anchor where Type: AnchorType.Center {
|
|
177
|
+
/// Aligns the axis with a superview axis.
|
|
178
|
+
@discardableResult func alignWithSuperview(offset: CGFloat = 0, relation: NSLayoutConstraint.Relation = .equal) -> NSLayoutConstraint {
|
|
179
|
+
return align(with: Anchor<Type, Axis>(self.item.superview!, self.attribute) + offset, relation: relation)
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// MARK: - Anchors (AnchorType.Dimension)
|
|
184
|
+
|
|
185
|
+
extension Anchor where Type: AnchorType.Dimension {
|
|
186
|
+
/// Sets the dimension to a specific size.
|
|
187
|
+
@discardableResult func set(_ constant: CGFloat, relation: NSLayoutConstraint.Relation = .equal) -> NSLayoutConstraint {
|
|
188
|
+
return Constraints.constrain(item: item, attribute: attribute, relatedBy: relation, constant: constant)
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
@discardableResult func match<Axis>(_ anchor: Anchor<AnchorType.Dimension, Axis>, relation: NSLayoutConstraint.Relation = .equal) -> NSLayoutConstraint {
|
|
192
|
+
return Constraints.constrain(self, anchor, relation: relation)
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// MARK: - AnchorCollectionEdges
|
|
197
|
+
|
|
198
|
+
struct AnchorCollectionEdges {
|
|
199
|
+
internal let item: LayoutItem
|
|
200
|
+
internal let edges: [LayoutEdge]
|
|
201
|
+
private var anchors: [Anchor<AnchorType.Edge, Any>] { return edges.map { Anchor(item, $0.attribute) } }
|
|
202
|
+
|
|
203
|
+
/// Pins the edges of the view to the edges of the superview so the the view
|
|
204
|
+
/// fills the available space in a container.
|
|
205
|
+
@discardableResult func pinToSuperview(insets: UIEdgeInsets = .zero, relation: NSLayoutConstraint.Relation = .equal) -> [NSLayoutConstraint] {
|
|
206
|
+
return anchors.map { $0.pinToSuperview(inset: insets.inset(for: $0.attribute), relation: relation) }
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/// Pins the edges of the view to the margins of the superview so the the view
|
|
210
|
+
/// fills the available space in a container.
|
|
211
|
+
@discardableResult func pinToSuperviewMargins(insets: UIEdgeInsets = .zero, relation: NSLayoutConstraint.Relation = .equal) -> [NSLayoutConstraint] {
|
|
212
|
+
return anchors.map { $0.pinToSuperviewMargin(inset: insets.inset(for: $0.attribute), relation: relation) }
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/// Pins the edges of the view to the edges of the given view so the the
|
|
216
|
+
/// view fills the available space in a container.
|
|
217
|
+
@discardableResult func pin(to item2: LayoutItem, insets: UIEdgeInsets = .zero, relation: NSLayoutConstraint.Relation = .equal) -> [NSLayoutConstraint] {
|
|
218
|
+
return anchors.map { $0.pin(to: item2, inset: insets.inset(for: $0.attribute), relation: relation) }
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/// Pins the edges to the safe area of the view controller.
|
|
222
|
+
/// Falls back to layout guides on iOS 10.
|
|
223
|
+
@discardableResult func pinToSafeArea(of vc: UIViewController, insets: UIEdgeInsets = .zero, relation: NSLayoutConstraint.Relation = .equal) -> [NSLayoutConstraint] {
|
|
224
|
+
return anchors.map { $0.pinToSafeArea(of: vc, inset: insets.inset(for: $0.attribute), relation: relation) }
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// MARK: - AnchorCollectionCenter
|
|
229
|
+
|
|
230
|
+
struct AnchorCollectionCenter {
|
|
231
|
+
internal let x: Anchor<AnchorType.Center, AnchorAxis.Horizontal>
|
|
232
|
+
internal let y: Anchor<AnchorType.Center, AnchorAxis.Vertical>
|
|
233
|
+
|
|
234
|
+
/// Centers the view in the superview.
|
|
235
|
+
@discardableResult func alignWithSuperview() -> [NSLayoutConstraint] {
|
|
236
|
+
return [x.alignWithSuperview(), y.alignWithSuperview()]
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/// Makes the axis equal to the other collection of axis.
|
|
240
|
+
@discardableResult func align(with anchors: AnchorCollectionCenter) -> [NSLayoutConstraint] {
|
|
241
|
+
return [x.align(with: anchors.x), y.align(with: anchors.y)]
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
// MARK: - AnchorCollectionSize
|
|
247
|
+
|
|
248
|
+
struct AnchorCollectionSize {
|
|
249
|
+
internal let width: Anchor<AnchorType.Dimension, AnchorAxis.Horizontal>
|
|
250
|
+
internal let height: Anchor<AnchorType.Dimension, AnchorAxis.Vertical>
|
|
251
|
+
|
|
252
|
+
/// Set the size of item.
|
|
253
|
+
@discardableResult func set(_ size: CGSize, relation: NSLayoutConstraint.Relation = .equal) -> [NSLayoutConstraint] {
|
|
254
|
+
return [width.set(size.width, relation: relation), height.set(size.height, relation: relation)]
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/// Makes the size of the item equal to the size of the other item.
|
|
258
|
+
@discardableResult func match(_ anchors: AnchorCollectionSize, insets: CGSize = .zero, multiplier: CGFloat = 1, relation: NSLayoutConstraint.Relation = .equal) -> [NSLayoutConstraint] {
|
|
259
|
+
return [width.match(anchors.width * multiplier - insets.width, relation: relation),
|
|
260
|
+
height.match(anchors.height * multiplier - insets.height, relation: relation)]
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
// MARK: - Constraints
|
|
265
|
+
|
|
266
|
+
final class Constraints {
|
|
267
|
+
var constraints = [NSLayoutConstraint]()
|
|
268
|
+
|
|
269
|
+
/// All of the constraints created in the given closure are automatically
|
|
270
|
+
/// activated at the same time. This is more efficient then installing them
|
|
271
|
+
/// one-be-one. More importantly, it allows to make changes to the constraints
|
|
272
|
+
/// before they are installed (e.g. change `priority`).
|
|
273
|
+
@discardableResult init(_ closure: () -> Void) {
|
|
274
|
+
Constraints._stack.append(self)
|
|
275
|
+
closure() // create constraints
|
|
276
|
+
Constraints._stack.removeLast()
|
|
277
|
+
NSLayoutConstraint.activate(constraints)
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/// Creates and automatically installs a constraint.
|
|
281
|
+
internal static func constrain(item item1: Any, attribute attr1: NSLayoutConstraint.Attribute, relatedBy relation: NSLayoutConstraint.Relation = .equal, toItem item2: Any? = nil, attribute attr2: NSLayoutConstraint.Attribute? = nil, multiplier: CGFloat = 1, constant: CGFloat = 0) -> NSLayoutConstraint {
|
|
282
|
+
precondition(Thread.isMainThread, "Yalta APIs can only be used from the main thread")
|
|
283
|
+
(item1 as? UIView)?.translatesAutoresizingMaskIntoConstraints = false
|
|
284
|
+
let constraint = NSLayoutConstraint(item: item1, attribute: attr1, relatedBy: relation, toItem: item2, attribute: attr2 ?? .notAnAttribute, multiplier: multiplier, constant: constant)
|
|
285
|
+
_install(constraint)
|
|
286
|
+
return constraint
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
/// Creates and automatically installs a constraint between two anchors.
|
|
290
|
+
internal static func constrain<T1, A1, T2, A2>(_ lhs: Anchor<T1, A1>, _ rhs: Anchor<T2, A2>, offset: CGFloat = 0, multiplier: CGFloat = 1, relation: NSLayoutConstraint.Relation = .equal) -> NSLayoutConstraint {
|
|
291
|
+
return constrain(item: lhs.item, attribute: lhs.attribute, relatedBy: relation, toItem: rhs.item, attribute: rhs.attribute, multiplier: (multiplier / lhs.multiplier) * rhs.multiplier, constant: offset - lhs.offset + rhs.offset)
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/// Creates and automatically installs a constraint between an anchor and
|
|
295
|
+
/// a given item.
|
|
296
|
+
internal static func constrain<T1, A1>(_ lhs: Anchor<T1, A1>, toItem item2: Any?, attribute attr2: NSLayoutConstraint.Attribute?, offset: CGFloat = 0, multiplier: CGFloat = 1, relation: NSLayoutConstraint.Relation = .equal) -> NSLayoutConstraint {
|
|
297
|
+
return constrain(item: lhs.item, attribute: lhs.attribute, relatedBy: relation, toItem: item2, attribute: attr2, multiplier: multiplier / lhs.multiplier, constant: offset - lhs.offset)
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
private static var _stack = [Constraints]() // this is what enabled constraint auto-installing
|
|
301
|
+
|
|
302
|
+
private static func _install(_ constraint: NSLayoutConstraint) {
|
|
303
|
+
if _stack.isEmpty { // not creating a group of constraints
|
|
304
|
+
constraint.isActive = true
|
|
305
|
+
} else { // remember which constaints to install when group is completed
|
|
306
|
+
let group = _stack.last!
|
|
307
|
+
group.constraints.append(constraint)
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
// MARK: - UIView + Constraints
|
|
313
|
+
|
|
314
|
+
extension UIView {
|
|
315
|
+
@discardableResult @nonobjc func addSubview(_ a: UIView, constraints: (LayoutProxy<UIView>) -> Void) -> Constraints {
|
|
316
|
+
addSubview(a)
|
|
317
|
+
return Constraints(for: a, constraints)
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
@discardableResult @nonobjc func addSubview(_ a: UIView, _ b: UIView, constraints: (LayoutProxy<UIView>, LayoutProxy<UIView>) -> Void) -> Constraints {
|
|
321
|
+
[a, b].forEach { addSubview($0) }
|
|
322
|
+
return Constraints(for: a, b, constraints)
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
@discardableResult @nonobjc func addSubview(_ a: UIView, _ b: UIView, _ c: UIView, constraints: (LayoutProxy<UIView>, LayoutProxy<UIView>, LayoutProxy<UIView>) -> Void) -> Constraints {
|
|
326
|
+
[a, b, c].forEach { addSubview($0) }
|
|
327
|
+
return Constraints(for: a, b, c, constraints)
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
@discardableResult @nonobjc func addSubview(_ a: UIView, _ b: UIView, _ c: UIView, _ d: UIView, constraints: (LayoutProxy<UIView>, LayoutProxy<UIView>, LayoutProxy<UIView>, LayoutProxy<UIView>) -> Void) -> Constraints {
|
|
331
|
+
[a, b, c, d].forEach { addSubview($0) }
|
|
332
|
+
return Constraints(for: a, b, c, d, constraints)
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
// MARK: - Constraints (Arity)
|
|
337
|
+
|
|
338
|
+
extension Constraints {
|
|
339
|
+
@discardableResult convenience init<A: LayoutItem>(for a: A, _ closure: (LayoutProxy<A>) -> Void) {
|
|
340
|
+
self.init { closure(a.al) }
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
@discardableResult convenience init<A: LayoutItem, B: LayoutItem>(for a: A, _ b: B, _ closure: (LayoutProxy<A>, LayoutProxy<B>) -> Void) {
|
|
344
|
+
self.init { closure(a.al, b.al) }
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
@discardableResult convenience init<A: LayoutItem, B: LayoutItem, C: LayoutItem>(for a: A, _ b: B, _ c: C, _ closure: (LayoutProxy<A>, LayoutProxy<B>, LayoutProxy<C>) -> Void) {
|
|
348
|
+
self.init { closure(a.al, b.al, c.al) }
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
@discardableResult convenience init<A: LayoutItem, B: LayoutItem, C: LayoutItem, D: LayoutItem>(for a: A, _ b: B, _ c: C, _ d: D, _ closure: (LayoutProxy<A>, LayoutProxy<B>, LayoutProxy<C>, LayoutProxy<D>) -> Void) {
|
|
352
|
+
self.init { closure(a.al, b.al, c.al, d.al) }
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
// MARK: - Misc
|
|
357
|
+
|
|
358
|
+
enum LayoutEdge {
|
|
359
|
+
case top, bottom, leading, trailing, left, right
|
|
360
|
+
|
|
361
|
+
internal var attribute: NSLayoutConstraint.Attribute {
|
|
362
|
+
switch self {
|
|
363
|
+
case .top: return .top; case .bottom: return .bottom
|
|
364
|
+
case .leading: return .leading; case .trailing: return .trailing
|
|
365
|
+
case .left: return .left; case .right: return .right
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
internal extension NSLayoutConstraint.Attribute {
|
|
371
|
+
var toMargin: NSLayoutConstraint.Attribute {
|
|
372
|
+
switch self {
|
|
373
|
+
case .top: return .topMargin; case .bottom: return .bottomMargin
|
|
374
|
+
case .leading: return .leadingMargin; case .trailing: return .trailingMargin
|
|
375
|
+
case .left: return .leftMargin case .right: return .rightMargin
|
|
376
|
+
default: return self
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
internal extension NSLayoutConstraint.Relation {
|
|
382
|
+
var inverted: NSLayoutConstraint.Relation {
|
|
383
|
+
switch self {
|
|
384
|
+
case .greaterThanOrEqual: return .lessThanOrEqual
|
|
385
|
+
case .lessThanOrEqual: return .greaterThanOrEqual
|
|
386
|
+
case .equal: return self
|
|
387
|
+
@unknown default:
|
|
388
|
+
return self
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
internal extension UIEdgeInsets {
|
|
394
|
+
func inset(for attribute: NSLayoutConstraint.Attribute) -> CGFloat {
|
|
395
|
+
switch attribute {
|
|
396
|
+
case .top: return top; case .bottom: return bottom
|
|
397
|
+
case .left, .leading: return left
|
|
398
|
+
case .right, .trailing: return right
|
|
399
|
+
default: return 0
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
// MARK: - Deprecated
|
|
405
|
+
|
|
406
|
+
extension Anchor where Type: AnchorType.Alignment {
|
|
407
|
+
@available(*, deprecated, message: "Please use operators instead, e.g. `view.top.align(with: view.bottom * 2 + 10)`.")
|
|
408
|
+
@discardableResult func align<Type: AnchorType.Alignment>(with anchor: Anchor<Type, Axis>, offset: CGFloat = 0, multiplier: CGFloat = 1, relation: NSLayoutConstraint.Relation = .equal) -> NSLayoutConstraint {
|
|
409
|
+
return Constraints.constrain(self, anchor, offset: offset, multiplier: multiplier, relation: relation)
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
extension Anchor where Type: AnchorType.Dimension {
|
|
414
|
+
@available(*, deprecated, message: "Please use operators instead, e.g. `view.width.match(view.height * 2 + 10)`.")
|
|
415
|
+
@discardableResult func match<Axis>(_ anchor: Anchor<AnchorType.Dimension, Axis>, offset: CGFloat = 0, multiplier: CGFloat = 1, relation: NSLayoutConstraint.Relation = .equal) -> NSLayoutConstraint {
|
|
416
|
+
return Constraints.constrain(self, anchor, offset: offset, multiplier: multiplier, relation: relation)
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
#endif // os(iOS) || os(tvOS) || os(watchOS)
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// Copyright © 2021 Lunabee Studio
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
//
|
|
15
|
+
// BottomSheetConstant.swift
|
|
16
|
+
// LBBottomSheet
|
|
17
|
+
//
|
|
18
|
+
// Created by Lunabee Studio / Date - 12/10/2021 - for the LBBottomSheet Swift Package.
|
|
19
|
+
//
|
|
20
|
+
|
|
21
|
+
import CoreGraphics
|
|
22
|
+
|
|
23
|
+
/// Bottom sheet constants.
|
|
24
|
+
public enum BottomSheetConstant {
|
|
25
|
+
/// Bottom sheet animation constants.
|
|
26
|
+
public enum Animation {
|
|
27
|
+
/// Bottom sheet animation elasticity functions.
|
|
28
|
+
public enum Elasticity {
|
|
29
|
+
/// Bottom sheet logarithmic animation function.
|
|
30
|
+
///
|
|
31
|
+
/// Here is the implementation of this function:
|
|
32
|
+
/// ```swift
|
|
33
|
+
/// let baseFunction: (_ x: CGFloat) -> CGFloat = { (2.0 * log($0 + 3.0) / log(2.0)) }
|
|
34
|
+
/// return baseFunction(x) - baseFunction(0.0)
|
|
35
|
+
/// ```
|
|
36
|
+
///
|
|
37
|
+
/// - Parameters:
|
|
38
|
+
/// - x: The abscissa: The bottom sheet will give the height slice that has to be computed to create the elacticity effect.
|
|
39
|
+
/// - Returns: The ordonate: The height value to be applied to be used by the bottom sheet to calculate its full height.
|
|
40
|
+
public static let logarithmic: (_ x: CGFloat) -> CGFloat = { x -> CGFloat in
|
|
41
|
+
let baseFunction: (_ x: CGFloat) -> CGFloat = { (2.0 * log($0 + 3.0) / log(2.0)) }
|
|
42
|
+
return baseFunction(x) - baseFunction(0.0)
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
internal static let preferredHeightVariableName: String = "preferredHeightInBottomSheet"
|
|
48
|
+
}
|