react-native-sheet2 1.1.23 → 1.2.0

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.
@@ -95,10 +95,10 @@ class AppFittedSheet(context: Context) : ViewGroup(context), LifecycleEventListe
95
95
  println("🥲 addView parentId: $id id: ${child.id}")
96
96
  UiThreadUtil.assertOnUiThread()
97
97
  mHostView.addView(child, index)
98
- val module = UIManagerHelper.getUIManager(context as ReactContext?, UIManagerType.DEFAULT) as UIManagerModule
99
- UIManagerHelper.getReactContext(this).runOnNativeModulesQueueThread {
100
- val resolveShadowNode = module.uiImplementation.resolveShadowNode(child.id)
101
- if (resolveShadowNode == null) return@runOnNativeModulesQueueThread
98
+ val ctx = context as ReactContext? ?: return
99
+ val module = UIManagerHelper.getUIManager(ctx, UIManagerType.DEFAULT) as? UIManagerModule ?: return
100
+ ctx.runOnNativeModulesQueueThread {
101
+ val resolveShadowNode = module?.uiImplementation?.resolveShadowNode(child.id) ?: return@runOnNativeModulesQueueThread
102
102
  val height = resolveShadowNode.layoutHeight
103
103
  if (height > 0) mHostView.setVirtualHeight(height)
104
104
  }
@@ -3,6 +3,7 @@ package com.sheet
3
3
  import android.content.Context
4
4
  import android.view.MotionEvent
5
5
  import android.view.View
6
+ import android.view.ViewGroup
6
7
  import com.facebook.react.bridge.ReactContext
7
8
  import com.facebook.react.config.ReactFeatureFlags
8
9
  import com.facebook.react.uimanager.JSPointerDispatcher
@@ -10,9 +11,8 @@ import com.facebook.react.uimanager.JSTouchDispatcher
10
11
  import com.facebook.react.uimanager.RootView
11
12
  import com.facebook.react.uimanager.UIManagerModule
12
13
  import com.facebook.react.uimanager.events.EventDispatcher
13
- import com.facebook.react.views.view.ReactViewGroup
14
14
 
15
- open class BaseRNView(context: Context?) : ReactViewGroup(context), RootView {
15
+ open class BaseRNView(context: Context?) : ViewGroup(context), RootView {
16
16
  private val reactContext: ReactContext
17
17
  get() = context as ReactContext
18
18
  private val mJSTouchDispatcher = JSTouchDispatcher(this)
@@ -62,12 +62,12 @@ open class BaseRNView(context: Context?) : ReactViewGroup(context), RootView {
62
62
  //e
63
63
  }
64
64
  super.onTouchEvent(event)
65
- // In case when there is no children interested in handling touch event, we return true from
66
- // the root view in order to receive subsequent events related to that gesture
67
65
  return true
68
66
  }
69
67
 
70
- // No-op - override in order to still receive events to onInterceptTouchEvent
71
- // even when some other view disallow that
68
+ override fun onLayout(changed: Boolean, l: Int, t: Int, r: Int, b: Int) {
69
+
70
+ }
71
+
72
72
  override fun requestDisallowInterceptTouchEvent(disallowIntercept: Boolean) = Unit
73
73
  }
@@ -145,24 +145,6 @@ public class CustomBottomSheetDialog extends AppCompatDialog {
145
145
  return behavior;
146
146
  }
147
147
 
148
- /**
149
- * Set to perform the swipe down animation when dismissing instead of the window animation for the
150
- * dialog.
151
- *
152
- * @param dismissWithAnimation True if swipe down animation should be used when dismissing.
153
- */
154
- public void setDismissWithAnimation(boolean dismissWithAnimation) {
155
- this.dismissWithAnimation = dismissWithAnimation;
156
- }
157
-
158
- /**
159
- * Returns if dismissing will perform the swipe down animation on the bottom sheet, rather than
160
- * the window animation for the dialog.
161
- */
162
- public boolean getDismissWithAnimation() {
163
- return dismissWithAnimation;
164
- }
165
-
166
148
  /**
167
149
  * Creates the container layout which must exist to find the behavior
168
150
  */
@@ -171,7 +153,7 @@ public class CustomBottomSheetDialog extends AppCompatDialog {
171
153
  container =
172
154
  (FrameLayout) View.inflate(getContext(), getDialogLayout(), null);
173
155
 
174
- FrameLayout bottomSheet = (FrameLayout) container.findViewById(R.id.design_bottom_sheet);
156
+ FrameLayout bottomSheet = container.findViewById(R.id.design_bottom_sheet);
175
157
  behavior = BottomSheetBehavior.from(bottomSheet);
176
158
  behavior.addBottomSheetCallback(bottomSheetCallback);
177
159
  behavior.setHideable(cancelable);
@@ -3,29 +3,13 @@ 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.util.TypedValue
7
- import android.view.MotionEvent
8
6
  import android.view.View
9
- import android.view.ViewGroup
10
7
  import android.view.ViewOutlineProvider
11
- import com.facebook.react.bridge.ReactContext
12
- import com.facebook.react.config.ReactFeatureFlags
13
- import com.facebook.react.uimanager.JSPointerDispatcher
14
- import com.facebook.react.uimanager.JSTouchDispatcher
15
- import com.facebook.react.uimanager.RootView
16
- import com.facebook.react.uimanager.UIManagerModule
17
- import com.facebook.react.uimanager.events.EventDispatcher
8
+ import com.facebook.react.uimanager.PixelUtil
18
9
  import kotlin.math.max
19
10
  import kotlin.math.min
20
11
 
21
- fun DialogRootViewGroup.eventDispatcher(): EventDispatcher {
22
- val reactContext = context as ReactContext
23
- return reactContext.getNativeModule(UIManagerModule::class.java)!!.eventDispatcher
24
- }
25
-
26
- class DialogRootViewGroup(context: Context) : ViewGroup(context), RootView {
27
- private val mJSTouchDispatcher = JSTouchDispatcher(this)
28
- private var mJSPointerDispatcher: JSPointerDispatcher? = null
12
+ class DialogRootViewGroup(context: Context) : BaseRNView(context) {
29
13
  var reactView: View? = null
30
14
 
31
15
  var sheetMaxHeightSize: Double = -1.0
@@ -41,9 +25,7 @@ class DialogRootViewGroup(context: Context) : ViewGroup(context), RootView {
41
25
  val top = 0
42
26
  val right = view.width
43
27
  val bottom = view.height
44
- val cornerRadius =
45
- TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, r, view.resources.displayMetrics)
46
- .toInt()
28
+ val cornerRadius = PixelUtil.toPixelFromDIP(r).toInt()
47
29
  outline.setRoundRect(left, top, right, bottom + cornerRadius, cornerRadius.toFloat())
48
30
  }
49
31
  })
@@ -52,20 +34,11 @@ class DialogRootViewGroup(context: Context) : ViewGroup(context), RootView {
52
34
 
53
35
  private val screenHeight: Int
54
36
  get() = metrics.displayMetrics.heightPixels
55
-
56
37
  private val screenWidth: Int
57
38
  get() = metrics.displayMetrics.widthPixels
58
- val currentHeight: Int
59
- get() = layoutParams?.height ?: 0
60
39
  val currentWidth: Int
61
40
  get() = layoutParams?.width ?: 0
62
41
 
63
- init {
64
- if (ReactFeatureFlags.dispatchPointerEvents) {
65
- mJSPointerDispatcher = JSPointerDispatcher(this)
66
- }
67
- }
68
-
69
42
  private fun allowedHeight(): Int {
70
43
  var returnValue = if (sheetMaxHeightSize >= 0) {
71
44
  min(sheetMaxHeightSize.toInt(), screenHeight)
@@ -116,40 +89,6 @@ class DialogRootViewGroup(context: Context) : ViewGroup(context), RootView {
116
89
  super.removeViewAt(index)
117
90
  }
118
91
 
119
- override fun onChildStartedNativeGesture(p0: View?, p1: MotionEvent?) {
120
- mJSTouchDispatcher.onChildStartedNativeGesture(p1, eventDispatcher())
121
- mJSPointerDispatcher?.onChildStartedNativeGesture(p0, p1, eventDispatcher())
122
- }
123
-
124
- override fun onChildStartedNativeGesture(p0: MotionEvent?) {
125
- this.onChildStartedNativeGesture(null, p0)
126
- }
127
-
128
- override fun onChildEndedNativeGesture(p0: View?, p1: MotionEvent?) {
129
- mJSTouchDispatcher.onChildEndedNativeGesture(p1, eventDispatcher())
130
- mJSPointerDispatcher?.onChildEndedNativeGesture()
131
- }
132
-
133
- override fun handleException(t: Throwable?) {
134
- (context as ReactContext).handleException(RuntimeException(t))
135
- }
136
-
137
- override fun onInterceptTouchEvent(event: MotionEvent): Boolean {
138
- mJSTouchDispatcher.handleTouchEvent(event, eventDispatcher())
139
- mJSPointerDispatcher?.handleMotionEvent(event, eventDispatcher(), true)
140
- return super.onInterceptTouchEvent(event)
141
- }
142
-
143
- override fun onTouchEvent(event: MotionEvent): Boolean {
144
- try {
145
- mJSTouchDispatcher.handleTouchEvent(event, eventDispatcher())
146
- mJSPointerDispatcher?.handleMotionEvent(event, eventDispatcher(), false)
147
- } catch (_: Throwable) { }
148
- super.onTouchEvent(event)
149
- return true
150
- }
151
-
152
- override fun requestDisallowInterceptTouchEvent(disallowIntercept: Boolean) = Unit
153
92
  override fun onLayout(changed: Boolean, l: Int, t: Int, r: Int, b: Int) {}
154
93
 
155
94
  private fun releaseReactView() {
@@ -6,15 +6,13 @@ import com.facebook.react.bridge.ReactApplicationContext
6
6
  import com.facebook.react.uimanager.ViewManager
7
7
  import com.modal.TopModalViewManager
8
8
  import com.modal.TopModalViewModule
9
- import com.transparent.activity.TransparentActivityManager
10
- import com.transparent.activity.TransparentActivityModule
11
9
 
12
10
  class SheetPackage : ReactPackage {
13
11
  override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
14
- return listOf(SheetViewModule(reactContext), TopModalViewModule(reactContext), TransparentActivityModule(reactContext))
12
+ return listOf(SheetViewModule(reactContext), TopModalViewModule(reactContext))
15
13
  }
16
14
 
17
15
  override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
18
- return listOf(SheetViewManager(), TopModalViewManager(), TransparentActivityManager())
16
+ return listOf(SheetViewManager(), TopModalViewManager())
19
17
  }
20
18
  }
@@ -1,64 +1,23 @@
1
1
  package com.sheet
2
2
 
3
- import android.view.View
4
3
  import com.facebook.react.bridge.ReactApplicationContext
5
- import com.facebook.react.bridge.ReactContext
6
4
  import com.facebook.react.bridge.ReadableMap
7
5
  import com.facebook.react.common.MapBuilder
8
6
  import com.facebook.react.uimanager.LayoutShadowNode
9
7
  import com.facebook.react.uimanager.NativeViewHierarchyOptimizer
10
- import com.facebook.react.uimanager.PixelUtil
11
- import com.facebook.react.uimanager.ReactShadowNodeImpl
12
8
  import com.facebook.react.uimanager.ReactStylesDiffMap
13
9
  import com.facebook.react.uimanager.StateWrapper
14
10
  import com.facebook.react.uimanager.ThemedReactContext
15
- import com.facebook.react.uimanager.UIManagerHelper
16
11
  import com.facebook.react.uimanager.UIViewOperationQueue
17
12
  import com.facebook.react.uimanager.ViewGroupManager
18
13
  import com.facebook.react.uimanager.annotations.ReactProp
19
14
  import com.facebook.react.uimanager.util.ReactFindViewUtil
20
- import com.facebook.yoga.YogaPositionType
21
15
 
22
16
  internal class ModalHostShadowNode : LayoutShadowNode() {
23
17
  companion object {
24
18
  val attachedViews = mutableMapOf<Int, AppFittedSheet>()
25
19
  }
26
20
 
27
- private var styledWidth: Float = 0f
28
- private var styledMaxHeight: Float = 0f
29
- private var styledMinHeight: Float = 0f
30
-
31
- /**
32
- * We need to set the styleWidth and styleHeight of the one child (represented by the <View></View>
33
- * within the <RCTModalHostView></RCTModalHostView> in Modal.js. This needs to fill the entire window.
34
- */
35
- override fun addChildAt(child: ReactShadowNodeImpl, i: Int) {
36
- super.addChildAt(child, i)
37
- child.setPositionType(YogaPositionType.ABSOLUTE)
38
- child.setStyleWidth(styledWidth)
39
- child.setStyleMinHeight(styledMinHeight)
40
- child.setStyleMaxHeight(styledMaxHeight)
41
- println("addChildAt ${styledWidth.toInt().toDP()} ${styledMaxHeight.toInt().toDP()} ${styledMinHeight.toInt().toDP()}")
42
- }
43
-
44
- override fun setStyleWidth(widthPx: Float) {
45
- super.setStyleWidth(widthPx)
46
- styledWidth = widthPx
47
- println("😀 setStyleWidth id: ${styledWidth.toInt().toDP()}")
48
- }
49
-
50
- override fun setStyleMaxHeight(widthPx: Float) {
51
- super.setStyleMaxHeight(widthPx)
52
- styledMaxHeight = widthPx
53
- println("😀 setStyleMaxHeight id: ${styledMaxHeight.toInt().toDP()}")
54
- }
55
-
56
- override fun setStyleMinHeight(widthPx: Float) {
57
- super.setStyleMinHeight(widthPx)
58
- styledMinHeight = widthPx
59
- println("😀 setStyleMinHeight id: ${styledMinHeight.toInt().toDP()}")
60
- }
61
-
62
21
  override fun dispatchUpdates(absoluteX: Float, absoluteY: Float, uiViewOperationQueue: UIViewOperationQueue?, nativeViewHierarchyOptimizer: NativeViewHierarchyOptimizer?) {
63
22
  super.dispatchUpdates(absoluteX, absoluteY, uiViewOperationQueue, nativeViewHierarchyOptimizer)
64
23
  val newHeight = getChildAt(0).layoutHeight
@@ -68,7 +27,6 @@ internal class ModalHostShadowNode : LayoutShadowNode() {
68
27
  } else {
69
28
  it.setVirtualHeight(newHeight)
70
29
  getChildAt(0).setStyleWidth(it.currentWidth.toFloat())
71
- println("😀 dispatchUpdates ${it.currentWidth.toDP()} pa: ${it.currentHeight.toDP()}")
72
30
  }
73
31
  }
74
32
  }
@@ -100,23 +58,6 @@ class SheetViewManager : ViewGroupManager<AppFittedSheet>() {
100
58
  view.setNewNestedScrollView(v)
101
59
  }
102
60
 
103
- @ReactProp(name = "increaseHeight")
104
- fun setIncreaseHeight(view: AppFittedSheet, by: Double) {
105
- if (by == 0.0) return
106
- val newHeight = view.mHostView.currentHeight + PixelUtil.toPixelFromDIP(by)
107
- view.mHostView.setVirtualHeight(newHeight)
108
- view.setNewShadowSize(view.mHostView.currentWidth, view.mHostView.currentHeight)
109
- }
110
-
111
- @ReactProp(name = "decreaseHeight")
112
- fun setDecreaseHeight(view: AppFittedSheet, by: Double) {
113
- if (by == 0.0) return
114
- val newHeight = view.mHostView.currentHeight - PixelUtil.toPixelFromDIP(by)
115
- println("🥲decreaseHeight from: ${view.mHostView.currentHeight} to: $newHeight")
116
- view.mHostView.setVirtualHeight(newHeight)
117
- view.setNewShadowSize(view.mHostView.currentWidth, view.mHostView.currentHeight)
118
- }
119
-
120
61
  override fun getExportedCustomDirectEventTypeConstants(): Map<String, Any>? {
121
62
  return MapBuilder.builder<String, Any>()
122
63
  .put("onSheetDismiss", MapBuilder.of("registrationName", "onSheetDismiss"))
@@ -1,7 +1,5 @@
1
1
  package com.sheet
2
2
 
3
- import android.os.Handler
4
- import android.os.Looper
5
3
  import android.util.Log
6
4
  import com.facebook.react.bridge.ReactApplicationContext
7
5
  import com.facebook.react.bridge.ReactContextBaseJavaModule
@@ -35,7 +33,7 @@ class SheetViewModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
35
33
 
36
34
  @ReactMethod
37
35
  fun dismiss(viewTag: Int) {
38
- Handler(Looper.getMainLooper()).post {
36
+ reactApplicationContext.runOnUiQueueThread {
39
37
  val view = findSheetView(viewTag)
40
38
  view?.dismiss()
41
39
  }
@@ -5,26 +5,14 @@ import android.graphics.Color
5
5
  import android.view.View
6
6
  import android.view.Window
7
7
  import com.facebook.react.bridge.ColorPropConverter
8
- import com.facebook.react.bridge.ReactContext
9
8
  import com.facebook.react.bridge.ReadableMap
10
9
  import com.facebook.react.uimanager.PixelUtil
11
- import com.facebook.react.uimanager.UIManagerHelper
12
- import com.facebook.react.uimanager.UIManagerModule
13
- import com.facebook.react.uimanager.common.UIManagerType
14
10
 
15
11
 
16
12
  fun Int.toDP(): Int {
17
13
  return PixelUtil.toDIPFromPixel(this.toFloat()).toInt()
18
14
  }
19
15
 
20
- fun Double.toDP(): Int {
21
- return PixelUtil.toDIPFromPixel(this.toFloat()).toInt()
22
- }
23
-
24
- fun Float.toDP(): Float {
25
- return PixelUtil.toDIPFromPixel(this)
26
- }
27
-
28
16
  fun Double.toPxD(): Double {
29
17
  return PixelUtil.toPixelFromDIP(this.toFloat()).toDouble()
30
18
  }
@@ -52,14 +40,6 @@ fun ReadableMap.color(value: String, context: Context): Int {
52
40
  return ColorPropConverter.getColor(getDouble("backgroundColor"), context)
53
41
  }
54
42
 
55
- fun View.setNewShadowSize(width: Int, height: Int) {
56
- val module = UIManagerHelper.getUIManager(context as ReactContext?, UIManagerType.DEFAULT) as UIManagerModule
57
- UIManagerHelper.getReactContext(this).runOnNativeModulesQueueThread {
58
- val id = module.uiImplementation.resolveShadowNode(this.id).getChildAt(0).reactTag
59
- module.updateNodeSize(id, width, height)
60
- }
61
- }
62
-
63
43
  fun Window.updateStatusBar(isLight: Boolean) {
64
44
  if (isLight) {
65
45
  decorView.systemUiVisibility =
@@ -245,11 +245,8 @@ public class SheetViewController: UIViewController {
245
245
 
246
246
  /// Change the sizes the sheet should try to pin to
247
247
  public func setSizes(_ sizes: [SheetSize], animated: Bool = true) {
248
- guard sizes.count > 0 else {
249
- return
250
- }
248
+ guard sizes.count > 0 else { return }
251
249
  self.sizes = sizes
252
-
253
250
  self.resize(to: sizes[0], animated: animated)
254
251
  }
255
252
 
@@ -540,7 +537,7 @@ public class SheetViewController: UIViewController {
540
537
  options: UIView.AnimationOptions = [.curveEaseOut],
541
538
  animated: Bool = true,
542
539
  complete: (() -> Void)? = nil) {
543
-
540
+ debugPrint("ShetViewController.resizeTo", size)
544
541
  let previousSize = self.currentSize
545
542
  self.currentSize = size
546
543
 
@@ -8,8 +8,6 @@ RCT_EXPORT_VIEW_PROPERTY(onSheetDismiss, RCTDirectEventBlock)
8
8
  RCT_EXPORT_VIEW_PROPERTY(fittedSheetParams, NSDictionary)
9
9
  RCT_EXPORT_VIEW_PROPERTY(passScrollViewReactTag, NSString)
10
10
 
11
- RCT_EXPORT_VIEW_PROPERTY(increaseHeight, NSNumber)
12
- RCT_EXPORT_VIEW_PROPERTY(decreaseHeight, NSNumber)
13
11
  RCT_EXTERN_METHOD(dismiss:(nonnull NSNumber *)node)
14
12
 
15
13
  @end
@@ -25,35 +25,26 @@ class ModalHostShadowView: RCTShadowView {
25
25
  subview.position = .absolute
26
26
  }
27
27
  }
28
-
28
+
29
+ func renderSizes(subviews: [RCTShadowView]?) {
30
+ guard let subviews else { return }
31
+ for v in subviews {
32
+ debugPrint(v)
33
+ renderSizes(subviews: v.reactSubviews())
34
+ }
35
+ }
36
+
29
37
  override func layoutSubviews(with layoutContext: RCTLayoutContext) {
30
38
  super.layoutSubviews(with: layoutContext)
31
- let tag = self.reactTag.intValue
32
- var size = reactSubviews()[0].contentFrame.size
33
-
34
- DispatchQueue.main.async {
35
- let view = ModalHostShadowView.attachedViews[tag]
36
- let maxWidth = view?.sheetWidth ?? .infinity
37
- let maxheight = view?.sheetMaxHeightSize?.doubleValue ?? .infinity
38
- let minHeight = view?.sheetMinHeightSize?.doubleValue ?? .zero
39
-
40
- if size.height > maxheight {
41
- debugPrint("😀 constraint \(tag) \(size) \(maxheight)")
42
- size.height = maxheight
43
- view!.notifyForBoundsChange(newBounds: size)
44
- }
45
- if size.height < minHeight {
46
- debugPrint("😀 constraint \(tag) \(size) \(minHeight)")
47
- size.height = minHeight
48
- view!.notifyForBoundsChange(newBounds: size)
49
- }
50
- if size.width > maxWidth {
51
- debugPrint("😀 constraint \(tag) \(size) \(maxWidth)")
52
- size.width = maxWidth
53
- view!.notifyForBoundsChange(newBounds: size)
54
- }
39
+
40
+ RCTExecuteOnMainQueue { [weak self] in
41
+ guard let self else { return }
42
+ let view = RCTBridge.current().uiManager.view(
43
+ forReactTag: self.reactTag) as? HostFittedSheet
44
+ let v = self.reactSubviews()[0]
45
+ let size = v.contentFrame.size
46
+ debugPrint("😀 ModalHostShadowView.layoutSubviews", size)
55
47
  view?._modalViewController?.setSizes([.fixed(size.height)])
56
- debugPrint("😀 layout(with \(tag) \(size) \(maxheight)")
57
48
  }
58
49
  }
59
50
  }
@@ -119,20 +110,13 @@ class HostFittedSheet: UIView {
119
110
  @objc
120
111
  private var onSheetDismiss: RCTDirectEventBlock?
121
112
 
122
- @objc
123
- func setIncreaseHeight(_ by: NSNumber) {
124
- if by.floatValue == 0 { return }
125
- debugPrint("setIncreaseHeight", by.floatValue)
126
- changeHeight(by.floatValue)
127
- }
128
-
129
- @objc
130
- func setDecreaseHeight(_ by: NSNumber) {
131
- if by.floatValue == 0 { return }
132
- debugPrint("setDecreaseHeight", -by.floatValue)
133
- changeHeight(-by.floatValue)
134
- }
135
-
113
+ var sheetMaxWidthSize: NSNumber?
114
+ private var dismissable = true
115
+ var sheetMaxHeightSize: NSNumber?
116
+ var sheetMinHeightSize: NSNumber?
117
+ private var topLeftRightCornerRadius: NSNumber?
118
+ private var sheetBackgroundColor: UIColor?
119
+
136
120
  @objc
137
121
  func setPassScrollViewReactTag(_ tag: NSNumber) {
138
122
  debugPrint("😀 setPassScrollViewReactTag", tag)
@@ -146,28 +130,6 @@ class HostFittedSheet: UIView {
146
130
  self._modalViewController?.handleScrollView(scrollView.scrollView)
147
131
  }
148
132
 
149
- private func changeHeight(_ by: Float) {
150
- if !_isPresented { return }
151
- guard let reactSubView = _reactSubview else { return }
152
-
153
- let newHeight = CGFloat(by)
154
- if reactSubView.frame.height == newHeight { return }
155
- let increasedHeight = reactSubView.frame.height + newHeight
156
- debugPrint("changeHeight from", reactSubView.frame.height, "to", increasedHeight)
157
- let sizes: [SheetSize] = [.fixed(increasedHeight)]
158
- self._modalViewController?.sizes = sizes
159
- self._modalViewController?.resize(to: sizes[0], animated: true)
160
- self.notifyForBoundsChange(newBounds: .init(width: reactSubView.frame.width, height: increasedHeight))
161
- debugPrint("", increasedHeight)
162
- }
163
-
164
- var sheetMaxWidthSize: NSNumber?
165
- private var dismissable = true
166
- var sheetMaxHeightSize: NSNumber?
167
- var sheetMinHeightSize: NSNumber?
168
- private var topLeftRightCornerRadius: NSNumber?
169
- private var sheetBackgroundColor: UIColor?
170
-
171
133
  @objc
172
134
  var fittedSheetParams: NSDictionary? {
173
135
  didSet {
@@ -195,13 +157,6 @@ class HostFittedSheet: UIView {
195
157
  fatalError("init(coder:) has not been implemented")
196
158
  }
197
159
 
198
- func notifyForBoundsChange(newBounds: CGSize) {
199
- if (_reactSubview != nil && _isPresented) {
200
- debugPrint("😀notifyForBoundsChange \(newBounds)")
201
- _bridge?.uiManager.setSize(newBounds, for: _reactSubview!)
202
- }
203
- }
204
-
205
160
  override func insertReactSubview(_ subview: UIView!, at atIndex: Int) {
206
161
  debugPrint("😀insertReactSubview")
207
162
  super.insertReactSubview(subview, at: atIndex)
@@ -246,24 +201,19 @@ class HostFittedSheet: UIView {
246
201
  size = .init(width: self.sheetWidth, height: CGFloat(self._sheetSize!.floatValue))
247
202
  debugPrint("😀 else", size)
248
203
  }
249
- var shouldUpdate = false
204
+
250
205
  if size.width > self.sheetWidth {
251
206
  size.width = self.sheetWidth
252
- shouldUpdate = true
253
207
  }
254
208
  // if maxSize is present notify react native view
255
209
  if self.sheetMaxHeightSize != nil && size.height > self.sheetMaxHeightSize!.doubleValue {
256
210
  size.height = self.sheetMaxHeightSize!.doubleValue
257
- shouldUpdate = true
258
211
  }
259
212
  // if maxSize is present notify react native view
260
213
  if self.sheetMinHeightSize != nil && size.height < self.sheetMinHeightSize!.doubleValue {
261
214
  size.height = self.sheetMinHeightSize!.doubleValue
262
- shouldUpdate = true
263
- }
264
- if shouldUpdate {
265
- self.notifyForBoundsChange(newBounds: size)
266
215
  }
216
+
267
217
  self._modalViewController = SheetViewController(
268
218
  controller: self.viewController,
269
219
  sizes: [.fixed(size.height)],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-sheet2",
3
- "version": "1.1.23",
3
+ "version": "1.2.0",
4
4
  "description": "Native implementation of Bottom sheet",
5
5
  "main": "src/index",
6
6
  "module": "src/index",
@@ -2,6 +2,7 @@ import React, { createContext, useContext } from 'react';
2
2
  import {
3
3
  Dimensions,
4
4
  findNodeHandle,
5
+ type LayoutChangeEvent,
5
6
  NativeModules,
6
7
  processColor,
7
8
  requireNativeComponent,
@@ -41,6 +42,7 @@ interface Props {
41
42
  interface State {
42
43
  show: boolean;
43
44
  data: any | null;
45
+ maxHeight: number;
44
46
  }
45
47
 
46
48
  export const FITTED_SHEET_SCROLL_VIEW = 'fittedSheetScrollView';
@@ -65,7 +67,7 @@ export class FittedSheet extends React.PureComponent<Props, State> {
65
67
  private sheetRef = React.createRef<any>();
66
68
  constructor(props: Props) {
67
69
  super(props);
68
- this.state = { show: false, data: null };
70
+ this.state = { show: false, data: null, maxHeight: -1 };
69
71
  }
70
72
 
71
73
  show = (data?: any) => {
@@ -74,6 +76,11 @@ export class FittedSheet extends React.PureComponent<Props, State> {
74
76
 
75
77
  data = () => this.state.data;
76
78
 
79
+ onLayout = (e: LayoutChangeEvent) => {
80
+ console.log('🍓[FittedSheet.onLayout]', e.nativeEvent.layout.height);
81
+ this.setState({ maxHeight: e.nativeEvent.layout.height });
82
+ };
83
+
77
84
  toggle = () => {
78
85
  this.setState({ show: !this.state.show });
79
86
  };
@@ -84,11 +91,16 @@ export class FittedSheet extends React.PureComponent<Props, State> {
84
91
  };
85
92
 
86
93
  increaseHeight = (by: number) => {
87
- this.sheetRef.current?.setNativeProps({ increaseHeight: by });
94
+ //this.sheetRef.current?.setNativeProps({ increaseHeight: by });
95
+ this.setState({ maxHeight: this.state.maxHeight + by });
88
96
  };
89
97
 
90
98
  decreaseHeight = (by: number) => {
91
- this.sheetRef.current?.setNativeProps({ decreaseHeight: by });
99
+ const minHeight = this.props.params?.minHeight;
100
+ this.setState({
101
+ maxHeight: Math.max(minHeight ?? 0, this.state.maxHeight - by),
102
+ });
103
+ //this.sheetRef.current?.setNativeProps({ decreaseHeight: by });
92
104
  };
93
105
 
94
106
  hide = (passThroughParam?: any) => {
@@ -128,12 +140,15 @@ export class FittedSheet extends React.PureComponent<Props, State> {
128
140
 
129
141
  render() {
130
142
  if (!this.state.show) return null;
143
+
131
144
  const dim = Dimensions.get('screen');
132
145
  const isLandscape = dim.width > dim.height;
133
- const maxHeight = Math.min(
146
+
147
+ let maxHeight = Math.min(
134
148
  this.props.params?.maxHeight ?? Number.MAX_VALUE,
135
149
  dim.height - (StatusBar.currentHeight ?? 0)
136
150
  );
151
+
137
152
  const paramsMaxWidth = isLandscape
138
153
  ? this.props.params?.maxLandscapeWidth
139
154
  : this.props.params?.maxPortraitWidth;
@@ -162,7 +177,11 @@ export class FittedSheet extends React.PureComponent<Props, State> {
162
177
  }
163
178
  >
164
179
  <FittedSheetContext.Provider value={this}>
165
- <View nativeID={'fitted-sheet-root-view'}>
180
+ <View
181
+ nativeID={'fitted-sheet-root-view'}
182
+ style={{ maxHeight, minHeight, maxWidth }}
183
+ onLayout={this.onLayout}
184
+ >
166
185
  {this.props.children &&
167
186
  typeof this.props.children === 'function' &&
168
187
  this.props.children(this.state.data)}
@@ -1,24 +0,0 @@
1
- package com.sheet;
2
-
3
- import android.view.View;
4
-
5
- import com.facebook.react.bridge.GuardedRunnable;
6
- import com.facebook.react.bridge.ReactContext;
7
- import com.facebook.react.uimanager.UIManagerModule;
8
-
9
- public class ReactNativeReflection {
10
- static void setSize(View view, int width, int height) {
11
- final View v = view;
12
- ReactContext context = (ReactContext) v.getContext();
13
- context.runOnNativeModulesQueueThread(new GuardedRunnable(context) {
14
- @Override
15
- public void runGuarded() {
16
- if (v.getParent() == null) return;
17
- if (!v.isAttachedToWindow()) return;
18
- UIManagerModule managerModule = context.getNativeModule(UIManagerModule.class);
19
- if (managerModule == null) return;
20
- managerModule.updateNodeSize(v.getId(), width, height);
21
- }
22
- });
23
- }
24
- }
@@ -1,71 +0,0 @@
1
- package com.transparent.activity
2
-
3
- import android.content.Context
4
- import android.content.Intent
5
- import android.view.View
6
- import android.view.WindowManager
7
- import android.view.accessibility.AccessibilityEvent
8
- import androidx.appcompat.app.AppCompatActivity
9
- import com.facebook.react.bridge.Arguments
10
- import com.facebook.react.bridge.ReactContext
11
- import com.facebook.react.bridge.UiThreadUtil
12
- import com.facebook.react.uimanager.events.RCTEventEmitter
13
- import com.facebook.react.views.view.ReactViewGroup
14
- import com.modal.TopModalView
15
- import com.sheet.BaseRNView
16
- import java.lang.ref.WeakReference
17
-
18
- fun ActivityModalView.onActivityDismiss() {
19
- (context as ReactContext).getJSModule(RCTEventEmitter::class.java)
20
- .receiveEvent(id, "onActivityDismiss", Arguments.createMap())
21
- }
22
-
23
- class ActivityModalView(context: Context?) : ReactViewGroup(context) {
24
- private var rnView = BaseRNView(context)
25
- init {
26
- println("🗡️ init")
27
- TransparentActivity.parentView = WeakReference(this)
28
- val intent = Intent(getCurrentActivity()!!, TransparentActivity::class.java)
29
- getCurrentActivity()?.startActivity(intent)
30
-
31
- }
32
-
33
- fun getCurrentActivity(): AppCompatActivity? {
34
- return (context as? ReactContext)?.currentActivity as? AppCompatActivity
35
- }
36
-
37
- override fun addView(child: View, index: Int) {
38
- rnView.addView(child)
39
- if (TransparentActivity.presentedInstance == null) {
40
- TransparentActivity.deferredView = WeakReference(rnView)
41
- }
42
- val activity = TransparentActivity.presentedInstance?.get() ?: return
43
- activity.setContentView(rnView)
44
- }
45
-
46
- override fun addChildrenForAccessibility(outChildren: ArrayList<View?>?) {}
47
- override fun dispatchPopulateAccessibilityEvent(event: AccessibilityEvent?) = false
48
-
49
-
50
- override fun removeView(child: View?) {
51
- println("🗡️️ removeView")
52
- UiThreadUtil.assertOnUiThread()
53
- dismiss()
54
- }
55
-
56
- override fun removeViewAt(index: Int) {
57
- println("🗡️️ removeViewAt: $index")
58
- UiThreadUtil.assertOnUiThread()
59
- dismiss()
60
- }
61
-
62
- fun onDismiss() {
63
- println("🗡️ onDismiss")
64
- onActivityDismiss()
65
- }
66
-
67
- fun dismiss() {
68
- println("🗡️️ dismiss")
69
- TransparentActivity.presentedInstance?.get()?.finish();
70
- }
71
- }
@@ -1,48 +0,0 @@
1
- package com.transparent.activity
2
-
3
- import android.os.Bundle
4
- import android.view.View
5
- import android.view.WindowManager
6
- import androidx.appcompat.app.AppCompatActivity
7
- import java.lang.ref.WeakReference
8
-
9
- class TransparentActivity : AppCompatActivity() {
10
- init {
11
- println("🗡️ TransparentActivity.init")
12
- presentedInstance = WeakReference(this)
13
- }
14
-
15
- override fun onCreate(savedInstanceState: Bundle?) {
16
- window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN)
17
- super.onCreate(savedInstanceState)
18
- println("🗡️ TransparentActivity.onCreate")
19
- parentView?.get()?.getCurrentActivity()?.window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING)
20
- deferredView?.get()?.let { setContentView(it) }
21
- deferredView = null
22
- }
23
-
24
- private fun dismiss() {
25
- println("🗡️ TransparentActivity.dismiss")
26
- parentView?.get()?.onDismiss()
27
- parentView?.get()?.getCurrentActivity()?.window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE)
28
- presentedInstance = null
29
- }
30
-
31
- override fun finish() {
32
- super.finish()
33
- println("🗡️ TransparentActivity.finish")
34
- dismiss()
35
- }
36
-
37
- override fun onBackPressed() {
38
- super.onBackPressed()
39
- println("🗡️ TransparentActivity.onBackPressed")
40
- dismiss()
41
- }
42
-
43
- companion object {
44
- var presentedInstance: WeakReference<TransparentActivity>? = null
45
- var deferredView: WeakReference<View>? = null
46
- var parentView: WeakReference<ActivityModalView>? = null
47
- }
48
- }
@@ -1,63 +0,0 @@
1
- package com.transparent.activity
2
-
3
- import android.content.res.Resources
4
- import android.view.View
5
- import com.facebook.react.bridge.ReactApplicationContext
6
- import com.facebook.react.common.MapBuilder
7
- import com.facebook.react.uimanager.LayoutShadowNode
8
- import com.facebook.react.uimanager.ReactShadowNodeImpl
9
- import com.facebook.react.uimanager.ThemedReactContext
10
- import com.facebook.react.uimanager.ViewGroupManager
11
- import com.facebook.yoga.YogaPositionType
12
-
13
- private class ModalHostShadowNode : LayoutShadowNode() {
14
- override fun addChildAt(child: ReactShadowNodeImpl, i: Int) {
15
- super.addChildAt(child, i)
16
- val display = Resources.getSystem().displayMetrics
17
- child.setStyleWidth(display.widthPixels.toFloat())
18
- child.setStyleHeight(display.heightPixels.toFloat())
19
- child.setPositionType(YogaPositionType.ABSOLUTE)
20
- }
21
- }
22
-
23
- class TransparentActivityManager : ViewGroupManager<ActivityModalView>() {
24
- override fun getName() = "TransparentActivity"
25
-
26
- override fun createViewInstance(reactContext: ThemedReactContext): ActivityModalView {
27
- return ActivityModalView(reactContext)
28
- }
29
-
30
- override fun getExportedCustomDirectEventTypeConstants(): Map<String, Any>? {
31
- return MapBuilder.builder<String, Any>()
32
- .put("onActivityDismiss", MapBuilder.of("registrationName", "onActivityDismiss"))
33
- .build()
34
- }
35
-
36
- override fun getShadowNodeClass(): Class<LayoutShadowNode> {
37
- return ModalHostShadowNode::class.java as Class<LayoutShadowNode>
38
- }
39
-
40
- override fun createShadowNodeInstance(): LayoutShadowNode {
41
- return ModalHostShadowNode()
42
- }
43
-
44
- override fun createShadowNodeInstance(context: ReactApplicationContext): LayoutShadowNode {
45
- println("⚽️ createShadowNodeInstance")
46
- return ModalHostShadowNode()
47
- }
48
-
49
- override fun removeView(parent: ActivityModalView?, view: View?) {
50
- super.removeView(parent, view)
51
- println("⚽️ removeView")
52
- }
53
-
54
- override fun removeViewAt(parent: ActivityModalView?, index: Int) {
55
- super.removeViewAt(parent, index)
56
- println("⚽️ removeViewAt")
57
- }
58
-
59
- override fun onDropViewInstance(view: ActivityModalView) {
60
- super.onDropViewInstance(view)
61
- view.dismiss()
62
- }
63
- }
@@ -1,28 +0,0 @@
1
- package com.transparent.activity
2
-
3
- import android.os.Handler
4
- import android.os.Looper
5
- import android.util.Log
6
- import com.facebook.react.bridge.ReactApplicationContext
7
- import com.facebook.react.bridge.ReactContextBaseJavaModule
8
- import com.facebook.react.bridge.ReactMethod
9
- import com.facebook.react.module.annotations.ReactModule
10
- import com.facebook.react.uimanager.UIManagerHelper
11
-
12
- @ReactModule(name = TransparentActivityModule.TAG)
13
- class TransparentActivityModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext) {
14
- companion object {
15
- const val TAG = "TransparentActivity"
16
- }
17
-
18
- override fun getName(): String {
19
- return TAG
20
- }
21
-
22
- @ReactMethod
23
- fun dismiss(viewTag: Int) {
24
- Handler(Looper.getMainLooper()).post {
25
- TransparentActivity.presentedInstance?.get()?.finish()
26
- }
27
- }
28
- }