react-native-sheet2 1.2.6 → 6.1.18

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.
Files changed (117) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +51 -32
  3. package/{react-native-sheet.podspec → Sheet.podspec} +7 -6
  4. package/android/build.gradle +43 -25
  5. package/android/generated/java/com/facebook/react/viewmanagers/SheetViewManagerDelegate.java +67 -0
  6. package/android/generated/java/com/facebook/react/viewmanagers/SheetViewManagerInterface.java +27 -0
  7. package/android/generated/java/com/sheet/NativeSheetSpec.java +78 -0
  8. package/android/generated/jni/CMakeLists.txt +36 -0
  9. package/android/generated/jni/RNSheetViewSpec-generated.cpp +50 -0
  10. package/android/generated/jni/RNSheetViewSpec.h +31 -0
  11. package/android/generated/jni/react/renderer/components/RNSheetViewSpec/ComponentDescriptors.cpp +22 -0
  12. package/android/generated/jni/react/renderer/components/RNSheetViewSpec/ComponentDescriptors.h +24 -0
  13. package/android/generated/jni/react/renderer/components/RNSheetViewSpec/EventEmitters.cpp +24 -0
  14. package/android/generated/jni/react/renderer/components/RNSheetViewSpec/EventEmitters.h +25 -0
  15. package/android/generated/jni/react/renderer/components/RNSheetViewSpec/Props.cpp +33 -0
  16. package/android/generated/jni/react/renderer/components/RNSheetViewSpec/Props.h +36 -0
  17. package/android/generated/jni/react/renderer/components/RNSheetViewSpec/RNSheetViewSpecJSI-generated.cpp +46 -0
  18. package/android/generated/jni/react/renderer/components/RNSheetViewSpec/RNSheetViewSpecJSI.h +98 -0
  19. package/android/generated/jni/react/renderer/components/RNSheetViewSpec/ShadowNodes.cpp +17 -0
  20. package/android/generated/jni/react/renderer/components/RNSheetViewSpec/ShadowNodes.h +32 -0
  21. package/android/generated/jni/react/renderer/components/RNSheetViewSpec/States.cpp +16 -0
  22. package/android/generated/jni/react/renderer/components/RNSheetViewSpec/States.h +29 -0
  23. package/android/gradle.properties +4 -5
  24. package/android/src/main/AndroidManifest.xml +0 -9
  25. package/android/src/main/AndroidManifestNew.xml +2 -0
  26. package/android/src/main/java/com/behavior/BottomSheetBehavior.java +10 -17
  27. package/android/src/main/java/com/sheet/AppFittedSheet.kt +107 -39
  28. package/android/src/main/java/com/sheet/BaseRNView.kt +81 -33
  29. package/android/src/main/java/com/sheet/CustomBottomSheetDialog.java +8 -0
  30. package/android/src/main/java/com/sheet/DialogRootViewGroup.kt +44 -33
  31. package/android/src/main/java/com/sheet/FragmentModalBottomSheet.kt +12 -2
  32. package/android/src/main/java/com/sheet/SafeAreaUtils.kt +90 -0
  33. package/android/src/main/java/com/sheet/SheetDismissEvent.kt +20 -0
  34. package/android/src/main/java/com/sheet/SheetModule.kt +37 -0
  35. package/android/src/main/java/com/sheet/SheetPackage.kt +32 -6
  36. package/android/src/main/java/com/sheet/SheetView.kt +5 -0
  37. package/android/src/main/java/com/sheet/SheetViewManager.kt +77 -56
  38. package/android/src/main/java/com/sheet/utils.kt +2 -10
  39. package/android/src/main/res/layout/dialog_bottom_sheet.xml +2 -2
  40. package/android/src/main/res/values/styles.xml +9 -0
  41. package/ios/FittedSheets/SheetContentViewController.swift +4 -4
  42. package/ios/FittedSheets/SheetViewController.swift +29 -100
  43. package/ios/HostFittedSheet.swift +271 -0
  44. package/ios/Sheet-Bridging-Header.h +1 -0
  45. package/ios/SheetModule.h +10 -0
  46. package/ios/SheetModule.mm +67 -0
  47. package/ios/SheetView.h +14 -0
  48. package/ios/SheetView.mm +129 -0
  49. package/ios/generated/RNSheetViewSpec/ComponentDescriptors.cpp +22 -0
  50. package/ios/generated/RNSheetViewSpec/ComponentDescriptors.h +24 -0
  51. package/ios/generated/RNSheetViewSpec/EventEmitters.cpp +24 -0
  52. package/ios/generated/RNSheetViewSpec/EventEmitters.h +25 -0
  53. package/ios/generated/RNSheetViewSpec/Props.cpp +33 -0
  54. package/ios/generated/RNSheetViewSpec/Props.h +36 -0
  55. package/ios/generated/RNSheetViewSpec/RCTComponentViewHelpers.h +44 -0
  56. package/ios/generated/RNSheetViewSpec/RNSheetViewSpec-generated.mm +60 -0
  57. package/ios/generated/RNSheetViewSpec/RNSheetViewSpec.h +100 -0
  58. package/ios/generated/RNSheetViewSpec/ShadowNodes.cpp +17 -0
  59. package/ios/generated/RNSheetViewSpec/ShadowNodes.h +32 -0
  60. package/ios/generated/RNSheetViewSpec/States.cpp +16 -0
  61. package/ios/generated/RNSheetViewSpec/States.h +29 -0
  62. package/ios/generated/RNSheetViewSpecJSI-generated.cpp +46 -0
  63. package/ios/generated/RNSheetViewSpecJSI.h +98 -0
  64. package/lib/module/FittedSheet.js +153 -0
  65. package/lib/module/FittedSheet.js.map +1 -0
  66. package/lib/module/NativeSheet.ts +17 -0
  67. package/lib/module/PublicSheetView.js +48 -0
  68. package/lib/module/PublicSheetView.js.map +1 -0
  69. package/lib/module/SheetViewNativeComponent.ts +31 -0
  70. package/lib/module/index.js +13 -0
  71. package/lib/module/index.js.map +1 -0
  72. package/lib/module/package.json +1 -0
  73. package/lib/typescript/package.json +1 -0
  74. package/lib/typescript/src/FittedSheet.d.ts +51 -0
  75. package/lib/typescript/src/FittedSheet.d.ts.map +1 -0
  76. package/lib/typescript/src/NativeSheet.d.ts +16 -0
  77. package/lib/typescript/src/NativeSheet.d.ts.map +1 -0
  78. package/lib/typescript/src/PublicSheetView.d.ts +12 -0
  79. package/lib/typescript/src/PublicSheetView.d.ts.map +1 -0
  80. package/lib/typescript/src/SheetViewNativeComponent.d.ts +22 -0
  81. package/lib/typescript/src/SheetViewNativeComponent.d.ts.map +1 -0
  82. package/lib/typescript/src/index.d.ts +8 -0
  83. package/lib/typescript/src/index.d.ts.map +1 -0
  84. package/package.json +109 -42
  85. package/react-native.config.js +12 -0
  86. package/src/FittedSheet.tsx +118 -95
  87. package/src/NativeSheet.ts +17 -0
  88. package/src/PublicSheetView.tsx +66 -0
  89. package/src/SheetViewNativeComponent.ts +31 -0
  90. package/src/index.tsx +26 -8
  91. package/android/src/main/java/com/modal/FullScreenDialog.kt +0 -100
  92. package/android/src/main/java/com/modal/TopModalView.kt +0 -77
  93. package/android/src/main/java/com/modal/TopModalViewManager.kt +0 -83
  94. package/android/src/main/java/com/modal/TopModalViewModule.kt +0 -40
  95. package/android/src/main/java/com/sheet/SheetViewModule.kt +0 -41
  96. package/ios/LBBottomSheet/BottomSheetConstant.swift +0 -48
  97. package/ios/LBBottomSheet/Model/BottomSheetController+Behavior.swift +0 -262
  98. package/ios/LBBottomSheet/Model/BottomSheetController+Theme.swift +0 -156
  99. package/ios/LBBottomSheet/Protocols/BottomSheetInteractionDelegate.swift +0 -29
  100. package/ios/LBBottomSheet/Protocols/BottomSheetPositionDelegate.swift +0 -31
  101. package/ios/LBBottomSheet/UI/BottomSheet.storyboard +0 -105
  102. package/ios/LBBottomSheet/UI/BottomSheetController.swift +0 -601
  103. package/ios/LBBottomSheet/Utils/Components/ForwardingEventsView.swift +0 -60
  104. package/ios/LBBottomSheet/Utils/Extensions/CACornerMask+Extension.swift +0 -33
  105. package/ios/LBBottomSheet/Utils/Extensions/Mirror+Extension.swift +0 -47
  106. package/ios/LBBottomSheet/Utils/Extensions/UIApplication+Extension.swift +0 -35
  107. package/ios/LBBottomSheet/Utils/Extensions/UIColor+Extension.swift +0 -61
  108. package/ios/LBBottomSheet/Utils/Extensions/UIGestureRecognizer+Extensions.swift +0 -28
  109. package/ios/LBBottomSheet/Utils/Extensions/UIScreen+Extension.swift +0 -28
  110. package/ios/LBBottomSheet/Utils/Extensions/UIScrollView+Extension.swift +0 -25
  111. package/ios/LBBottomSheet/Utils/Extensions/UIView+Extension.swift +0 -52
  112. package/ios/LBBottomSheet/Utils/Extensions/UIViewController+Extension.swift +0 -104
  113. package/ios/Sheet.xcodeproj/project.pbxproj +0 -377
  114. package/ios/SheetViewManager.m +0 -25
  115. package/ios/SheetViewManager.swift +0 -324
  116. package/ios/TopModalViewManager.swift +0 -196
  117. package/src/TopModal.tsx +0 -94
