@lodev09/react-native-true-sheet 2.0.5 → 2.0.6

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.
@@ -210,7 +210,7 @@ class TrueSheetDialog(private val reactContext: ThemedReactContext, private val
210
210
  /**
211
211
  * Set the state based for the given size index.
212
212
  */
213
- private fun setStateForSizeIndex(index: Int) {
213
+ fun setStateForSizeIndex(index: Int) {
214
214
  behavior.state = getStateForSizeIndex(index)
215
215
  }
216
216
 
@@ -263,9 +263,11 @@ class TrueSheetDialog(private val reactContext: ThemedReactContext, private val
263
263
  /**
264
264
  * Determines the state based from the given size index.
265
265
  */
266
- private fun getStateForSizeIndex(index: Int) =
267
- when (sizes.size) {
268
- 1 -> BottomSheetBehavior.STATE_EXPANDED
266
+ private fun getStateForSizeIndex(index: Int): Int {
267
+ return when (sizes.size) {
268
+ 1 -> {
269
+ return BottomSheetBehavior.STATE_EXPANDED
270
+ }
269
271
 
270
272
  2 -> {
271
273
  when (index) {
@@ -286,6 +288,7 @@ class TrueSheetDialog(private val reactContext: ThemedReactContext, private val
286
288
 
287
289
  else -> BottomSheetBehavior.STATE_HIDDEN
288
290
  }
291
+ }
289
292
 
290
293
  /**
291
294
  * Handle keyboard state changes and adjust maxScreenHeight (sheet max height) accordingly.
@@ -331,6 +334,15 @@ class TrueSheetDialog(private val reactContext: ThemedReactContext, private val
331
334
  1 -> {
332
335
  maxHeight = getSizeHeight(sizes[0])
333
336
  skipCollapsed = true
337
+
338
+ if (sizes[0] == "auto") {
339
+ // Force a layout update
340
+ sheetContainerView?.let {
341
+ val params = it.layoutParams
342
+ params.height = maxHeight
343
+ it.layoutParams = params
344
+ }
345
+ }
334
346
  }
335
347
 
336
348
  2 -> {
@@ -358,6 +370,7 @@ class TrueSheetDialog(private val reactContext: ThemedReactContext, private val
358
370
  when (sizes.size) {
359
371
  1 -> {
360
372
  when (state) {
373
+ BottomSheetBehavior.STATE_COLLAPSED -> SizeInfo(0, Utils.toDIP(behavior.maxHeight.toFloat()))
361
374
  BottomSheetBehavior.STATE_EXPANDED -> SizeInfo(0, Utils.toDIP(behavior.maxHeight.toFloat()))
362
375
  else -> null
363
376
  }
@@ -324,7 +324,11 @@ class TrueSheetView(context: Context) :
324
324
  fun configureIfShowing() {
325
325
  if (sheetDialog.isShowing) {
326
326
  sheetDialog.configure()
327
- sheetDialog.positionFooter()
327
+ sheetDialog.setStateForSizeIndex(currentSizeIndex)
328
+
329
+ UiThreadUtil.runOnUiThread {
330
+ sheetDialog.positionFooter()
331
+ }
328
332
  }
329
333
  }
330
334
 
@@ -109,7 +109,7 @@ class TrueSheetViewManager : ViewGroupManager<TrueSheetView>() {
109
109
 
110
110
  @ReactProp(name = "background")
111
111
  fun setBackground(view: TrueSheetView, colorName: Double) {
112
- val color = runCatching { ColorPropConverter.getColor(colorName, view.context) }.getOrDefault(Color.WHITE)
112
+ val color = runCatching { ColorPropConverter.getColor(colorName, view.context) }.getOrNull() ?: Color.WHITE
113
113
  view.setBackground(color)
114
114
  }
115
115
 
@@ -433,11 +433,17 @@ class TrueSheetView: UIView, RCTInvalidating, TrueSheetViewControllerDelegate {
433
433
  }
434
434
 
435
435
  if isPresented {
436
- withPresentedSheet { sheet in
437
- sheet.selectedDetentIdentifier = viewController.detentIdentifierForIndex(index)
436
+ if #available(iOS 15.0, *) {
437
+ withPresentedSheet { sheet in
438
+ sheet.selectedDetentIdentifier = viewController.detentIdentifierForIndex(index)
438
439
 
440
+ // Trigger onSizeChange event when size is changed while presenting
441
+ viewControllerDidChangeSize(self.viewController.currentSizeInfo)
442
+ promise?.resolve(nil)
443
+ }
444
+ } else {
439
445
  // Trigger onSizeChange event when size is changed while presenting
440
- viewControllerDidChangeSize(self.viewController.currentSizeInfo)
446
+ viewControllerDidChangeSize(viewController.currentSizeInfo)
441
447
  promise?.resolve(nil)
442
448
  }
443
449
  } else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lodev09/react-native-true-sheet",
3
- "version": "2.0.5",
3
+ "version": "2.0.6",
4
4
  "description": "The true native bottom sheet experience for your React Native Apps.",
5
5
  "source": "./src/index.ts",
6
6
  "main": "./lib/commonjs/index.js",