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,33 @@
|
|
|
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
|
+
// CACornerMask+Extensions.swift
|
|
16
|
+
// LBBottomSheet
|
|
17
|
+
//
|
|
18
|
+
// Created by Lunabee Studio / Date - 12/10/2021 - for the LBBottomSheet Swift Package.
|
|
19
|
+
//
|
|
20
|
+
|
|
21
|
+
import UIKit
|
|
22
|
+
|
|
23
|
+
public extension CACornerMask {
|
|
24
|
+
static var lbbsAll: CACornerMask { [.layerMinXMinYCorner, .layerMaxXMinYCorner, .layerMinXMaxYCorner, .layerMaxXMaxYCorner] }
|
|
25
|
+
static var lbbsTop: CACornerMask { [.layerMinXMinYCorner, .layerMaxXMinYCorner] }
|
|
26
|
+
static var lbbsBottom: CACornerMask { [.layerMinXMaxYCorner, .layerMaxXMaxYCorner] }
|
|
27
|
+
static var lbbsNone: CACornerMask { [] }
|
|
28
|
+
|
|
29
|
+
static var lbbsTopLeft: CACornerMask { .layerMinXMinYCorner }
|
|
30
|
+
static var lbbsTopRight: CACornerMask { .layerMaxXMinYCorner }
|
|
31
|
+
static var lbbsBottomLeft: CACornerMask { .layerMinXMaxYCorner }
|
|
32
|
+
static var lbbsBottomRight: CACornerMask { .layerMaxXMaxYCorner }
|
|
33
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
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
|
+
// Mirror+Extension.swift
|
|
16
|
+
// LBBottomSheet
|
|
17
|
+
//
|
|
18
|
+
// Created by Lunabee Studio / Date - 14/10/2021 - for the LBBottomSheet Swift Package.
|
|
19
|
+
//
|
|
20
|
+
|
|
21
|
+
import Foundation
|
|
22
|
+
|
|
23
|
+
internal extension Mirror {
|
|
24
|
+
static func lbbsGetTypesOfProperties(in class: NSObject.Type) -> [String]? {
|
|
25
|
+
var count: UInt32 = UInt32()
|
|
26
|
+
guard let properties = class_copyPropertyList(`class`, &count) else { return nil }
|
|
27
|
+
var names: [String] = []
|
|
28
|
+
for i in 0..<Int(count) {
|
|
29
|
+
let property: objc_property_t = properties[i]
|
|
30
|
+
guard let name = lbbsGetNameOf(property: property) else { continue }
|
|
31
|
+
names.append(name)
|
|
32
|
+
}
|
|
33
|
+
free(properties)
|
|
34
|
+
return names
|
|
35
|
+
}
|
|
36
|
+
static func isPreferredHeightInBottomSheetDeclared(in class: NSObject.Type) -> Bool {
|
|
37
|
+
let propertiesName: [String] = lbbsGetTypesOfProperties(in: `class`) ?? []
|
|
38
|
+
return propertiesName.contains(BottomSheetConstant.preferredHeightVariableName)
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
private extension Mirror {
|
|
43
|
+
static func lbbsGetNameOf(property: objc_property_t) -> String? {
|
|
44
|
+
guard let name: NSString = NSString(utf8String: property_getName(property)) else { return nil }
|
|
45
|
+
return name as String
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
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
|
+
// UIApplication+Extensions.swift
|
|
16
|
+
// LBBottomSheet
|
|
17
|
+
//
|
|
18
|
+
// Created by Lunabee Studio / Date - 12/10/2021 - for the LBBottomSheet Swift Package.
|
|
19
|
+
//
|
|
20
|
+
|
|
21
|
+
import UIKit
|
|
22
|
+
|
|
23
|
+
internal extension UIApplication {
|
|
24
|
+
/// This will return the first connected scene key window of the main screen if it exists.
|
|
25
|
+
var lbbsKeySceneWindow: UIWindow? {
|
|
26
|
+
if #available(iOS 13.0, *) {
|
|
27
|
+
return UIApplication.shared.connectedScenes.compactMap { $0 as? UIWindowScene }
|
|
28
|
+
.filter { $0.screen === UIScreen.main }
|
|
29
|
+
.first?.windows
|
|
30
|
+
.filter { $0.isKeyWindow }.first ?? UIApplication.shared.keyWindow
|
|
31
|
+
} else {
|
|
32
|
+
return UIApplication.shared.keyWindow
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
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
|
+
// UIColor+Extensions.swift
|
|
16
|
+
// LBBottomSheet
|
|
17
|
+
//
|
|
18
|
+
// Created by Lunabee Studio / Date - 12/10/2021 - for the LBBottomSheet Swift Package.
|
|
19
|
+
//
|
|
20
|
+
|
|
21
|
+
import UIKit
|
|
22
|
+
|
|
23
|
+
public extension UIColor {
|
|
24
|
+
static var lbbsDefaultDimmingBackgroundColor: UIColor {
|
|
25
|
+
if #available(iOS 13.0, *) {
|
|
26
|
+
return UIColor.init(dynamicProvider: {
|
|
27
|
+
switch $0.userInterfaceStyle {
|
|
28
|
+
case .dark:
|
|
29
|
+
return .white.withAlphaComponent(0.1)
|
|
30
|
+
default:
|
|
31
|
+
return .black.withAlphaComponent(0.4)
|
|
32
|
+
}
|
|
33
|
+
})
|
|
34
|
+
} else {
|
|
35
|
+
return .black.withAlphaComponent(0.4)
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
static var lbbsDefaultShadowColor: UIColor {
|
|
39
|
+
if #available(iOS 13.0, *) {
|
|
40
|
+
return UIColor.init(dynamicProvider: {
|
|
41
|
+
switch $0.userInterfaceStyle {
|
|
42
|
+
case .dark:
|
|
43
|
+
return .gray
|
|
44
|
+
case .light, .unspecified:
|
|
45
|
+
return .black
|
|
46
|
+
@unknown default:
|
|
47
|
+
return .black
|
|
48
|
+
}
|
|
49
|
+
})
|
|
50
|
+
} else {
|
|
51
|
+
return .black
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
static var lbbsDefaultGrabberColor: UIColor {
|
|
55
|
+
if #available(iOS 13.0, *) {
|
|
56
|
+
return .tertiaryLabel
|
|
57
|
+
} else {
|
|
58
|
+
return .lightGray
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
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
|
+
// UIGestureRecognizer+Extensions.swift
|
|
16
|
+
// LBBottomSheet
|
|
17
|
+
//
|
|
18
|
+
// Created by Lunabee Studio / Date - 12/10/2021 - for the LBBottomSheet Swift Package.
|
|
19
|
+
//
|
|
20
|
+
|
|
21
|
+
import UIKit
|
|
22
|
+
|
|
23
|
+
internal extension UIGestureRecognizer {
|
|
24
|
+
func lbbsCancel() {
|
|
25
|
+
isEnabled = false
|
|
26
|
+
isEnabled = true
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
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
|
+
// UIScreen+Extension.swift
|
|
16
|
+
// LBBottomSheet
|
|
17
|
+
//
|
|
18
|
+
// Created by Lunabee Studio / Date - 09/11/2021 - for the LBBottomSheet Swift Package.
|
|
19
|
+
//
|
|
20
|
+
|
|
21
|
+
import UIKit
|
|
22
|
+
|
|
23
|
+
public extension UIScreen {
|
|
24
|
+
var lbbsCornerRadius: CGFloat {
|
|
25
|
+
guard let radius = UIScreen.main.value(forKey: ["Radius", "Corner", "display", "_"].reversed().joined()) as? CGFloat else { return 0.0 }
|
|
26
|
+
return radius - 1.0
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
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
|
+
// UIViewController+Extension.swift
|
|
16
|
+
// LBBottomSheet
|
|
17
|
+
//
|
|
18
|
+
// Created by Lunabee Studio / Date - 12/10/2021 - for the LBBottomSheet Swift Package.
|
|
19
|
+
//
|
|
20
|
+
|
|
21
|
+
import UIKit
|
|
22
|
+
|
|
23
|
+
internal extension UIScrollView {
|
|
24
|
+
var lbbsContentHeight: CGFloat { contentInset.top + contentSize.height + contentInset.bottom }
|
|
25
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
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
|
+
// UIView+Extension.swift
|
|
16
|
+
// LBBottomSheet
|
|
17
|
+
//
|
|
18
|
+
// Created by Lunabee Studio / Date - 14/10/2021 - for the LBBottomSheet Swift Package.
|
|
19
|
+
//
|
|
20
|
+
|
|
21
|
+
import UIKit
|
|
22
|
+
|
|
23
|
+
internal extension UIView {
|
|
24
|
+
func lbbsAddFullSubview(_ subview: UIView, belowSubview: UIView? = nil) {
|
|
25
|
+
if let belowSubview = belowSubview {
|
|
26
|
+
insertSubview(subview, belowSubview: belowSubview)
|
|
27
|
+
} else {
|
|
28
|
+
addSubview(subview)
|
|
29
|
+
}
|
|
30
|
+
subview.translatesAutoresizingMaskIntoConstraints = false
|
|
31
|
+
subview.topAnchor.constraint(equalTo: topAnchor, constant: 0.0).isActive = true
|
|
32
|
+
subview.bottomAnchor.constraint(equalTo: bottomAnchor, constant: 0.0).isActive = true
|
|
33
|
+
subview.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 0.0).isActive = true
|
|
34
|
+
subview.trailingAnchor.constraint(equalTo: trailingAnchor, constant: 0.0).isActive = true
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
func lbbsGetSubviews<T: UIView>() -> [T] {
|
|
38
|
+
var foundSubviews: [T] = []
|
|
39
|
+
if let subview = self as? T { foundSubviews.append(subview) }
|
|
40
|
+
self.subviews.forEach {
|
|
41
|
+
foundSubviews += $0.lbbsGetSubviews() as [T]
|
|
42
|
+
if let subview = $0 as? T { foundSubviews.append(subview) }
|
|
43
|
+
}
|
|
44
|
+
return foundSubviews
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
func lbbsGetFirstTableOrCollectionView() -> UIScrollView? {
|
|
48
|
+
let tableViews: [UITableView] = lbbsGetSubviews()
|
|
49
|
+
let collectionViews: [UICollectionView] = lbbsGetSubviews()
|
|
50
|
+
return tableViews.first ?? collectionViews.first
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
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
|
+
// UIViewController+Extension.swift
|
|
16
|
+
// LBBottomSheet
|
|
17
|
+
//
|
|
18
|
+
// Created by Lunabee Studio / Date - 12/10/2021 - for the LBBottomSheet Swift Package.
|
|
19
|
+
//
|
|
20
|
+
|
|
21
|
+
import UIKit
|
|
22
|
+
|
|
23
|
+
// MARK: - Public extensions -
|
|
24
|
+
public extension UIViewController {
|
|
25
|
+
/// Find the BottomSheetController embedding the current controller.
|
|
26
|
+
/// It is working like `navigationController` or others.
|
|
27
|
+
var bottomSheetController: BottomSheetController? {
|
|
28
|
+
var parentController: UIViewController? = self
|
|
29
|
+
while let controller = parentController?.parent {
|
|
30
|
+
parentController = controller
|
|
31
|
+
if parentController is BottomSheetController {
|
|
32
|
+
break
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return parentController as? BottomSheetController
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/// Presents a given controller as a bottom sheet.
|
|
39
|
+
/// - Parameters:
|
|
40
|
+
/// - controller: The controller to present in a bottom sheet.
|
|
41
|
+
/// - positionDelegate: A `UIViewController` being a <doc:LBBottomSheet/BottomSheetPositionDelegate> to get the bottom sheet position updates if it needs to update its content bottom inset.
|
|
42
|
+
/// - theme: A Theme to customize the bottom sheet appearance.
|
|
43
|
+
/// - behavior: A Behavior to customize the way the bottom sheet behaves.
|
|
44
|
+
/// - Returns: A reference to the created `BottomSheetController`.
|
|
45
|
+
@discardableResult
|
|
46
|
+
func presentAsBottomSheet(_ controller: UIViewController,
|
|
47
|
+
positionDelegate: BottomSheetPositionDelegate? = nil,
|
|
48
|
+
bottomSheetInteractionDelegate: BottomSheetInteractionDelegate? = nil,
|
|
49
|
+
theme: BottomSheetController.Theme = BottomSheetController.Theme(),
|
|
50
|
+
behavior: BottomSheetController.Behavior = BottomSheetController.Behavior()) -> BottomSheetController {
|
|
51
|
+
let bottomSheetController: BottomSheetController = .controller(bottomSheetChild: controller,
|
|
52
|
+
bottomSheetPositionDelegate: positionDelegate,
|
|
53
|
+
bottomSheetInteractionDelegate: bottomSheetInteractionDelegate,
|
|
54
|
+
theme: theme,
|
|
55
|
+
behavior: behavior)
|
|
56
|
+
present(bottomSheetController, animated: false, completion: nil)
|
|
57
|
+
return bottomSheetController
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/// Use this function to dismiss the top presented bottom sheet.
|
|
61
|
+
/// If the top presented controller is not a bottom sheet, nothing will happen.
|
|
62
|
+
/// - Parameters:
|
|
63
|
+
/// - completion: An optional completion handler to be called when the bottom sheet is dismissed.
|
|
64
|
+
func dismissBottomSheet(_ completion: (() -> Void)? = nil) {
|
|
65
|
+
guard let controller = lbbsTopPresentedController as? BottomSheetController else {
|
|
66
|
+
completion?()
|
|
67
|
+
return
|
|
68
|
+
}
|
|
69
|
+
controller.dismiss(completion)
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// MARK: - Internal extensions -
|
|
74
|
+
internal extension UIViewController {
|
|
75
|
+
var lbbsTopPresentedController: UIViewController {
|
|
76
|
+
var presentedController: UIViewController = self
|
|
77
|
+
while let controller = presentedController.presentedViewController {
|
|
78
|
+
presentedController = controller
|
|
79
|
+
}
|
|
80
|
+
return presentedController
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
func lbbsRearControllerTopInset(includeNavigationBar: Bool = true) -> CGFloat {
|
|
84
|
+
var topInset: CGFloat = UIApplication.shared.lbbsKeySceneWindow?.safeAreaInsets.top ?? 0.0
|
|
85
|
+
if let navController = presentingViewController as? UINavigationController ?? presentingViewController?.navigationController, !navController.isNavigationBarHidden && includeNavigationBar {
|
|
86
|
+
topInset = navController.navigationBar.frame.maxY + 8.0
|
|
87
|
+
}
|
|
88
|
+
return topInset
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
func lbbsAddChildViewController(_ childController: UIViewController, containerView: UIView) {
|
|
92
|
+
addChild(childController)
|
|
93
|
+
containerView.lbbsAddFullSubview(childController.view)
|
|
94
|
+
childController.didMove(toParent: self)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
func lbbsFindControllerDeclaringPreferredHeightInBottomSheet() -> UIViewController? {
|
|
98
|
+
if Mirror.isPreferredHeightInBottomSheetDeclared(in: type(of: self)) {
|
|
99
|
+
return self
|
|
100
|
+
} else {
|
|
101
|
+
return children.first { Mirror.isPreferredHeightInBottomSheetDeclared(in: type(of: $0)) }
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#import <React/RCTViewManager.h>
|