@@ -1,73 +1,121 @@
1
1
  package com.sheet
2
2
 
3
+ import android.annotation.SuppressLint
3
4
  import android.content.Context
4
5
  import android.view.MotionEvent
5
6
  import android.view.View
6
- import android.view.ViewGroup
7
- import com.facebook.react.bridge.ReactContext
7
+ import android.view.accessibility.AccessibilityNodeInfo
8
+ import androidx.annotation.UiThread
9
+ import com.facebook.react.bridge.GuardedRunnable
10
+ import com.facebook.react.bridge.WritableMap
11
+ import com.facebook.react.bridge.WritableNativeMap
8
12
  import com.facebook.react.config.ReactFeatureFlags
9
13
  import com.facebook.react.uimanager.JSPointerDispatcher
10
14
  import com.facebook.react.uimanager.JSTouchDispatcher
15
+ import com.facebook.react.uimanager.PixelUtil.pxToDp
11
16
  import com.facebook.react.uimanager.RootView
17
+ import com.facebook.react.uimanager.StateWrapper
18
+ import com.facebook.react.uimanager.ThemedReactContext
12
19
  import com.facebook.react.uimanager.UIManagerModule
13
20
  import com.facebook.react.uimanager.events.EventDispatcher
21
+ import com.facebook.react.views.view.ReactViewGroup
14
22
 
