@swmansion/react-native-bottom-sheet 0.7.2 → 0.7.3

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.
@@ -426,20 +426,18 @@ class BottomSheetView(context: Context) : ReactViewGroup(context) {
426
426
  private fun isScrollViewAtTop(): Boolean {
427
427
  val scrollView = findScrollView(sheetContainer) ?: return true
428
428
  if (!isTouchInsideView(scrollView)) return true
429
- return !scrollView.canScrollVertically(-1)
429
+ val inverted = isViewInverted(scrollView)
430
+ return if (inverted) !scrollView.canScrollVertically(1) else !scrollView.canScrollVertically(-1)
430
431
  }
431
432
 
432
433
  private fun isTouchInsideView(target: View): Boolean {
433
- val targetLocation = IntArray(2)
434
- target.getLocationOnScreen(targetLocation)
434
+ val rect = android.graphics.Rect()
435
+ if (!target.getGlobalVisibleRect(rect)) return false
435
436
  val myLocation = IntArray(2)
436
437
  getLocationOnScreen(myLocation)
437
- val touchScreenX = myLocation[0] + initialTouchX
438
- val touchScreenY = myLocation[1] + initialTouchY
439
- return touchScreenX >= targetLocation[0] &&
440
- touchScreenX < targetLocation[0] + target.width &&
441
- touchScreenY >= targetLocation[1] &&
442
- touchScreenY < targetLocation[1] + target.height
438
+ val touchScreenX = (myLocation[0] + initialTouchX).toInt()
439
+ val touchScreenY = (myLocation[1] + initialTouchY).toInt()
440
+ return rect.contains(touchScreenX, touchScreenY)
443
441
  }
444
442
 
445
443
  private fun findScrollView(view: View): View? {
@@ -452,6 +450,19 @@ class BottomSheetView(context: Context) : ReactViewGroup(context) {
452
450
  return null
453
451
  }
454
452
 
453
+ private fun isViewInverted(view: View): Boolean {
454
+ val values = FloatArray(9)
455
+ var current: View? = view
456
+ while (current != null && current !== sheetContainer) {
457
+ if (!current.matrix.isIdentity) {
458
+ current.matrix.getValues(values)
459
+ if (values[android.graphics.Matrix.MSCALE_Y] < 0) return true
460
+ }
461
+ current = current.parent as? View
462
+ }
463
+ return false
464
+ }
465
+
455
466
  // MARK: - Cleanup
456
467
 
457
468
  fun destroy() {
@@ -344,6 +344,15 @@ public final class RNSBottomSheetHostingView: UIView {
344
344
  return nil
345
345
  }
346
346
 
347
+ private func isViewInverted(_ view: UIView) -> Bool {
348
+ var current: UIView? = view
349
+ while let v = current, v !== sheetContainer {
350
+ if v.transform.d < 0 { return true }
351
+ current = v.superview
352
+ }
353
+ return false
354
+ }
355
+
347
356
  public override func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
348
357
  guard gestureRecognizer === panGesture else { return true }
349
358
 
@@ -365,6 +374,11 @@ public final class RNSBottomSheetHostingView: UIView {
365
374
  guard let scrollView = firstScrollView(in: sheetContainer) else { return true }
366
375
  let locationInScroll = panGesture.location(in: scrollView)
367
376
  guard scrollView.bounds.contains(locationInScroll) else { return true }
377
+ let inverted = isViewInverted(scrollView)
378
+ if inverted {
379
+ let maxOffsetY = scrollView.contentSize.height - scrollView.bounds.height + scrollView.adjustedContentInset.bottom
380
+ return scrollView.contentOffset.y >= maxOffsetY
381
+ }
368
382
  return scrollView.contentOffset.y <= 0
369
383
  }
370
384
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@swmansion/react-native-bottom-sheet",
3
- "version": "0.7.2",
3
+ "version": "0.7.3",
4
4
  "description": "Provides bottom-sheet components for React Native.",
5
5
  "main": "./lib/module/index.js",
6
6
  "types": "./lib/typescript/src/index.d.ts",