@lodev09/react-native-true-sheet 0.4.0 → 0.4.1

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.
@@ -13,14 +13,23 @@ extension UISheetPresentationController.Detent.Identifier {
13
13
 
14
14
  @available(iOS 15.0, *)
15
15
  extension UIViewController {
16
+ private func minValue(_ x: CGFloat?, _ maxHeight: CGFloat?) -> CGFloat {
17
+ let x = x ?? 0
18
+ guard let maxHeight else {
19
+ return x
20
+ }
21
+
22
+ return min(x, maxHeight)
23
+ }
24
+
16
25
  private func detentFor(identifier: UISheetPresentationController.Detent.Identifier,
17
- with maxHeight: CGFloat,
26
+ with maxHeight: CGFloat?,
18
27
  _ resolution: @escaping (CGFloat) -> Void) -> UISheetPresentationController.Detent {
19
28
  switch identifier {
20
29
  case .large:
21
30
  if #available(iOS 16.0, *) {
22
31
  return .custom(identifier: .large) { context in
23
- let value = min(UISheetPresentationController.Detent.large().resolvedValue(in: context) ?? 0, maxHeight)
32
+ let value = self.minValue(UISheetPresentationController.Detent.large().resolvedValue(in: context), maxHeight)
24
33
  resolution(value)
25
34
  return value
26
35
  }
@@ -31,7 +40,7 @@ extension UIViewController {
31
40
  case .medium:
32
41
  if #available(iOS 16.0, *) {
33
42
  return .custom(identifier: .medium) { context in
34
- let value = min(UISheetPresentationController.Detent.medium().resolvedValue(in: context) ?? 0, maxHeight)
43
+ let value = self.minValue(UISheetPresentationController.Detent.medium().resolvedValue(in: context), maxHeight)
35
44
  resolution(value)
36
45
  return value
37
46
  }
@@ -39,7 +48,7 @@ extension UIViewController {
39
48
  case .small:
40
49
  if #available(iOS 16.0, *) {
41
50
  return .custom { context in
42
- let value = min(0.25 * context.maximumDetentValue, maxHeight)
51
+ let value = self.minValue(0.25 * context.maximumDetentValue, maxHeight)
43
52
  resolution(value)
44
53
  return value
45
54
  }
@@ -55,14 +64,14 @@ extension UIViewController {
55
64
  /// Get the custom detent based on the given size and view frame size
56
65
  func detentFor(_ anySize: Any,
57
66
  with height: CGFloat?,
58
- with maxHeight: CGFloat,
67
+ with maxHeight: CGFloat?,
59
68
  _ resolution: @escaping (String, CGFloat) -> Void) -> UISheetPresentationController.Detent {
60
69
  let id = "custom-\(anySize)"
61
70
 
62
71
  if let floatSize = anySize as? CGFloat {
63
72
  if #available(iOS 16.0, *) {
64
73
  return .custom(identifier: identifier(from: id)) { context in
65
- let value = min(floatSize, context.maximumDetentValue, maxHeight)
74
+ let value = min(floatSize, self.minValue(context.maximumDetentValue, maxHeight))
66
75
  resolution(id, value)
67
76
  return value
68
77
  }
@@ -91,7 +100,7 @@ extension UIViewController {
91
100
  if #available(iOS 16.0, *) {
92
101
  if stringSize == "auto" {
93
102
  return .custom(identifier: identifier(from: id)) { context in
94
- let value = min(height ?? context.maximumDetentValue / 2, context.maximumDetentValue, maxHeight)
103
+ let value = min(height ?? context.maximumDetentValue / 2, self.minValue(context.maximumDetentValue, maxHeight))
95
104
  resolution(id, value)
96
105
  return value
97
106
  }
@@ -101,7 +110,7 @@ extension UIViewController {
101
110
  let floatSize = CGFloat((stringSize as NSString).floatValue)
102
111
  if floatSize > 0.0 {
103
112
  return .custom(identifier: identifier(from: id)) { context in
104
- let value = min((floatSize / 100) * context.maximumDetentValue, context.maximumDetentValue, maxHeight)
113
+ let value = min((floatSize / 100) * context.maximumDetentValue, self.minValue(context.maximumDetentValue, maxHeight))
105
114
  resolution(id, value)
106
115
  return value
107
116
  }
@@ -82,7 +82,7 @@ class TrueSheetViewController: UIViewController, UISheetPresentationControllerDe
82
82
  var detents: [UISheetPresentationController.Detent] = []
83
83
 
84
84
  for (index, size) in sizes.enumerated() {
85
- let detent = detentFor(size, with: contentHeight, with: maxHeight ?? view.frame.height) { id, value in
85
+ let detent = detentFor(size, with: contentHeight, with: maxHeight) { id, value in
86
86
  self.detentValues[id] = SizeInfo(index: index, value: value)
87
87
  }
88
88
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lodev09/react-native-true-sheet",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "description": "The true native bottom sheet. 💩",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",