15
- open class BaseRNView(context: Context?) : ViewGroup(context), RootView {
16
- private val reactContext: ReactContext
17
- get() = context as ReactContext
18
- private val mJSTouchDispatcher = JSTouchDispatcher(this)
19
- private var mJSPointerDispatcher: JSPointerDispatcher? = null
23
+ open class BaseRNView(context: Context?) : ReactViewGroup(context), RootView {
24
+ internal var stateWrapper: StateWrapper? = null
25
+ internal var eventDispatcher: EventDispatcher? = null
26
+
27
+ private var viewWidth = 0
28
+ private var viewHeight = 0
29
+ private val jSTouchDispatcher: JSTouchDispatcher = JSTouchDispatcher(this)
30
+ private var jSPointerDispatcher: JSPointerDispatcher? = null
31
+
32
+ private val reactContext: ThemedReactContext
33
+ get() = context as ThemedReactContext
20
34
 
21
35
  init {
22
36
  if (ReactFeatureFlags.dispatchPointerEvents) {
23
- mJSPointerDispatcher = JSPointerDispatcher(this)
37
+ jSPointerDispatcher = JSPointerDispatcher(this)
24
38
  }
25
39
  }
26
40
 
27
- private val eventDispatcher: EventDispatcher
28
- get() {
29
- val reactContext = reactContext
30
- return reactContext.getNativeModule(UIManagerModule::class.java)!!.eventDispatcher
31
- }
32
-
33
- override fun onChildStartedNativeGesture(p0: View?, p1: MotionEvent?) {
34
- mJSTouchDispatcher.onChildStartedNativeGesture(p1, eventDispatcher)
35
- mJSPointerDispatcher?.onChildStartedNativeGesture(p0, p1, eventDispatcher)
41
+ override fun onInitializeAccessibilityNodeInfo(info: AccessibilityNodeInfo) {
42
+ super.onInitializeAccessibilityNodeInfo(info)
36
43
  }
37
44
 
38
- override fun onChildStartedNativeGesture(p0: MotionEvent?) {
39
- this.onChildStartedNativeGesture(null, p0)
45
+ override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
46
+ super.onSizeChanged(w, h, oldw, oldh)
47
+ viewWidth = w
48
+ viewHeight = h
49
+
50
+ updateState(viewWidth, viewHeight)
40
51
  }
41
52
 
42
- override fun onChildEndedNativeGesture(p0: View?, p1: MotionEvent?) {
43
- mJSTouchDispatcher.onChildEndedNativeGesture(p1, eventDispatcher)
44
- mJSPointerDispatcher?.onChildEndedNativeGesture()
53
+ @UiThread
54
+ public fun updateState(width: Int, height: Int) {
55
+ val realWidth: Float = width.toFloat().pxToDp()
56
+ val realHeight: Float = height.toFloat().pxToDp()
57
+
58
+ stateWrapper?.let { sw ->
59
+ // new architecture
60
+ val newStateData: WritableMap = WritableNativeMap()
61
+ newStateData.putDouble("screenWidth", realWidth.toDouble())
62
+ newStateData.putDouble("screenHeight", realHeight.toDouble())
63
+ sw.updateState(newStateData)
64
+ }
65
+ ?: run {
66
+ // old architecture
67
+ // TODO: T44725185 remove after full migration to Fabric
68
+ reactContext.runOnNativeModulesQueueThread(
69
+ object : GuardedRunnable(reactContext) {
70
+ override fun runGuarded() {
71
+ reactContext.reactApplicationContext
72
+ .getNativeModule(UIManagerModule::class.java)
73
+ ?.updateNodeSize(id, viewWidth, viewHeight)
74
+ }
75
+ })
76
+ }
45
77
  }
46
78
 
47
- override fun handleException(t: Throwable?) {
48
- reactContext.handleException(RuntimeException(t))
79
+ override fun handleException(t: Throwable) {
80
+ reactContext.reactApplicationContext.handleException(RuntimeException(t))
49
81
  }
50
82
 
51
83
  override fun onInterceptTouchEvent(event: MotionEvent): Boolean {
52
- mJSTouchDispatcher.handleTouchEvent(event, eventDispatcher)
53
- mJSPointerDispatcher?.handleMotionEvent(event, eventDispatcher, true)
84
+ eventDispatcher?.let { eventDispatcher ->
85
+ jSTouchDispatcher.handleTouchEvent(event, eventDispatcher, reactContext)
86
+ jSPointerDispatcher?.handleMotionEvent(event, eventDispatcher, true)
87
+ }
54
88
  return super.onInterceptTouchEvent(event)
55
89
  }
56
90
 
91
+ @SuppressLint("ClickableViewAccessibility")
57
92
  override fun onTouchEvent(event: MotionEvent): Boolean {
58
- try {
59
- mJSTouchDispatcher.handleTouchEvent(event, eventDispatcher)
60
- mJSPointerDispatcher?.handleMotionEvent(event, eventDispatcher, false)
61
- } catch (e: Throwable) {
62
- //e
93
+ eventDispatcher?.let { eventDispatcher ->
94
+ jSTouchDispatcher.handleTouchEvent(event, eventDispatcher, reactContext)
95
+ jSPointerDispatcher?.handleMotionEvent(event, eventDispatcher, false)
63
96
  }
64
97
  super.onTouchEvent(event)
98
+ // In case when there is no children interested in handling touch event, we return true from
99
+ // the root view in order to receive subsequent events related to that gesture
65
100
  return true
66
101
  }
67
102
 
68
- override fun onLayout(changed: Boolean, l: Int, t: Int, r: Int, b: Int) {
103
+ override fun onChildStartedNativeGesture(childView: View?, ev: MotionEvent) {
104
+ println("🐣 onChildStartedNativeGesture")
105
+ eventDispatcher?.let { eventDispatcher ->
106
+ jSTouchDispatcher.onChildStartedNativeGesture(ev, eventDispatcher)
107
+ jSPointerDispatcher?.onChildStartedNativeGesture(childView, ev, eventDispatcher)
108
+ }
109
+ }
69
110
 
111
+ override fun onChildEndedNativeGesture(childView: View, ev: MotionEvent) {
112
+ println("🐣 onChildEndedNativeGesture")
113
+ eventDispatcher?.let { jSTouchDispatcher.onChildEndedNativeGesture(ev, it) }
114
+ jSPointerDispatcher?.onChildEndedNativeGesture()
70
115
  }
71
116
 
72
- override fun requestDisallowInterceptTouchEvent(disallowIntercept: Boolean) = Unit
117
+ override fun requestDisallowInterceptTouchEvent(disallowIntercept: Boolean) {
118
+ // No-op - override in order to still receive events to onInterceptTouchEvent
119
+ // even when some other view disallow that
120
+ }
73
121
  }
@@ -27,6 +27,14 @@ public class CustomBottomSheetDialog extends AppCompatDialog {
27
27
  behavior.setNewNestedScrollView(view);
28
28
  }
29
29
 
30
+ public void collapse() {
31
+ behavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
32
+ }
33
+
34
+ public void expand() {
35
+ behavior.setState(BottomSheetBehavior.STATE_EXPANDED);
36
+ }
37
+
30
38
  public void setSheetBackgroundColor(int sheetBackgroundColor) {
31
39
  ViewGroup contentContainer = getContentContainer();
32
40
  if (contentContainer == null) return;
@@ -3,18 +3,23 @@ package com.sheet
3
3
  import android.content.Context
4
4
  import android.content.res.Resources
5
5
  import android.graphics.Outline
6
+ import android.os.Looper
6
7
  import android.view.View
7
8
  import android.view.ViewOutlineProvider
9
+ import androidx.appcompat.app.AppCompatActivity
10
+ import androidx.core.view.ViewCompat
11
+ import com.facebook.react.bridge.ReactContext
8
12
  import com.facebook.react.uimanager.PixelUtil
13
+ import com.facebook.react.uimanager.PixelUtil.pxToDp
9
14
  import kotlin.math.max
10
15
  import kotlin.math.min
11
16
 
12
17
  class DialogRootViewGroup(context: Context) : BaseRNView(context) {
13
- var reactView: View? = null
18
+ private var reactView: View? = null
14
19
 
15
- var sheetMaxHeightSize: Double = -1.0
16
- var sheetMaxWidthSize: Double = -1.0
17
- var sheetMinHeightSize: Double = -1.0
20
+ var sheetMaxHeightSize = Float.MAX_VALUE
21
+ var sheetMaxWidthSize = Float.MAX_VALUE
22
+ var sheetMinHeightSize = Float.MIN_VALUE
18
23
 
19
24
  private val metrics: Resources by lazy { Resources.getSystem() }
20
25
 
@@ -25,58 +30,64 @@ class DialogRootViewGroup(context: Context) : BaseRNView(context) {
25
30
  val top = 0
26
31
  val right = view.width
27
32
  val bottom = view.height
28
- val cornerRadius = PixelUtil.toPixelFromDIP(r).toInt()
29
- outline.setRoundRect(left, top, right, bottom + cornerRadius, cornerRadius.toFloat())
33
+ val cornerRadius = r
34
+ outline.setRoundRect(left, top, right, ((bottom + cornerRadius).toInt()), cornerRadius)
30
35
  }
31
36
  })
32
37
  setClipToOutline(true)
33
38
  }
34
39
 
35
- private val screenHeight: Int
36
- get() = metrics.displayMetrics.heightPixels
37
- private val screenWidth: Int
38
- get() = metrics.displayMetrics.widthPixels
39
- val currentWidth: Int
40
- get() = layoutParams?.width ?: 0
41
-
42
- private fun allowedHeight(): Int {
43
- var returnValue = if (sheetMaxHeightSize >= 0) {
44
- min(sheetMaxHeightSize.toInt(), screenHeight)
45
- } else {
46
- screenHeight
40
+ private val allowedHeight: Int
41
+ get() {
42
+ var returnValue = min(sheetMaxHeightSize.toInt(), metrics.displayMetrics.heightPixels)
43
+ returnValue = max(returnValue, sheetMinHeightSize.toInt())
44
+ return returnValue
47
45
  }
48
- returnValue = max(returnValue, sheetMinHeightSize.toInt())
49
- return returnValue
50
- }
51
46
 
52
- private fun allowedWidth(): Int {
53
- if (sheetMaxWidthSize >= 0) return min(sheetMaxWidthSize.toInt(), screenWidth)
54
- return screenWidth
55
- }
47
+ private val allowedWidth: Int
48
+ get() = min(sheetMaxWidthSize.toInt(), metrics.displayMetrics.widthPixels)
56
49
 
57
50
  private fun ensureLayoutParams() {
58
51
  if (layoutParams != null) return
59
52
  layoutParams = LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)
60
53
  }
61
54
 
55
+ private fun layout() {
56
+ if (Looper.myLooper() == Looper.getMainLooper()) {
57
+ parent?.requestLayout()
58
+ } else {
59
+ post { parent?.requestLayout() }
60
+ }
61
+ }
62
+
62
63
  fun setVirtualHeight(h: Float) {
63
64
  if (reactView == null) return
65
+ this.sheetMaxHeightSize = h
66
+ if (sheetMaxHeightSize == Float.MAX_VALUE) return
67
+ val newHeight = allowedHeight
68
+ val newWidth = allowedWidth
69
+ println("😀 DialogRootViewGroup.setVirtualHeight ${newHeight.pxToDp()} :${newWidth.pxToDp()}")
64
70
  ensureLayoutParams()
65
- this.sheetMaxHeightSize = h.toDouble()
66
- val newHeight = allowedHeight()
67
- val newWidth = allowedWidth()
68
- println("😀 DialogRootViewGroup.setVirtualHeight ${newHeight.toDP()} :${newWidth.toDP()}")
69
- translationX = ((screenWidth - newWidth) / 2).toFloat()
70
71
  layoutParams?.height = newHeight
72
+ translationX = ((metrics.displayMetrics.widthPixels - newWidth) / 2).toFloat()
73
+ layoutParams?.width = newWidth
74
+ layout()
75
+ }
76
+
77
+ fun updateMaxWidth(value: Float) {
78
+ sheetMaxWidthSize = value
79
+ val newWidth = allowedWidth
80
+ translationX = ((metrics.displayMetrics.widthPixels - newWidth) / 2).toFloat()
71
81
  layoutParams?.width = newWidth
82
+ layout()
72
83
  }
73
84
 
74
85
  override fun addView(child: View, index: Int, params: LayoutParams) {
75
86
  println("😀 DialogRootViewGroup.addView ${child.id}")
76
87
  if (reactView != null) removeView(reactView)
77
- super.addView(child, -1, params)
88
+ super.addView(child, index, params)
78
89
  reactView = child
79
- setVirtualHeight(sheetMaxHeightSize.toFloat())
90
+ setVirtualHeight(sheetMaxHeightSize)
80
91
  }
81
92
 
82
93
  override fun removeView(view: View?) {
@@ -92,7 +103,7 @@ class DialogRootViewGroup(context: Context) : BaseRNView(context) {
92
103
  override fun onLayout(changed: Boolean, l: Int, t: Int, r: Int, b: Int) {}
93
104
 
94
105
  private fun releaseReactView() {
95
- sheetMaxHeightSize = -1.0
106
+ sheetMaxHeightSize = Float.MAX_VALUE
96
107
  reactView = null
97
108
  }
98
109
  }
@@ -15,9 +15,11 @@ class FragmentModalBottomSheet(
15
15
  private val modalView: ViewGroup,
16
16
  private val dismissable: Boolean,
17
17
  private val isSystemUILight: Boolean,
18
- private val onDismiss: () -> Unit
18
+ private val onDismiss: (dismissAll: Boolean) -> Unit
19
19
  ) : BottomSheetDialogFragment() {
20
20
 
21
+ var dismissAll = false
22
+
21
23
  companion object {
22
24
  var presentedWindow: WeakReference<Window>? = null
23
25
  }
@@ -48,10 +50,18 @@ class FragmentModalBottomSheet(
48
50
  (dialog as CustomBottomSheetDialog).setNewNestedScrollView(view)
49
51
  }
50
52
 
53
+ fun collapse() {
54
+ (dialog as CustomBottomSheetDialog).collapse()
55
+ }
56
+
57
+ fun expand() {
58
+ (dialog as CustomBottomSheetDialog).expand()
59
+ }
60
+
51
61
  override fun onDismiss(dialog: DialogInterface) {
52
62
  super.onDismiss(dialog)
53
63
  presentedWindow?.clear()
54
64
  presentedWindow = null
55
- onDismiss()
65
+ onDismiss(dismissAll)
56
66
  }
57
67
  }
@@ -0,0 +1,90 @@
1
+ package com.sheet
2
+
3
+ import android.os.Build
4
+ import android.view.View
5
+ import android.view.ViewGroup
6
+ import android.view.WindowInsets
7
+ import androidx.annotation.RequiresApi
8
+ import com.facebook.react.uimanager.PixelUtil.pxToDp
9
+ import java.lang.IllegalArgumentException
10
+ import kotlin.math.max
11
+ import kotlin.math.min
12
+
13
+ internal data class EdgeInsets(val top: Float, val right: Float, val bottom: Float, val left: Float)
14
+ @RequiresApi(Build.VERSION_CODES.R)
15
+ private fun getRootWindowInsetsCompatR(rootView: View): EdgeInsets? {
16
+ val insets =
17
+ rootView.rootWindowInsets?.getInsets(
18
+ WindowInsets.Type.statusBars() or
19
+ WindowInsets.Type.displayCutout() or
20
+ WindowInsets.Type.navigationBars() or
21
+ WindowInsets.Type.captionBar())
22
+ ?: return null
23
+ return EdgeInsets(
24
+ top = insets.top.toFloat(),
25
+ right = insets.right.toFloat(),
26
+ bottom = insets.bottom.toFloat(),
27
+ left = insets.left.toFloat())
28
+ }
29
+
30
+ @RequiresApi(Build.VERSION_CODES.M)
31
+ @Suppress("DEPRECATION")
32
+ private fun getRootWindowInsetsCompatM(rootView: View): EdgeInsets? {
33
+ val insets = rootView.rootWindowInsets ?: return null
34
+ return EdgeInsets(
35
+ top = insets.systemWindowInsetTop.toFloat(),
36
+ right = insets.systemWindowInsetRight.toFloat(),
37
+ // System insets are more reliable to account for notches but the
38
+ // system inset for bottom includes the soft keyboard which we don't
39
+ // want to be consistent with iOS. Using the min value makes sure we
40
+ // never get the keyboard offset while still working with devices that
41
+ // hide the navigation bar.
42
+ bottom = min(insets.systemWindowInsetBottom, insets.stableInsetBottom).toFloat(),
43
+ left = insets.systemWindowInsetLeft.toFloat())
44
+ }
45
+
46
+ private fun getRootWindowInsetsCompatBase(rootView: View): EdgeInsets? {
47
+ val visibleRect = android.graphics.Rect()
48
+ rootView.getWindowVisibleDisplayFrame(visibleRect)
49
+ return EdgeInsets(
50
+ top = visibleRect.top.toFloat(),
51
+ right = (rootView.width - visibleRect.right).toFloat(),
52
+ bottom = (rootView.height - visibleRect.bottom).toFloat(),
53
+ left = visibleRect.left.toFloat())
54
+ }
55
+
56
+ private fun getRootWindowInsetsCompat(rootView: View): EdgeInsets? {
57
+ return when {
58
+ Build.VERSION.SDK_INT >= Build.VERSION_CODES.R -> getRootWindowInsetsCompatR(rootView)
59
+ Build.VERSION.SDK_INT >= Build.VERSION_CODES.M -> getRootWindowInsetsCompatM(rootView)
60
+ else -> getRootWindowInsetsCompatBase(rootView)
61
+ }
62
+ }
63
+
64
+ internal fun getSafeAreaInsets(view: View): EdgeInsets? {
65
+ // The view has not been layout yet.
66
+ if (view.height == 0) {
67
+ return null
68
+ }
69
+ val rootView = view.rootView
70
+ val windowInsets = getRootWindowInsetsCompat(rootView) ?: return null
71
+
72
+ // Calculate the part of the view that overlaps with window insets.
73
+ val windowWidth = rootView.width.toFloat()
74
+ val windowHeight = rootView.height.toFloat()
75
+ val visibleRect = android.graphics.Rect()
76
+ view.getGlobalVisibleRect(visibleRect)
77
+ return EdgeInsets(
78
+ top = max(windowInsets.top - visibleRect.top, 0f),
79
+ right = max(min(visibleRect.left + view.width - windowWidth, 0f) + windowInsets.right, 0f),
80
+ bottom = max(min(visibleRect.top + view.height - windowHeight, 0f) + windowInsets.bottom, 0f),
81
+ left = max(windowInsets.left - visibleRect.left, 0f))
82
+ }
83
+
84
+ internal fun edgeInsetsToJavaMap(insets: EdgeInsets): Map<String, Float> {
85
+ return mapOf(
86
+ "top" to insets.top.pxToDp(),
87
+ "right" to insets.right.pxToDp(),
88
+ "bottom" to insets.bottom.pxToDp(),
89
+ "left" to insets.left.pxToDp())
90
+ }
@@ -0,0 +1,20 @@
1
+ package com.sheet
2
+
3
+ import com.facebook.react.bridge.WritableMap
4
+ import com.facebook.react.uimanager.events.Event
5
+
6
+ class SheetDismissEvent(
7
+ surfaceId: Int,
8
+ viewId: Int,
9
+ ) : Event<SheetDismissEvent>(surfaceId, viewId) {
10
+ override fun getEventName() = EVENT_NAME
11
+
12
+ // All events for a given view can be coalesced.
13
+ override fun getCoalescingKey(): Short = 0
14
+
15
+ override fun getEventData(): WritableMap? = null
16
+
17
+ companion object {
18
+ const val EVENT_NAME = "onSheetDismiss"
19
+ }
20
+ }
@@ -0,0 +1,37 @@
1
+ package com.sheet
2
+
3
+ import android.view.ViewGroup
4
+ import androidx.appcompat.app.AppCompatActivity
5
+ import com.facebook.react.bridge.Arguments
6
+ import com.facebook.react.bridge.ReactApplicationContext
7
+ import com.facebook.react.bridge.WritableMap
8
+
9
+ class SheetModule(reactContext: ReactApplicationContext) : NativeSheetSpec(reactContext) {
10
+ override fun getTypedExportedConstants(): Map<String, Any> {
11
+ return getInitialWindowMetrics()
12
+ }
13
+
14
+ private fun getInitialWindowMetrics(): Map<String, Any> {
15
+ val decorView = reactApplicationContext.currentActivity?.window?.decorView as ViewGroup? ?: return emptyMap()
16
+ val insets = getSafeAreaInsets(decorView)
17
+ return if (insets == null) {
18
+ emptyMap()
19
+ } else mapOf("insets" to edgeInsetsToJavaMap(insets))
20
+ }
21
+
22
+ override fun viewportSize(): WritableMap {
23
+ return Arguments.createMap()
24
+ }
25
+
26
+ override fun dismissAll() {
27
+ reactApplicationContext.runOnUiQueueThread {
28
+ reactApplicationContext.currentActivity?.let { AppFittedSheet.dismissAll(it as AppCompatActivity) }
29
+ }
30
+ }
31
+
32
+ override fun dismissPresented() {
33
+ reactApplicationContext.runOnUiQueueThread {
34
+ reactApplicationContext.currentActivity?.let { AppFittedSheet.dismissPresented(it as AppCompatActivity) }
35
+ }
36
+ }
37
+ }
@@ -1,18 +1,44 @@
1
1
  package com.sheet
2
2
 
3
+ import com.facebook.react.BaseReactPackage
3
4
  import com.facebook.react.ReactPackage
4
5
  import com.facebook.react.bridge.NativeModule
5
6
  import com.facebook.react.bridge.ReactApplicationContext
7
+ import com.facebook.react.module.model.ReactModuleInfo
8
+ import com.facebook.react.module.model.ReactModuleInfoProvider
6
9
  import com.facebook.react.uimanager.ViewManager
7
- import com.modal.TopModalViewManager
8
- import com.modal.TopModalViewModule
10
+ import java.util.ArrayList
11
+
12
+ class SheetViewPackage : BaseReactPackage() {
13
+ override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
14
+ val viewManagers: MutableList<ViewManager<*, *>> = ArrayList()
15
+ viewManagers.add(SheetViewManager(reactContext))
16
+ return viewManagers
17
+ }
9
18
 
10
- class SheetPackage : ReactPackage {
11
19
  override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
12
- return listOf(SheetViewModule(reactContext), TopModalViewModule(reactContext))
20
+ return emptyList()
13
21
  }
14
22
 
15
- override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
16
- return listOf(SheetViewManager(), TopModalViewManager())
23
+ override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? {
24
+ if (name == NativeSheetSpec.NAME) {
25
+ return SheetModule(reactContext)
26
+ }
27
+ return null
28
+ }
29
+
30
+ override fun getReactModuleInfoProvider(): ReactModuleInfoProvider {
31
+ return ReactModuleInfoProvider {
32
+ val moduleInfos: MutableMap<String, ReactModuleInfo> = HashMap()
33
+ moduleInfos[NativeSheetSpec.NAME] = ReactModuleInfo(
34
+ NativeSheetSpec.NAME,
35
+ NativeSheetSpec.NAME,
36
+ false, // canOverrideExistingModule
37
+ false, // needsEagerInit
38
+ false, // isCxxModule
39
+ true // isTurboModule
40
+ )
41
+ moduleInfos
42
+ }
17
43
  }
18
44
  }
@@ -0,0 +1,5 @@
1
+ package com.sheet
2
+
3
+ import android.content.Context
4
+
5
+ class SheetView(context: Context) : AppFittedSheet(context)