@lodev09/react-native-true-sheet 0.3.1 → 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.
- package/android/src/main/java/com/lodev09/truesheet/TrueSheetView.kt +11 -2
- package/android/src/main/java/com/lodev09/truesheet/TrueSheetViewManager.kt +15 -13
- package/android/src/main/java/com/lodev09/truesheet/TrueSheetViewModule.kt +3 -3
- package/android/src/main/java/com/lodev09/truesheet/core/SheetBehavior.kt +23 -26
- package/android/src/main/java/com/lodev09/truesheet/core/Utils.kt +58 -0
- package/ios/Extensions/UIViewController+detentForSize.swift +28 -15
- package/ios/TrueSheetView.swift +11 -5
- package/ios/TrueSheetViewController.swift +5 -2
- package/ios/TrueSheetViewManager.m +2 -4
- package/lib/commonjs/TrueSheet.js +1 -0
- package/lib/commonjs/TrueSheet.js.map +1 -1
- package/lib/module/TrueSheet.js +1 -0
- package/lib/module/TrueSheet.js.map +1 -1
- package/lib/typescript/src/TrueSheet.d.ts.map +1 -1
- package/lib/typescript/src/types.d.ts +4 -0
- package/lib/typescript/src/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/TrueSheet.tsx +2 -0
- package/src/types.ts +5 -0
- package/android/src/main/java/com/lodev09/truesheet/utils/maxSize.kt +0 -49
- package/android/src/main/java/com/lodev09/truesheet/utils/toDIP.kt +0 -5
- package/android/src/main/java/com/lodev09/truesheet/utils/withPromise.kt +0 -13
|
@@ -19,7 +19,7 @@ import com.lodev09.truesheet.core.PresentEvent
|
|
|
19
19
|
import com.lodev09.truesheet.core.RootViewGroup
|
|
20
20
|
import com.lodev09.truesheet.core.SheetBehavior
|
|
21
21
|
import com.lodev09.truesheet.core.SizeChangeEvent
|
|
22
|
-
import com.lodev09.truesheet.
|
|
22
|
+
import com.lodev09.truesheet.core.Utils
|
|
23
23
|
|
|
24
24
|
class TrueSheetView(context: Context) :
|
|
25
25
|
ViewGroup(context),
|
|
@@ -63,7 +63,9 @@ class TrueSheetView(context: Context) :
|
|
|
63
63
|
|
|
64
64
|
// Configure Sheet events
|
|
65
65
|
sheetBehavior.apply {
|
|
66
|
-
|
|
66
|
+
|
|
67
|
+
// Set our default max height
|
|
68
|
+
maxSheetSize = Utils.maxSize(context)
|
|
67
69
|
|
|
68
70
|
addBottomSheetCallback(
|
|
69
71
|
object : BottomSheetBehavior.BottomSheetCallback() {
|
|
@@ -103,6 +105,8 @@ class TrueSheetView(context: Context) :
|
|
|
103
105
|
// Configure Sheet Dialog
|
|
104
106
|
sheetDialog.apply {
|
|
105
107
|
setOnShowListener {
|
|
108
|
+
|
|
109
|
+
// Initialize footer y
|
|
106
110
|
UiThreadUtil.runOnUiThread {
|
|
107
111
|
footerView?.let {
|
|
108
112
|
val sheetView = sheetLayout.parent as ViewGroup
|
|
@@ -205,6 +209,11 @@ class TrueSheetView(context: Context) :
|
|
|
205
209
|
sheetDialog.dismiss()
|
|
206
210
|
}
|
|
207
211
|
|
|
212
|
+
fun setMaxHeight(height: Int) {
|
|
213
|
+
sheetBehavior.maxSheetHeight = height
|
|
214
|
+
sheetBehavior.configure(sizes)
|
|
215
|
+
}
|
|
216
|
+
|
|
208
217
|
fun setSizes(newSizes: Array<Any>) {
|
|
209
218
|
sizes = newSizes
|
|
210
219
|
sheetBehavior.configure(sizes)
|
|
@@ -10,6 +10,7 @@ import com.facebook.react.uimanager.annotations.ReactProp
|
|
|
10
10
|
import com.lodev09.truesheet.core.DismissEvent
|
|
11
11
|
import com.lodev09.truesheet.core.PresentEvent
|
|
12
12
|
import com.lodev09.truesheet.core.SizeChangeEvent
|
|
13
|
+
import com.lodev09.truesheet.core.Utils
|
|
13
14
|
|
|
14
15
|
class TrueSheetViewManager : ViewGroupManager<TrueSheetView>() {
|
|
15
16
|
override fun getName() = TAG
|
|
@@ -28,22 +29,23 @@ class TrueSheetViewManager : ViewGroupManager<TrueSheetView>() {
|
|
|
28
29
|
.put(SizeChangeEvent.EVENT_NAME, MapBuilder.of("registrationName", "onSizeChange"))
|
|
29
30
|
.build()
|
|
30
31
|
|
|
32
|
+
@ReactProp(name = "maxHeight")
|
|
33
|
+
fun setMaxHeight(view: TrueSheetView, height: Double) {
|
|
34
|
+
view.setMaxHeight(Utils.toPixel(height))
|
|
35
|
+
}
|
|
36
|
+
|
|
31
37
|
@ReactProp(name = "sizes")
|
|
32
|
-
fun setSizes(view: TrueSheetView, sizes: ReadableArray
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
else -> Log.d(TAG, "Invalid type")
|
|
40
|
-
}
|
|
38
|
+
fun setSizes(view: TrueSheetView, sizes: ReadableArray) {
|
|
39
|
+
val result = ArrayList<Any>()
|
|
40
|
+
for (i in 0 until minOf(sizes.size(), 3)) {
|
|
41
|
+
when (sizes.getType(i)) {
|
|
42
|
+
ReadableType.Number -> result.add(sizes.getDouble(i))
|
|
43
|
+
ReadableType.String -> result.add(sizes.getString(i))
|
|
44
|
+
else -> Log.d(TAG, "Invalid type")
|
|
41
45
|
}
|
|
42
|
-
|
|
43
|
-
view.setSizes(result.toArray())
|
|
44
|
-
} else {
|
|
45
|
-
view.setSizes(arrayOf("medium", "large"))
|
|
46
46
|
}
|
|
47
|
+
|
|
48
|
+
view.setSizes(result.toArray())
|
|
47
49
|
}
|
|
48
50
|
|
|
49
51
|
companion object {
|
|
@@ -8,7 +8,7 @@ import com.facebook.react.bridge.ReactMethod
|
|
|
8
8
|
import com.facebook.react.bridge.UiThreadUtil
|
|
9
9
|
import com.facebook.react.module.annotations.ReactModule
|
|
10
10
|
import com.facebook.react.uimanager.UIManagerHelper
|
|
11
|
-
import com.lodev09.truesheet.
|
|
11
|
+
import com.lodev09.truesheet.core.Utils
|
|
12
12
|
|
|
13
13
|
@ReactModule(name = TrueSheetViewModule.TAG)
|
|
14
14
|
class TrueSheetViewModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext) {
|
|
@@ -39,7 +39,7 @@ class TrueSheetViewModule(reactContext: ReactApplicationContext) : ReactContextB
|
|
|
39
39
|
fun present(tag: Int, index: Int, promise: Promise) {
|
|
40
40
|
withTrueSheetView(tag) {
|
|
41
41
|
it.present(index) {
|
|
42
|
-
withPromise(promise) {
|
|
42
|
+
Utils.withPromise(promise) {
|
|
43
43
|
return@withPromise null
|
|
44
44
|
}
|
|
45
45
|
}
|
|
@@ -50,7 +50,7 @@ class TrueSheetViewModule(reactContext: ReactApplicationContext) : ReactContextB
|
|
|
50
50
|
fun dismiss(tag: Int, promise: Promise) {
|
|
51
51
|
withTrueSheetView(tag) {
|
|
52
52
|
it.dismiss {
|
|
53
|
-
withPromise(promise) {
|
|
53
|
+
Utils.withPromise(promise) {
|
|
54
54
|
return@withPromise null
|
|
55
55
|
}
|
|
56
56
|
}
|
|
@@ -5,14 +5,13 @@ import android.view.MotionEvent
|
|
|
5
5
|
import android.view.ViewGroup
|
|
6
6
|
import android.widget.ScrollView
|
|
7
7
|
import androidx.coordinatorlayout.widget.CoordinatorLayout
|
|
8
|
-
import com.facebook.react.uimanager.PixelUtil
|
|
9
8
|
import com.google.android.material.bottomsheet.BottomSheetBehavior
|
|
10
|
-
import com.lodev09.truesheet.utils.toDIP
|
|
11
9
|
|
|
12
10
|
data class SizeInfo(val index: Int, val value: Float)
|
|
13
11
|
|
|
14
12
|
class SheetBehavior<T : ViewGroup> : BottomSheetBehavior<T>() {
|
|
15
|
-
var
|
|
13
|
+
var maxSheetSize: Point = Point()
|
|
14
|
+
var maxSheetHeight: Int? = null
|
|
16
15
|
|
|
17
16
|
var contentView: ViewGroup? = null
|
|
18
17
|
var footerView: ViewGroup? = null
|
|
@@ -55,49 +54,47 @@ class SheetBehavior<T : ViewGroup> : BottomSheetBehavior<T>() {
|
|
|
55
54
|
event.action == MotionEvent.ACTION_CANCEL
|
|
56
55
|
}
|
|
57
56
|
|
|
58
|
-
|
|
59
|
-
val maxHeight = maxSize.y
|
|
60
|
-
|
|
57
|
+
fun getSizeHeight(size: Any, contentHeight: Int): Int {
|
|
61
58
|
val height =
|
|
62
59
|
when (size) {
|
|
63
|
-
is Double ->
|
|
60
|
+
is Double -> Utils.toPixel(size)
|
|
64
61
|
|
|
65
|
-
is Int ->
|
|
62
|
+
is Int -> Utils.toPixel(size.toDouble())
|
|
66
63
|
|
|
67
64
|
is String -> {
|
|
68
|
-
|
|
65
|
+
when (size) {
|
|
69
66
|
"auto" -> contentHeight
|
|
70
67
|
|
|
71
|
-
"large" ->
|
|
68
|
+
"large" -> maxSheetSize.y
|
|
72
69
|
|
|
73
|
-
"medium" -> (
|
|
70
|
+
"medium" -> (maxSheetSize.y * 0.50).toInt()
|
|
74
71
|
|
|
75
|
-
"small" -> (
|
|
72
|
+
"small" -> (maxSheetSize.y * 0.25).toInt()
|
|
76
73
|
|
|
77
74
|
else -> {
|
|
78
75
|
if (size.endsWith('%')) {
|
|
79
76
|
val percent = size.trim('%').toDoubleOrNull()
|
|
80
|
-
|
|
77
|
+
if (percent == null) {
|
|
81
78
|
0
|
|
82
79
|
} else {
|
|
83
|
-
((percent / 100) *
|
|
80
|
+
((percent / 100) * maxSheetSize.y).toInt()
|
|
84
81
|
}
|
|
85
82
|
} else {
|
|
86
83
|
val fixedHeight = size.toDoubleOrNull()
|
|
87
|
-
|
|
84
|
+
if (fixedHeight == null) {
|
|
88
85
|
0
|
|
89
86
|
} else {
|
|
90
|
-
|
|
87
|
+
Utils.toPixel(fixedHeight)
|
|
91
88
|
}
|
|
92
89
|
}
|
|
93
90
|
}
|
|
94
91
|
}
|
|
95
92
|
}
|
|
96
93
|
|
|
97
|
-
else -> (
|
|
94
|
+
else -> (maxSheetSize.y * 0.5).toInt()
|
|
98
95
|
}
|
|
99
96
|
|
|
100
|
-
return minOf(height,
|
|
97
|
+
return minOf(height, maxSheetHeight ?: maxSheetSize.y)
|
|
101
98
|
}
|
|
102
99
|
|
|
103
100
|
fun configure(sizes: Array<Any>) {
|
|
@@ -128,7 +125,7 @@ class SheetBehavior<T : ViewGroup> : BottomSheetBehavior<T>() {
|
|
|
128
125
|
isFitToContents = false
|
|
129
126
|
|
|
130
127
|
peekHeight = getSizeHeight(sizes[0], contentHeight)
|
|
131
|
-
halfExpandedRatio = getSizeHeight(sizes[1], contentHeight).toFloat() /
|
|
128
|
+
halfExpandedRatio = getSizeHeight(sizes[1], contentHeight).toFloat() / maxSheetSize.y.toFloat()
|
|
132
129
|
maxHeight = getSizeHeight(sizes[2], contentHeight)
|
|
133
130
|
}
|
|
134
131
|
}
|
|
@@ -139,29 +136,29 @@ class SheetBehavior<T : ViewGroup> : BottomSheetBehavior<T>() {
|
|
|
139
136
|
when (sizeCount) {
|
|
140
137
|
1 -> {
|
|
141
138
|
when (state) {
|
|
142
|
-
STATE_EXPANDED -> SizeInfo(0,
|
|
139
|
+
STATE_EXPANDED -> SizeInfo(0, Utils.toDIP(maxHeight))
|
|
143
140
|
else -> null
|
|
144
141
|
}
|
|
145
142
|
}
|
|
146
143
|
|
|
147
144
|
2 -> {
|
|
148
145
|
when (state) {
|
|
149
|
-
STATE_COLLAPSED -> SizeInfo(0, toDIP(peekHeight))
|
|
150
|
-
STATE_EXPANDED -> SizeInfo(1, toDIP(maxHeight))
|
|
146
|
+
STATE_COLLAPSED -> SizeInfo(0, Utils.toDIP(peekHeight))
|
|
147
|
+
STATE_EXPANDED -> SizeInfo(1, Utils.toDIP(maxHeight))
|
|
151
148
|
else -> null
|
|
152
149
|
}
|
|
153
150
|
}
|
|
154
151
|
|
|
155
152
|
3 -> {
|
|
156
153
|
when (state) {
|
|
157
|
-
STATE_COLLAPSED -> SizeInfo(0, toDIP(peekHeight))
|
|
154
|
+
STATE_COLLAPSED -> SizeInfo(0, Utils.toDIP(peekHeight))
|
|
158
155
|
|
|
159
156
|
STATE_HALF_EXPANDED -> {
|
|
160
|
-
val height = halfExpandedRatio *
|
|
161
|
-
SizeInfo(1, toDIP(height.toInt()))
|
|
157
|
+
val height = halfExpandedRatio * maxSheetSize.y
|
|
158
|
+
SizeInfo(1, Utils.toDIP(height.toInt()))
|
|
162
159
|
}
|
|
163
160
|
|
|
164
|
-
STATE_EXPANDED -> SizeInfo(2, toDIP(maxHeight))
|
|
161
|
+
STATE_EXPANDED -> SizeInfo(2, Utils.toDIP(maxHeight))
|
|
165
162
|
|
|
166
163
|
else -> null
|
|
167
164
|
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
package com.lodev09.truesheet.core
|
|
2
|
+
|
|
3
|
+
import android.annotation.SuppressLint
|
|
4
|
+
import android.content.Context
|
|
5
|
+
import android.graphics.Point
|
|
6
|
+
import android.view.WindowManager
|
|
7
|
+
import com.facebook.infer.annotation.Assertions
|
|
8
|
+
import com.facebook.react.bridge.Promise
|
|
9
|
+
import com.facebook.react.uimanager.PixelUtil
|
|
10
|
+
|
|
11
|
+
object Utils {
|
|
12
|
+
@SuppressLint("DiscouragedApi", "InternalInsetResource")
|
|
13
|
+
fun maxSize(context: Context): Point {
|
|
14
|
+
val minPoint = Point()
|
|
15
|
+
val maxPoint = Point()
|
|
16
|
+
val sizePoint = Point()
|
|
17
|
+
|
|
18
|
+
val wm = context.getSystemService(Context.WINDOW_SERVICE) as WindowManager
|
|
19
|
+
val display = Assertions.assertNotNull(wm).defaultDisplay
|
|
20
|
+
// getCurrentSizeRange will return the min and max width and height that the window can be
|
|
21
|
+
display.getCurrentSizeRange(minPoint, maxPoint)
|
|
22
|
+
// getSize will return the dimensions of the screen in its current orientation
|
|
23
|
+
display.getSize(sizePoint)
|
|
24
|
+
val attrs = intArrayOf(android.R.attr.windowFullscreen)
|
|
25
|
+
val theme = context.theme
|
|
26
|
+
val ta = theme.obtainStyledAttributes(attrs)
|
|
27
|
+
val windowFullscreen = ta.getBoolean(0, false)
|
|
28
|
+
|
|
29
|
+
// We need to add the status bar height to the height if we have a fullscreen window,
|
|
30
|
+
// because Display.getCurrentSizeRange doesn't include it.
|
|
31
|
+
val resources = context.resources
|
|
32
|
+
val statusBarId = resources.getIdentifier("status_bar_height", "dimen", "android")
|
|
33
|
+
var statusBarHeight = 0
|
|
34
|
+
if (windowFullscreen && statusBarId > 0) {
|
|
35
|
+
statusBarHeight = resources.getDimension(statusBarId).toInt()
|
|
36
|
+
}
|
|
37
|
+
return if (sizePoint.x < sizePoint.y) {
|
|
38
|
+
// If we are vertical the width value comes from min width and height comes from max height
|
|
39
|
+
Point(minPoint.x, maxPoint.y + statusBarHeight)
|
|
40
|
+
} else {
|
|
41
|
+
// If we are horizontal the width value comes from max width and height comes from min height
|
|
42
|
+
Point(maxPoint.x, minPoint.y + statusBarHeight)
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
fun toDIP(value: Int): Float = PixelUtil.toDIPFromPixel(value.toFloat())
|
|
47
|
+
fun toPixel(value: Double): Int = PixelUtil.toPixelFromDIP(value).toInt()
|
|
48
|
+
|
|
49
|
+
fun withPromise(promise: Promise, closure: () -> Any?) {
|
|
50
|
+
try {
|
|
51
|
+
val result = closure()
|
|
52
|
+
promise.resolve(result)
|
|
53
|
+
} catch (e: Throwable) {
|
|
54
|
+
e.printStackTrace()
|
|
55
|
+
promise.reject("Error", e.message, e.cause)
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -13,14 +13,24 @@ 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,
|
|
26
|
+
with maxHeight: CGFloat?,
|
|
17
27
|
_ resolution: @escaping (CGFloat) -> Void) -> UISheetPresentationController.Detent {
|
|
18
28
|
switch identifier {
|
|
19
29
|
case .large:
|
|
20
30
|
if #available(iOS 16.0, *) {
|
|
21
31
|
return .custom(identifier: .large) { context in
|
|
22
|
-
let value = UISheetPresentationController.Detent.large().resolvedValue(in: context)
|
|
23
|
-
resolution(value
|
|
32
|
+
let value = self.minValue(UISheetPresentationController.Detent.large().resolvedValue(in: context), maxHeight)
|
|
33
|
+
resolution(value)
|
|
24
34
|
return value
|
|
25
35
|
}
|
|
26
36
|
} else {
|
|
@@ -30,15 +40,15 @@ extension UIViewController {
|
|
|
30
40
|
case .medium:
|
|
31
41
|
if #available(iOS 16.0, *) {
|
|
32
42
|
return .custom(identifier: .medium) { context in
|
|
33
|
-
let value = UISheetPresentationController.Detent.medium().resolvedValue(in: context)
|
|
34
|
-
resolution(value
|
|
43
|
+
let value = self.minValue(UISheetPresentationController.Detent.medium().resolvedValue(in: context), maxHeight)
|
|
44
|
+
resolution(value)
|
|
35
45
|
return value
|
|
36
46
|
}
|
|
37
47
|
}
|
|
38
48
|
case .small:
|
|
39
49
|
if #available(iOS 16.0, *) {
|
|
40
50
|
return .custom { context in
|
|
41
|
-
let value = 0.25 * context.maximumDetentValue
|
|
51
|
+
let value = self.minValue(0.25 * context.maximumDetentValue, maxHeight)
|
|
42
52
|
resolution(value)
|
|
43
53
|
return value
|
|
44
54
|
}
|
|
@@ -52,18 +62,21 @@ extension UIViewController {
|
|
|
52
62
|
}
|
|
53
63
|
|
|
54
64
|
/// Get the custom detent based on the given size and view frame size
|
|
55
|
-
func detentFor(_ anySize: Any,
|
|
65
|
+
func detentFor(_ anySize: Any,
|
|
66
|
+
with height: CGFloat?,
|
|
67
|
+
with maxHeight: CGFloat?,
|
|
68
|
+
_ resolution: @escaping (String, CGFloat) -> Void) -> UISheetPresentationController.Detent {
|
|
56
69
|
let id = "custom-\(anySize)"
|
|
57
70
|
|
|
58
71
|
if let floatSize = anySize as? CGFloat {
|
|
59
72
|
if #available(iOS 16.0, *) {
|
|
60
73
|
return .custom(identifier: identifier(from: id)) { context in
|
|
61
|
-
let value = min(floatSize, context.maximumDetentValue)
|
|
74
|
+
let value = min(floatSize, self.minValue(context.maximumDetentValue, maxHeight))
|
|
62
75
|
resolution(id, value)
|
|
63
76
|
return value
|
|
64
77
|
}
|
|
65
78
|
} else {
|
|
66
|
-
return detentFor(identifier: .medium) { value in
|
|
79
|
+
return detentFor(identifier: .medium, with: maxHeight) { value in
|
|
67
80
|
resolution(id, value)
|
|
68
81
|
}
|
|
69
82
|
}
|
|
@@ -72,22 +85,22 @@ extension UIViewController {
|
|
|
72
85
|
if var stringSize = anySize as? String {
|
|
73
86
|
switch stringSize {
|
|
74
87
|
case "small":
|
|
75
|
-
return detentFor(identifier: .small) { value in
|
|
88
|
+
return detentFor(identifier: .small, with: maxHeight) { value in
|
|
76
89
|
resolution(UISheetPresentationController.Detent.Identifier.small.rawValue, value)
|
|
77
90
|
}
|
|
78
91
|
case "medium":
|
|
79
|
-
return detentFor(identifier: .medium) { value in
|
|
92
|
+
return detentFor(identifier: .medium, with: maxHeight) { value in
|
|
80
93
|
resolution(UISheetPresentationController.Detent.Identifier.medium.rawValue, value)
|
|
81
94
|
}
|
|
82
95
|
case "large":
|
|
83
|
-
return detentFor(identifier: .large) { value in
|
|
96
|
+
return detentFor(identifier: .large, with: maxHeight) { value in
|
|
84
97
|
resolution(UISheetPresentationController.Detent.Identifier.large.rawValue, value)
|
|
85
98
|
}
|
|
86
99
|
default:
|
|
87
100
|
if #available(iOS 16.0, *) {
|
|
88
101
|
if stringSize == "auto" {
|
|
89
102
|
return .custom(identifier: identifier(from: id)) { context in
|
|
90
|
-
let value = min(height ?? context.maximumDetentValue / 2, context.maximumDetentValue)
|
|
103
|
+
let value = min(height ?? context.maximumDetentValue / 2, self.minValue(context.maximumDetentValue, maxHeight))
|
|
91
104
|
resolution(id, value)
|
|
92
105
|
return value
|
|
93
106
|
}
|
|
@@ -97,21 +110,21 @@ extension UIViewController {
|
|
|
97
110
|
let floatSize = CGFloat((stringSize as NSString).floatValue)
|
|
98
111
|
if floatSize > 0.0 {
|
|
99
112
|
return .custom(identifier: identifier(from: id)) { context in
|
|
100
|
-
let value = min((floatSize / 100) * context.maximumDetentValue, context.maximumDetentValue)
|
|
113
|
+
let value = min((floatSize / 100) * context.maximumDetentValue, self.minValue(context.maximumDetentValue, maxHeight))
|
|
101
114
|
resolution(id, value)
|
|
102
115
|
return value
|
|
103
116
|
}
|
|
104
117
|
}
|
|
105
118
|
}
|
|
106
119
|
} else {
|
|
107
|
-
return detentFor(identifier: .medium) { value in
|
|
120
|
+
return detentFor(identifier: .medium, with: maxHeight) { value in
|
|
108
121
|
resolution(id, value)
|
|
109
122
|
}
|
|
110
123
|
}
|
|
111
124
|
}
|
|
112
125
|
}
|
|
113
126
|
|
|
114
|
-
resolution(id,
|
|
127
|
+
resolution(id, view.frame.height / 2)
|
|
115
128
|
return .medium()
|
|
116
129
|
}
|
|
117
130
|
|
package/ios/TrueSheetView.swift
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
class TrueSheetView: UIView, RCTInvalidating, TrueSheetViewControllerDelegate {
|
|
11
11
|
// MARK: - React properties
|
|
12
12
|
|
|
13
|
-
var
|
|
13
|
+
var maxHeight: CGFloat?
|
|
14
14
|
|
|
15
15
|
// Events
|
|
16
16
|
@objc var onDismiss: RCTDirectEventBlock?
|
|
@@ -150,9 +150,15 @@ class TrueSheetView: UIView, RCTInvalidating, TrueSheetViewControllerDelegate {
|
|
|
150
150
|
|
|
151
151
|
// MARK: - Prop setters
|
|
152
152
|
|
|
153
|
+
@objc
|
|
154
|
+
func setMaxHeight(_ height: NSNumber) {
|
|
155
|
+
viewController.maxHeight = CGFloat(height.floatValue)
|
|
156
|
+
configureSheetIfPresented()
|
|
157
|
+
}
|
|
158
|
+
|
|
153
159
|
@objc
|
|
154
160
|
func setSizes(_ sizes: [Any]) {
|
|
155
|
-
|
|
161
|
+
viewController.sizes = Array(sizes.prefix(3))
|
|
156
162
|
configureSheetIfPresented()
|
|
157
163
|
}
|
|
158
164
|
|
|
@@ -171,7 +177,7 @@ class TrueSheetView: UIView, RCTInvalidating, TrueSheetViewControllerDelegate {
|
|
|
171
177
|
func configureSheetIfPresented() {
|
|
172
178
|
// Resize sheet
|
|
173
179
|
if #available(iOS 15.0, *), isPresented {
|
|
174
|
-
viewController.configureSheet(
|
|
180
|
+
viewController.configureSheet(at: activeIndex ?? 0, with: contentHeight, nil)
|
|
175
181
|
}
|
|
176
182
|
}
|
|
177
183
|
|
|
@@ -218,13 +224,13 @@ class TrueSheetView: UIView, RCTInvalidating, TrueSheetViewControllerDelegate {
|
|
|
218
224
|
return
|
|
219
225
|
}
|
|
220
226
|
|
|
221
|
-
guard sizes.indices.contains(index) else {
|
|
227
|
+
guard viewController.sizes.indices.contains(index) else {
|
|
222
228
|
promise.reject(message: "Size at \(index) is not configured.")
|
|
223
229
|
return
|
|
224
230
|
}
|
|
225
231
|
|
|
226
232
|
if #available(iOS 15.0, *) {
|
|
227
|
-
viewController.configureSheet(
|
|
233
|
+
viewController.configureSheet(at: index, with: contentHeight) {
|
|
228
234
|
if self.isPresented {
|
|
229
235
|
// Notify when size is changed programatically
|
|
230
236
|
let info = self.viewController.detentValues.first(where: { $0.value.index == index })
|
|
@@ -29,6 +29,9 @@ class TrueSheetViewController: UIViewController, UISheetPresentationControllerDe
|
|
|
29
29
|
|
|
30
30
|
weak var delegate: TrueSheetViewControllerDelegate?
|
|
31
31
|
|
|
32
|
+
var sizes: [Any] = ["medium", "large"]
|
|
33
|
+
var maxHeight: CGFloat?
|
|
34
|
+
|
|
32
35
|
var lastViewWidth: CGFloat = 0
|
|
33
36
|
var detentValues: [String: SizeInfo] = [:]
|
|
34
37
|
|
|
@@ -71,7 +74,7 @@ class TrueSheetViewController: UIViewController, UISheetPresentationControllerDe
|
|
|
71
74
|
/// Prepares the view controller for sheet presentation
|
|
72
75
|
/// Do nothing on IOS 14 and below... sad
|
|
73
76
|
@available(iOS 15.0, *)
|
|
74
|
-
func configureSheet(
|
|
77
|
+
func configureSheet(at index: Int = 0, with contentHeight: CGFloat, _ completion: (() -> Void)?) {
|
|
75
78
|
guard let sheet else { return }
|
|
76
79
|
|
|
77
80
|
detentValues = [:]
|
|
@@ -79,7 +82,7 @@ class TrueSheetViewController: UIViewController, UISheetPresentationControllerDe
|
|
|
79
82
|
var detents: [UISheetPresentationController.Detent] = []
|
|
80
83
|
|
|
81
84
|
for (index, size) in sizes.enumerated() {
|
|
82
|
-
let detent = detentFor(size, with:
|
|
85
|
+
let detent = detentFor(size, with: contentHeight, with: maxHeight) { id, value in
|
|
83
86
|
self.detentValues[id] = SizeInfo(index: index, value: value)
|
|
84
87
|
}
|
|
85
88
|
|
|
@@ -27,11 +27,9 @@ RCT_EXPORT_VIEW_PROPERTY(onPresent, RCTDirectEventBlock)
|
|
|
27
27
|
RCT_EXPORT_VIEW_PROPERTY(onDismiss, RCTDirectEventBlock)
|
|
28
28
|
RCT_EXPORT_VIEW_PROPERTY(onSizeChange, RCTDirectEventBlock)
|
|
29
29
|
|
|
30
|
-
// Internal Properties
|
|
31
|
-
RCT_EXPORT_VIEW_PROPERTY(scrollableHandle, NSNumber*)
|
|
32
|
-
RCT_EXPORT_VIEW_PROPERTY(footerHandle, NSNumber*)
|
|
33
|
-
|
|
34
30
|
// Properties
|
|
31
|
+
RCT_EXPORT_VIEW_PROPERTY(scrollableHandle, NSNumber)
|
|
32
|
+
RCT_EXPORT_VIEW_PROPERTY(maxHeight, NSNumber)
|
|
35
33
|
RCT_EXPORT_VIEW_PROPERTY(sizes, NSArray)
|
|
36
34
|
|
|
37
35
|
@end
|
|
@@ -83,6 +83,7 @@ class TrueSheet extends _react.PureComponent {
|
|
|
83
83
|
style: $nativeSheet,
|
|
84
84
|
scrollableHandle: this.state.scrollableHandle,
|
|
85
85
|
sizes: this.props.sizes ?? ['medium', 'large'],
|
|
86
|
+
maxHeight: this.props.maxHeight,
|
|
86
87
|
onPresent: this.onPresent,
|
|
87
88
|
onDismiss: this.onDismiss,
|
|
88
89
|
onSizeChange: this.onSizeChange
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_react","_interopRequireWildcard","require","_reactNative","_TrueSheetModule","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","prototype","hasOwnProperty","call","i","set","LINKING_ERROR","Platform","select","ios","ComponentName","TrueSheetNativeView","requireNativeComponent","Error","TrueSheet","PureComponent","displayName","constructor","props","ref","createRef","onDismiss","bind","onPresent","onSizeChange","state","scrollableHandle","handle","nodeHandle","findNodeHandle","current","updateState","scrollRef","setState","event","nativeEvent","componentDidMount","sizes","length","console","warn","componentDidUpdate","present","index","TrueSheetModule","dismiss","render","FooterComponent","createElement","style","$nativeSheet","View","collapsable","backgroundColor","children","exports","position","zIndex"],"sourceRoot":"../../src","sources":["TrueSheet.tsx"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AAYA,IAAAE,gBAAA,GAAAF,OAAA;AAAmD,SAAAG,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAL,wBAAAK,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAI,UAAA,SAAAJ,CAAA,eAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,WAAAK,OAAA,EAAAL,CAAA,QAAAG,CAAA,GAAAJ,wBAAA,CAAAG,CAAA,OAAAC,CAAA,IAAAA,CAAA,CAAAG,GAAA,CAAAN,CAAA,UAAAG,CAAA,CAAAI,GAAA,CAAAP,CAAA,OAAAQ,CAAA,KAAAC,SAAA,UAAAC,CAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,CAAA,IAAAd,CAAA,oBAAAc,CAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAjB,CAAA,EAAAc,CAAA,SAAAI,CAAA,GAAAR,CAAA,GAAAC,MAAA,CAAAE,wBAAA,CAAAb,CAAA,EAAAc,CAAA,UAAAI,CAAA,KAAAA,CAAA,CAAAX,GAAA,IAAAW,CAAA,CAAAC,GAAA,IAAAR,MAAA,CAAAC,cAAA,CAAAJ,CAAA,EAAAM,CAAA,EAAAI,CAAA,IAAAV,CAAA,CAAAM,CAAA,IAAAd,CAAA,CAAAc,CAAA,YAAAN,CAAA,CAAAH,OAAA,GAAAL,CAAA,EAAAG,CAAA,IAAAA,CAAA,CAAAgB,GAAA,CAAAnB,CAAA,EAAAQ,CAAA,GAAAA,CAAA;AAEnD,MAAMY,aAAa,GAChB,2FAA0F,GAC3FC,qBAAQ,CAACC,MAAM,CAAC;EAAEC,GAAG,EAAE,gCAAgC;EAAElB,OAAO,EAAE;AAAG,CAAC,CAAC,GACvE,sDAAsD,GACtD,+BAA+B;AAEjC,MAAMmB,aAAa,GAAG,eAAe;
|
|
1
|
+
{"version":3,"names":["_react","_interopRequireWildcard","require","_reactNative","_TrueSheetModule","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","prototype","hasOwnProperty","call","i","set","LINKING_ERROR","Platform","select","ios","ComponentName","TrueSheetNativeView","requireNativeComponent","Error","TrueSheet","PureComponent","displayName","constructor","props","ref","createRef","onDismiss","bind","onPresent","onSizeChange","state","scrollableHandle","handle","nodeHandle","findNodeHandle","current","updateState","scrollRef","setState","event","nativeEvent","componentDidMount","sizes","length","console","warn","componentDidUpdate","present","index","TrueSheetModule","dismiss","render","FooterComponent","createElement","style","$nativeSheet","maxHeight","View","collapsable","backgroundColor","children","exports","position","zIndex"],"sourceRoot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AACD,KAAK,CAACC,gBAAiB;MAC9CW,KAAK,EAAE,IAAI,CAACnB,KAAK,CAACmB,KAAK,IAAI,CAAC,QAAQ,EAAE,OAAO,CAAE;MAC/Cc,SAAS,EAAE,IAAI,CAACjC,KAAK,CAACiC,SAAU;MAChC5B,SAAS,EAAE,IAAI,CAACA,SAAU;MAC1BF,SAAS,EAAE,IAAI,CAACA,SAAU;MAC1BG,YAAY,EAAE,IAAI,CAACA;IAAa,gBAEhC5C,MAAA,CAAAW,OAAA,CAAAyD,aAAA,CAACjE,YAAA,CAAAqE,IAAI;MACHC,WAAW,EAAE,KAAM;MACnBJ,KAAK,EAAE;QAAEK,eAAe,EAAE,IAAI,CAACpC,KAAK,CAACoC,eAAe,IAAI;MAAQ;IAAE,gBAElE1E,MAAA,CAAAW,OAAA,CAAAyD,aAAA,CAACjE,YAAA,CAAAqE,IAAI;MAACC,WAAW,EAAE,KAAM;MAACJ,KAAK,EAAE,IAAI,CAAC/B,KAAK,CAAC+B;IAAM,GAC/C,IAAI,CAAC/B,KAAK,CAACqC,QACR,CAAC,eACP3E,MAAA,CAAAW,OAAA,CAAAyD,aAAA,CAACjE,YAAA,CAAAqE,IAAI;MAACC,WAAW,EAAE;IAAM,GAAE,CAAC,CAACN,eAAe,iBAAInE,MAAA,CAAAW,OAAA,CAAAyD,aAAA,CAACD,eAAe,MAAE,CAAQ,CACtE,CACa,CAAC;EAE1B;AACF;AAACS,OAAA,CAAA1C,SAAA,GAAAA,SAAA;AAED,MAAMoC,YAAuB,GAAG;EAC9BO,QAAQ,EAAE,UAAU;EACpBC,MAAM,EAAE,CAAC;AACX,CAAC","ignoreList":[]}
|
package/lib/module/TrueSheet.js
CHANGED
|
@@ -75,6 +75,7 @@ export class TrueSheet extends PureComponent {
|
|
|
75
75
|
style: $nativeSheet,
|
|
76
76
|
scrollableHandle: this.state.scrollableHandle,
|
|
77
77
|
sizes: this.props.sizes ?? ['medium', 'large'],
|
|
78
|
+
maxHeight: this.props.maxHeight,
|
|
78
79
|
onPresent: this.onPresent,
|
|
79
80
|
onDismiss: this.onDismiss,
|
|
80
81
|
onSizeChange: this.onSizeChange
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","PureComponent","createRef","requireNativeComponent","Platform","findNodeHandle","View","TrueSheetModule","LINKING_ERROR","select","ios","default","ComponentName","TrueSheetNativeView","Error","TrueSheet","displayName","constructor","props","ref","onDismiss","bind","onPresent","onSizeChange","state","scrollableHandle","handle","nodeHandle","current","updateState","scrollRef","setState","event","nativeEvent","componentDidMount","sizes","length","console","warn","componentDidUpdate","present","index","dismiss","render","FooterComponent","createElement","style","$nativeSheet","collapsable","backgroundColor","children","position","zIndex"],"sourceRoot":"../../src","sources":["TrueSheet.tsx"],"mappings":"AAAA,OAAOA,KAAK,IAAIC,aAAa,EAA6BC,SAAS,QAAwB,OAAO;AAClG,SACEC,sBAAsB,EACtBC,QAAQ,EACRC,cAAc,EACdC,IAAI,QAKC,cAAc;AAGrB,SAASC,eAAe,QAAQ,mBAAmB;AAEnD,MAAMC,aAAa,GAChB,2FAA0F,GAC3FJ,QAAQ,CAACK,MAAM,CAAC;EAAEC,GAAG,EAAE,gCAAgC;EAAEC,OAAO,EAAE;AAAG,CAAC,CAAC,GACvE,sDAAsD,GACtD,+BAA+B;AAEjC,MAAMC,aAAa,GAAG,eAAe;
|
|
1
|
+
{"version":3,"names":["React","PureComponent","createRef","requireNativeComponent","Platform","findNodeHandle","View","TrueSheetModule","LINKING_ERROR","select","ios","default","ComponentName","TrueSheetNativeView","Error","TrueSheet","displayName","constructor","props","ref","onDismiss","bind","onPresent","onSizeChange","state","scrollableHandle","handle","nodeHandle","current","updateState","scrollRef","setState","event","nativeEvent","componentDidMount","sizes","length","console","warn","componentDidUpdate","present","index","dismiss","render","FooterComponent","createElement","style","$nativeSheet","maxHeight","collapsable","backgroundColor","children","position","zIndex"],"sourceRoot":"../../src","sources":["TrueSheet.tsx"],"mappings":"AAAA,OAAOA,KAAK,IAA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3,"file":"TrueSheet.d.ts","sourceRoot":"","sources":["../../../src/TrueSheet.tsx"],"names":[],"mappings":"AAAA,OAAc,EAAE,aAAa,EAAwC,KAAK,SAAS,EAAE,MAAM,OAAO,CAAA;AAYlG,OAAO,KAAK,EAAE,cAAc,EAAmB,MAAM,SAAS,CAAA;AA8B9D,UAAU,cAAc;IACtB,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAA;CAChC;AAED,qBAAa,SAAU,SAAQ,aAAa,CAAC,cAAc,EAAE,cAAc,CAAC;IAC1E,WAAW,SAAc;IAEzB,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAsB;gBAE9B,KAAK,EAAE,cAAc;IAcjC,OAAO,KAAK,MAAM,GAOjB;IAED,OAAO,CAAC,WAAW;IAUnB,OAAO,CAAC,YAAY;IAIpB,OAAO,CAAC,SAAS;IAIjB,OAAO,CAAC,SAAS;IAIjB,iBAAiB,IAAI,IAAI;IAUzB,kBAAkB,IAAI,IAAI;IAI1B;;;OAGG;IACU,OAAO,CAAC,KAAK,GAAE,MAAU;IAItC;;OAEG;IACU,OAAO;IAIpB,MAAM,IAAI,SAAS;CA0BpB"}
|
|
@@ -73,6 +73,10 @@ export interface TrueSheetProps extends ViewProps {
|
|
|
73
73
|
* @default ['medium', 'large']
|
|
74
74
|
*/
|
|
75
75
|
sizes?: SheetSize[];
|
|
76
|
+
/**
|
|
77
|
+
* Overrides `large` or `100%` height.
|
|
78
|
+
*/
|
|
79
|
+
maxHeight?: number;
|
|
76
80
|
/**
|
|
77
81
|
* A component that floats at the bottom of the Sheet.
|
|
78
82
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAChE,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;A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GAAG,MAAM,GAAG;AAEd;;;;;GAKG;GACD,OAAO;AAET;;;;;GAKG;GACD,QAAQ;AAEV;;;;;GAKG;GACD,OAAO,CAAA;AAEX,MAAM,WAAW,cAAe,SAAQ,SAAS;IAC/C;;OAEG;IACH,eAAe,CAAC,EAAE,UAAU,CAAA;IAE5B;;;OAGG;IACH,SAAS,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAA;IAEzC;;;;;;;;;;OAUG;IACH,KAAK,CAAC,EAAE,SAAS,EAAE,CAAA;IAEnB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAElB;;OAEG;IACH,eAAe,CAAC,EAAE,aAAa,CAAC,OAAO,CAAC,CAAA;IAExC;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,IAAI,CAAA;IAEtB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,IAAI,CAAA;IAEtB;;;OAGG;IACH,YAAY,CAAC,EAAE,CAAC,KAAK,EAAE,eAAe,KAAK,IAAI,CAAA;CAChD"}
|
package/package.json
CHANGED
package/src/TrueSheet.tsx
CHANGED
|
@@ -25,6 +25,7 @@ interface TrueSheetNativeViewProps {
|
|
|
25
25
|
scrollableHandle: number | null
|
|
26
26
|
style: StyleProp<ViewStyle>
|
|
27
27
|
sizes: TrueSheetProps['sizes']
|
|
28
|
+
maxHeight?: TrueSheetProps['maxHeight']
|
|
28
29
|
children: ReactNode
|
|
29
30
|
onDismiss: () => void
|
|
30
31
|
onPresent: (event: NativeSyntheticEvent<{ index: number }>) => void
|
|
@@ -131,6 +132,7 @@ export class TrueSheet extends PureComponent<TrueSheetProps, TrueSheetState> {
|
|
|
131
132
|
style={$nativeSheet}
|
|
132
133
|
scrollableHandle={this.state.scrollableHandle}
|
|
133
134
|
sizes={this.props.sizes ?? ['medium', 'large']}
|
|
135
|
+
maxHeight={this.props.maxHeight}
|
|
134
136
|
onPresent={this.onPresent}
|
|
135
137
|
onDismiss={this.onDismiss}
|
|
136
138
|
onSizeChange={this.onSizeChange}
|
package/src/types.ts
CHANGED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
package com.lodev09.truesheet.utils
|
|
2
|
-
|
|
3
|
-
import android.annotation.SuppressLint
|
|
4
|
-
import android.content.Context
|
|
5
|
-
import android.graphics.Point
|
|
6
|
-
import android.view.WindowManager
|
|
7
|
-
import com.facebook.infer.annotation.Assertions
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* To get the size of the screen, we use information from the WindowManager and default Display.
|
|
11
|
-
* We don't use DisplayMetricsHolder, or Display#getSize() because they return values that include
|
|
12
|
-
* the status bar. We only want the values of what will actually be shown on screen. We use
|
|
13
|
-
* Display#getSize() to determine if the screen is in portrait or landscape. We don't use
|
|
14
|
-
* getRotation because the 'natural' rotation will be portrait on phones and landscape on tablets.
|
|
15
|
-
* This should only be called on the native modules/shadow nodes thread.
|
|
16
|
-
*/
|
|
17
|
-
@SuppressLint("DiscouragedApi", "InternalInsetResource")
|
|
18
|
-
fun maxSize(context: Context): Point {
|
|
19
|
-
val minPoint = Point()
|
|
20
|
-
val maxPoint = Point()
|
|
21
|
-
val sizePoint = Point()
|
|
22
|
-
|
|
23
|
-
val wm = context.getSystemService(Context.WINDOW_SERVICE) as WindowManager
|
|
24
|
-
val display = Assertions.assertNotNull(wm).defaultDisplay
|
|
25
|
-
// getCurrentSizeRange will return the min and max width and height that the window can be
|
|
26
|
-
display.getCurrentSizeRange(minPoint, maxPoint)
|
|
27
|
-
// getSize will return the dimensions of the screen in its current orientation
|
|
28
|
-
display.getSize(sizePoint)
|
|
29
|
-
val attrs = intArrayOf(android.R.attr.windowFullscreen)
|
|
30
|
-
val theme = context.theme
|
|
31
|
-
val ta = theme.obtainStyledAttributes(attrs)
|
|
32
|
-
val windowFullscreen = ta.getBoolean(0, false)
|
|
33
|
-
|
|
34
|
-
// We need to add the status bar height to the height if we have a fullscreen window,
|
|
35
|
-
// because Display.getCurrentSizeRange doesn't include it.
|
|
36
|
-
val resources = context.resources
|
|
37
|
-
val statusBarId = resources.getIdentifier("status_bar_height", "dimen", "android")
|
|
38
|
-
var statusBarHeight = 0
|
|
39
|
-
if (windowFullscreen && statusBarId > 0) {
|
|
40
|
-
statusBarHeight = resources.getDimension(statusBarId).toInt()
|
|
41
|
-
}
|
|
42
|
-
return if (sizePoint.x < sizePoint.y) {
|
|
43
|
-
// If we are vertical the width value comes from min width and height comes from max height
|
|
44
|
-
Point(minPoint.x, maxPoint.y + statusBarHeight)
|
|
45
|
-
} else {
|
|
46
|
-
// If we are horizontal the width value comes from max width and height comes from min height
|
|
47
|
-
Point(maxPoint.x, minPoint.y + statusBarHeight)
|
|
48
|
-
}
|
|
49
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
package com.lodev09.truesheet.utils
|
|
2
|
-
|
|
3
|
-
import com.facebook.react.bridge.Promise
|
|
4
|
-
|
|
5
|
-
inline fun withPromise(promise: Promise, closure: () -> Any?) {
|
|
6
|
-
try {
|
|
7
|
-
val result = closure()
|
|
8
|
-
promise.resolve(result)
|
|
9
|
-
} catch (e: Throwable) {
|
|
10
|
-
e.printStackTrace()
|
|
11
|
-
promise.reject("Error", e.message, e.cause)
|
|
12
|
-
}
|
|
13
|
-
}
|