react-native-sheet2 1.1.19

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 (74) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +79 -0
  3. package/android/build.gradle +83 -0
  4. package/android/gradle.properties +6 -0
  5. package/android/src/main/AndroidManifest.xml +12 -0
  6. package/android/src/main/java/com/behavior/BottomSheetBehavior.java +2329 -0
  7. package/android/src/main/java/com/behavior/InsetsAnimationCallback.java +83 -0
  8. package/android/src/main/java/com/modal/FullScreenDialog.kt +100 -0
  9. package/android/src/main/java/com/modal/TopModalView.kt +77 -0
  10. package/android/src/main/java/com/modal/TopModalViewManager.kt +83 -0
  11. package/android/src/main/java/com/modal/TopModalViewModule.kt +36 -0
  12. package/android/src/main/java/com/sheet/AppFittedSheet.kt +149 -0
  13. package/android/src/main/java/com/sheet/BaseRNView.kt +73 -0
  14. package/android/src/main/java/com/sheet/CustomBottomSheetDialog.java +238 -0
  15. package/android/src/main/java/com/sheet/DialogRootViewGroup.kt +159 -0
  16. package/android/src/main/java/com/sheet/FragmentModalBottomSheet.kt +54 -0
  17. package/android/src/main/java/com/sheet/ReactNativeReflection.java +24 -0
  18. package/android/src/main/java/com/sheet/SheetPackage.kt +20 -0
  19. package/android/src/main/java/com/sheet/SheetViewManager.kt +144 -0
  20. package/android/src/main/java/com/sheet/SheetViewModule.kt +43 -0
  21. package/android/src/main/java/com/sheet/utils.kt +71 -0
  22. package/android/src/main/java/com/transparent/activity/ActivityModalView.kt +71 -0
  23. package/android/src/main/java/com/transparent/activity/TransparentActivity.kt +48 -0
  24. package/android/src/main/java/com/transparent/activity/TransparentActivityManager.kt +63 -0
  25. package/android/src/main/java/com/transparent/activity/TransparentActivityModule.kt +28 -0
  26. package/android/src/main/res/anim/fade_in.xml +8 -0
  27. package/android/src/main/res/anim/fade_out.xml +11 -0
  28. package/android/src/main/res/anim/slide_down.xml +8 -0
  29. package/android/src/main/res/anim/slide_up.xml +8 -0
  30. package/android/src/main/res/layout/dialog_bottom_sheet.xml +64 -0
  31. package/android/src/main/res/layout/item_full.xml +14 -0
  32. package/android/src/main/res/values/colors.xml +15 -0
  33. package/android/src/main/res/values/styles.xml +75 -0
  34. package/ios/FittedSheets/Compatible.swift +55 -0
  35. package/ios/FittedSheets/InitialTouchPanGestureRecognizer.swift +19 -0
  36. package/ios/FittedSheets/SheetContentViewController.swift +326 -0
  37. package/ios/FittedSheets/SheetContentViewDelegate.swift +17 -0
  38. package/ios/FittedSheets/SheetOptions.swift +100 -0
  39. package/ios/FittedSheets/SheetSize.swift +20 -0
  40. package/ios/FittedSheets/SheetTransition.swift +153 -0
  41. package/ios/FittedSheets/SheetView.swift +21 -0
  42. package/ios/FittedSheets/SheetViewController.swift +761 -0
  43. package/ios/FittedSheets/SheetViewDelegate.swift +16 -0
  44. package/ios/FittedSheets/UIColorExtension.swift +59 -0
  45. package/ios/FittedSheets/UIViewControllerExtension.swift +27 -0
  46. package/ios/FittedSheets/Yalta.swift +420 -0
  47. package/ios/LBBottomSheet/BottomSheetConstant.swift +48 -0
  48. package/ios/LBBottomSheet/Model/BottomSheetController+Behavior.swift +262 -0
  49. package/ios/LBBottomSheet/Model/BottomSheetController+Theme.swift +156 -0
  50. package/ios/LBBottomSheet/Protocols/BottomSheetInteractionDelegate.swift +29 -0
  51. package/ios/LBBottomSheet/Protocols/BottomSheetPositionDelegate.swift +31 -0
  52. package/ios/LBBottomSheet/UI/BottomSheet.storyboard +105 -0
  53. package/ios/LBBottomSheet/UI/BottomSheetController.swift +601 -0
  54. package/ios/LBBottomSheet/Utils/Components/ForwardingEventsView.swift +60 -0
  55. package/ios/LBBottomSheet/Utils/Extensions/CACornerMask+Extension.swift +33 -0
  56. package/ios/LBBottomSheet/Utils/Extensions/Mirror+Extension.swift +47 -0
  57. package/ios/LBBottomSheet/Utils/Extensions/UIApplication+Extension.swift +35 -0
  58. package/ios/LBBottomSheet/Utils/Extensions/UIColor+Extension.swift +61 -0
  59. package/ios/LBBottomSheet/Utils/Extensions/UIGestureRecognizer+Extensions.swift +28 -0
  60. package/ios/LBBottomSheet/Utils/Extensions/UIScreen+Extension.swift +28 -0
  61. package/ios/LBBottomSheet/Utils/Extensions/UIScrollView+Extension.swift +25 -0
  62. package/ios/LBBottomSheet/Utils/Extensions/UIView+Extension.swift +52 -0
  63. package/ios/LBBottomSheet/Utils/Extensions/UIViewController+Extension.swift +104 -0
  64. package/ios/Sheet-Bridging-Header.h +1 -0
  65. package/ios/Sheet.xcodeproj/project.pbxproj +377 -0
  66. package/ios/SheetViewManager.m +27 -0
  67. package/ios/SheetViewManager.swift +351 -0
  68. package/ios/TopModalViewManager.swift +196 -0
  69. package/package.json +103 -0
  70. package/react-native-sheet.podspec +21 -0
  71. package/src/FittedSheet.tsx +177 -0
  72. package/src/TopModal.tsx +94 -0
  73. package/src/TransparentActivity.tsx +98 -0
  74. package/src/index.tsx +16 -0
@@ -0,0 +1,83 @@
1
+ /*
2
+ * Copyright (C) 2023 The Android Open Source Project
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ package com.behavior;
18
+
19
+ import android.view.View;
20
+ import androidx.annotation.NonNull;
21
+ import androidx.core.view.WindowInsetsAnimationCompat;
22
+ import androidx.core.view.WindowInsetsAnimationCompat.BoundsCompat;
23
+ import androidx.core.view.WindowInsetsCompat;
24
+ import com.google.android.material.animation.AnimationUtils;
25
+ import java.util.List;
26
+
27
+ class InsetsAnimationCallback extends WindowInsetsAnimationCompat.Callback {
28
+
29
+ private final View view;
30
+
31
+ private int startY;
32
+ private int startTranslationY;
33
+
34
+ private final int[] tmpLocation = new int[2];
35
+
36
+ public InsetsAnimationCallback(View view) {
37
+ super(DISPATCH_MODE_STOP);
38
+ this.view = view;
39
+ }
40
+
41
+ @Override
42
+ public void onPrepare(@NonNull WindowInsetsAnimationCompat windowInsetsAnimationCompat) {
43
+ view.getLocationOnScreen(tmpLocation);
44
+ startY = tmpLocation[1];
45
+ }
46
+
47
+ @NonNull
48
+ @Override
49
+ public BoundsCompat onStart(
50
+ @NonNull WindowInsetsAnimationCompat windowInsetsAnimationCompat,
51
+ @NonNull BoundsCompat boundsCompat) {
52
+ view.getLocationOnScreen(tmpLocation);
53
+ int endY = tmpLocation[1];
54
+ startTranslationY = startY - endY;
55
+
56
+ // Move the view back to its original position before the insets were applied.
57
+ view.setTranslationY(startTranslationY);
58
+
59
+ return boundsCompat;
60
+ }
61
+
62
+ @NonNull
63
+ @Override
64
+ public WindowInsetsCompat onProgress(
65
+ @NonNull WindowInsetsCompat insets,
66
+ @NonNull List<WindowInsetsAnimationCompat> animationList) {
67
+ for (WindowInsetsAnimationCompat animation : animationList) {
68
+ if ((animation.getTypeMask() & WindowInsetsCompat.Type.ime()) != 0) {
69
+ // Move the view to match the animated position of the keyboard.
70
+ float translationY =
71
+ AnimationUtils.lerp(startTranslationY, 0, animation.getInterpolatedFraction());
72
+ view.setTranslationY(translationY);
73
+ break;
74
+ }
75
+ }
76
+ return insets;
77
+ }
78
+
79
+ @Override
80
+ public void onEnd(@NonNull WindowInsetsAnimationCompat windowInsetsAnimationCompat) {
81
+ view.setTranslationY(0f);
82
+ }
83
+ }
@@ -0,0 +1,100 @@
1
+ package com.modal
2
+
3
+ import android.content.DialogInterface
4
+ import android.graphics.Color
5
+ import android.graphics.PixelFormat
6
+ import android.graphics.drawable.ColorDrawable
7
+ import android.os.Bundle
8
+ import android.view.LayoutInflater
9
+ import android.view.View
10
+ import android.view.ViewGroup
11
+ import android.view.WindowManager
12
+ import android.widget.FrameLayout
13
+ import androidx.coordinatorlayout.widget.CoordinatorLayout
14
+ import androidx.fragment.app.DialogFragment
15
+ import androidx.fragment.app.FragmentManager
16
+ import com.sheet.R
17
+ import com.sheet.updateStatusBar
18
+
19
+
20
+ fun androidx.fragment.app.Fragment.safeShow(
21
+ manager: FragmentManager,
22
+ tag: String?
23
+ ) {
24
+ val ft = manager.beginTransaction()
25
+ ft.add(this, tag)
26
+ ft.commitAllowingStateLoss()
27
+ }
28
+
29
+ class FullScreenDialog(
30
+ private val presentView: View,
31
+ private val animated: Boolean,
32
+ // "slide" || "fade"
33
+ private val animationType: String,
34
+ private val isEdgeToEdge: Boolean,
35
+ private val isStatusBarBgLight: Boolean,
36
+ private val onDismiss: () -> Unit
37
+ ) : DialogFragment() {
38
+ override fun onCreate(savedInstanceState: Bundle?) {
39
+ super.onCreate(savedInstanceState)
40
+ if (isEdgeToEdge) {
41
+ setStyle(STYLE_NORMAL, R.style.Custom_Theme_EdgeToEdgeDialog)
42
+ } else {
43
+ setStyle(STYLE_NORMAL, R.style.Custom_Theme_FullScreenDialog)
44
+ }
45
+ }
46
+
47
+ override fun onStart() {
48
+ super.onStart()
49
+ isCancelable = false
50
+
51
+ dialog?.window?.let {
52
+ if (animated) {
53
+ if (animationType == "slide") {
54
+ it.setWindowAnimations(R.style.Custom_Theme_FullScreenDialog_Slide)
55
+ }
56
+ // Fade is applied by Default
57
+ } else {
58
+ it.setWindowAnimations(R.style.Custom_Theme_FullScreenDialog_NoAnimation)
59
+ }
60
+
61
+ if (isEdgeToEdge) {
62
+ it.navigationBarColor = Color.TRANSPARENT
63
+ it.statusBarColor = Color.TRANSPARENT
64
+ it.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE or
65
+ View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
66
+
67
+ it.updateStatusBar(isStatusBarBgLight)
68
+ } else {
69
+ val width = ViewGroup.LayoutParams.MATCH_PARENT
70
+ val height = ViewGroup.LayoutParams.MATCH_PARENT
71
+ it.setLayout(width, height)
72
+ it.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND)
73
+ }
74
+
75
+ it.setFormat(PixelFormat.TRANSLUCENT)
76
+ it.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
77
+ }
78
+ }
79
+
80
+ override fun onCreateView(
81
+ inflater: LayoutInflater,
82
+ container: ViewGroup?,
83
+ savedInstanceState: Bundle?
84
+ ): View {
85
+ super.onCreateView(inflater, container, savedInstanceState)
86
+ val parent = inflater.inflate(R.layout.item_full, container, false) as CoordinatorLayout
87
+ return parent
88
+ }
89
+
90
+ override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
91
+ super.onViewCreated(view, savedInstanceState)
92
+ view.findViewById<FrameLayout>(R.id.container).addView(presentView)
93
+ }
94
+
95
+ override fun onDismiss(dialog: DialogInterface) {
96
+ super.onDismiss(dialog)
97
+ println("⚽️ FullScreenDialog.onDismiss")
98
+ onDismiss()
99
+ }
100
+ }
@@ -0,0 +1,77 @@
1
+ package com.modal
2
+
3
+ import android.content.Context
4
+ import android.view.View
5
+ import android.view.accessibility.AccessibilityEvent
6
+ import androidx.appcompat.app.AppCompatActivity
7
+ import com.sheet.BaseRNView
8
+ import com.facebook.react.bridge.Arguments
9
+ import com.facebook.react.bridge.LifecycleEventListener
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
+
15
+ fun TopModalView.onModalDismiss() {
16
+ (context as ReactContext).getJSModule(RCTEventEmitter::class.java)
17
+ .receiveEvent(id, "onModalDismiss", Arguments.createMap())
18
+ }
19
+
20
+ class TopModalView(context: Context?) : ReactViewGroup(context) {
21
+ private var dialog: FullScreenDialog? = null
22
+ private var rnView = BaseRNView(context)
23
+
24
+ var isEdgeToEdge = false
25
+ var isStatusBarBgLight = false
26
+ var animated = true
27
+ // "slide" || "fade"
28
+ var animationType = "slide"
29
+
30
+ init {
31
+ println("⚽️ init")
32
+ }
33
+
34
+ private fun getCurrentActivity(): AppCompatActivity? {
35
+ return (context as? ReactContext)?.currentActivity as? AppCompatActivity
36
+ }
37
+
38
+ override fun addView(child: View, index: Int) {
39
+ val activity = getCurrentActivity() ?: return
40
+ rnView.addView(child)
41
+ dialog = FullScreenDialog(
42
+ presentView = rnView,
43
+ animated = animated,
44
+ animationType = animationType,
45
+ isEdgeToEdge = isEdgeToEdge,
46
+ isStatusBarBgLight = isStatusBarBgLight,
47
+ ::onModalDismiss,
48
+ )
49
+ dialog?.safeShow(activity.supportFragmentManager, "TopModalView")
50
+ dialog?.isCancelable = true
51
+
52
+ }
53
+
54
+ override fun addChildrenForAccessibility(outChildren: ArrayList<View?>?) {}
55
+ override fun dispatchPopulateAccessibilityEvent(event: AccessibilityEvent?) = false
56
+
57
+
58
+ override fun removeView(child: View?) {
59
+ println("⚽️ removeView")
60
+ UiThreadUtil.assertOnUiThread()
61
+ dismiss()
62
+ }
63
+
64
+ override fun removeViewAt(index: Int) {
65
+ println("⚽️ removeViewAt: $index")
66
+ UiThreadUtil.assertOnUiThread()
67
+ dismiss()
68
+ }
69
+
70
+ fun dismiss() {
71
+ dialog?.let {
72
+ println("⚽️ dismiss")
73
+ dialog?.dismissAllowingStateLoss()
74
+ dialog = null
75
+ }
76
+ }
77
+ }
@@ -0,0 +1,83 @@
1
+ package com.modal
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.react.uimanager.annotations.ReactProp
12
+ import com.facebook.yoga.YogaPositionType
13
+
14
+ private class ModalHostShadowNode : LayoutShadowNode() {
15
+ override fun addChildAt(child: ReactShadowNodeImpl, i: Int) {
16
+ super.addChildAt(child, i)
17
+ val display = Resources.getSystem().displayMetrics
18
+ child.setStyleWidth(display.widthPixels.toFloat())
19
+ child.setStyleHeight(display.heightPixels.toFloat())
20
+ child.setPositionType(YogaPositionType.ABSOLUTE)
21
+ }
22
+ }
23
+
24
+ class TopModalViewManager : ViewGroupManager<TopModalView>() {
25
+ override fun getName() = "TopModalView"
26
+
27
+ override fun createViewInstance(reactContext: ThemedReactContext): TopModalView {
28
+ return TopModalView(reactContext)
29
+ }
30
+
31
+ override fun getExportedCustomDirectEventTypeConstants(): Map<String, Any>? {
32
+ return MapBuilder.builder<String, Any>()
33
+ .put("onModalDismiss", MapBuilder.of("registrationName", "onModalDismiss"))
34
+ .build()
35
+ }
36
+
37
+ @ReactProp(name = "isEdgeToEdge")
38
+ fun setIsEdgeToEdge(view: TopModalView, isEdgeToEdge: Boolean) {
39
+ view.isEdgeToEdge = isEdgeToEdge
40
+ }
41
+ @ReactProp(name = "isStatusBarBgLight")
42
+ fun setIsStatusBarBgLight(view: TopModalView, isStatusBarBgLight: Boolean) {
43
+ view.isStatusBarBgLight = isStatusBarBgLight
44
+ }
45
+
46
+ @ReactProp(name="animated")
47
+ fun setAnimated(view: TopModalView, animated: Boolean) {
48
+ view.animated = animated
49
+ }
50
+ // "slide" | "fade"
51
+ @ReactProp(name = "animationType")
52
+ fun setAnimationType(view: TopModalView, animationType: String) {
53
+ view.animationType = animationType
54
+ }
55
+
56
+ override fun getShadowNodeClass(): Class<LayoutShadowNode> {
57
+ return ModalHostShadowNode::class.java as Class<LayoutShadowNode>
58
+ }
59
+
60
+ override fun createShadowNodeInstance(): LayoutShadowNode {
61
+ return ModalHostShadowNode()
62
+ }
63
+
64
+ override fun createShadowNodeInstance(context: ReactApplicationContext): LayoutShadowNode {
65
+ println("⚽️ createShadowNodeInstance")
66
+ return ModalHostShadowNode()
67
+ }
68
+
69
+ override fun removeView(parent: TopModalView?, view: View?) {
70
+ super.removeView(parent, view)
71
+ println("⚽️ removeView")
72
+ }
73
+
74
+ override fun removeViewAt(parent: TopModalView?, index: Int) {
75
+ super.removeViewAt(parent, index)
76
+ println("⚽️ removeViewAt")
77
+ }
78
+
79
+ override fun onDropViewInstance(view: TopModalView) {
80
+ super.onDropViewInstance(view)
81
+ view.dismiss()
82
+ }
83
+ }
@@ -0,0 +1,36 @@
1
+ package com.modal
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 = TopModalViewModule.TAG)
13
+ class TopModalViewModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext) {
14
+ companion object {
15
+ const val TAG = "TopModalView"
16
+ }
17
+
18
+ override fun getName(): String {
19
+ return TAG
20
+ }
21
+
22
+ private fun findSheetView(viewId: Int): TopModalView {
23
+ Log.d(TAG, "Finding view $viewId...")
24
+ val view = if (reactApplicationContext != null) UIManagerHelper.getUIManager(reactApplicationContext, viewId)?.resolveView(viewId) as TopModalView? else null
25
+ Log.d(TAG, if (reactApplicationContext != null) "Found view $viewId!" else "Couldn't find view $viewId!")
26
+ return view ?: throw RuntimeException("ViewNotFound($viewId)")
27
+ }
28
+
29
+ @ReactMethod
30
+ fun dismiss(viewTag: Int) {
31
+ Handler(Looper.getMainLooper()).post {
32
+ val view = findSheetView(viewTag)
33
+ view.dismiss()
34
+ }
35
+ }
36
+ }
@@ -0,0 +1,149 @@
1
+ package com.sheet
2
+
3
+ import android.content.Context
4
+ import android.graphics.Color
5
+ import android.os.Build
6
+ import android.view.View
7
+ import android.view.ViewGroup
8
+ import android.view.ViewStructure
9
+ import android.view.accessibility.AccessibilityEvent
10
+ import androidx.annotation.RequiresApi
11
+ import androidx.appcompat.app.AppCompatActivity
12
+ import com.facebook.react.bridge.Arguments
13
+ import com.facebook.react.bridge.LifecycleEventListener
14
+ import com.facebook.react.bridge.ReactContext
15
+ import com.facebook.react.bridge.ReadableMap
16
+ import com.facebook.react.bridge.UiThreadUtil
17
+ import com.facebook.react.uimanager.UIManagerHelper
18
+ import com.facebook.react.uimanager.UIManagerModule
19
+ import com.facebook.react.uimanager.common.UIManagerType
20
+ import com.facebook.react.uimanager.events.RCTEventEmitter
21
+ import com.modal.safeShow
22
+
23
+
24
+ internal fun AppFittedSheet.onSheetDismiss() {
25
+ (context as ReactContext).getJSModule(RCTEventEmitter::class.java)
26
+ .receiveEvent(id, "onSheetDismiss", Arguments.createMap())
27
+ }
28
+
29
+ class AppFittedSheet(context: Context) : ViewGroup(context), LifecycleEventListener {
30
+ private val fragmentTag = "CCBottomSheet-${System.currentTimeMillis()}"
31
+ var mHostView = DialogRootViewGroup(context)
32
+
33
+ var params: ReadableMap? = null
34
+ set(value) {
35
+ mHostView.sheetMaxHeightSize = value.double("maxHeight", -1.0).toPxD()
36
+ mHostView.sheetMaxWidthSize = value.double("maxWidth", -1.0).toPxD()
37
+ mHostView.sheetMinHeightSize = value.double("minHeight", -1.0).toPxD()
38
+
39
+ field = value
40
+ }
41
+
42
+ private val dismissible: Boolean
43
+ get() = params.bool("dismissible", true)
44
+ private val topLeftRightCornerRadius: Float
45
+ get() = params.float("topLeftRightCornerRadius", 0f)
46
+ private val backgroundColor: Int
47
+ get() = params?.color("backgroundColor", context) ?: Color.TRANSPARENT
48
+ private val isDark: Boolean
49
+ get() = params.bool("isDark", false)
50
+ private val isStatusBarBgLight: Boolean
51
+ get() = params?.bool("isStatusBarBgLight", false) ?: false
52
+
53
+ private fun getCurrentActivity(): AppCompatActivity? {
54
+ return (context as ReactContext)?.currentActivity as? AppCompatActivity
55
+ }
56
+
57
+ private val sheet: FragmentModalBottomSheet?
58
+ get() = getCurrentActivity()?.supportFragmentManager?.findFragmentByTag(fragmentTag) as FragmentModalBottomSheet?
59
+
60
+ fun showOrUpdate() {
61
+ println("🥲 showOrUpdate")
62
+ UiThreadUtil.assertOnUiThread()
63
+
64
+ val sheet = this.sheet
65
+ mHostView.setCornerRadius(topLeftRightCornerRadius)
66
+ mHostView.setBackgroundColor(backgroundColor)
67
+ if (sheet == null) {
68
+ val fragment = FragmentModalBottomSheet(
69
+ modalView = mHostView,
70
+ dismissible = dismissible,
71
+ isDark = isDark,
72
+ isStatusBarBgLight = isStatusBarBgLight
73
+ ) {
74
+ println("😀 onDismiss")
75
+ val parent = mHostView.parent as? ViewGroup
76
+ parent?.removeViewAt(0)
77
+ onSheetDismiss()
78
+ }
79
+ getCurrentActivity()?.supportFragmentManager?.let {
80
+ fragment.safeShow(it, fragmentTag)
81
+ }
82
+ }
83
+ }
84
+
85
+ fun setNewNestedScrollView(view: View) {
86
+ sheet?.setNewNestedScrollView(view)
87
+ }
88
+
89
+ @RequiresApi(Build.VERSION_CODES.M)
90
+ override fun dispatchProvideStructure(structure: ViewStructure?) {
91
+ mHostView.dispatchProvideStructure(structure)
92
+ }
93
+
94
+ override fun addView(child: View, index: Int) {
95
+ println("🥲 addView parentId: $id id: ${child.id}")
96
+ UiThreadUtil.assertOnUiThread()
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
102
+ val height = resolveShadowNode.layoutHeight
103
+ if (height > 0) mHostView.setVirtualHeight(height)
104
+ }
105
+ }
106
+
107
+ override fun getChildCount(): Int = mHostView.childCount
108
+
109
+ override fun getChildAt(index: Int): View? = mHostView.getChildAt(index)
110
+
111
+ override fun removeView(child: View) {
112
+ println("🥲 removeView id: ${child.id}")
113
+ UiThreadUtil.assertOnUiThread()
114
+ dismiss()
115
+ }
116
+
117
+ override fun onDetachedFromWindow() {
118
+ super.onDetachedFromWindow()
119
+ println("🥲 onDetachedFromWindow: $id")
120
+ ModalHostShadowNode.attachedViews.remove(id)
121
+ }
122
+
123
+ override fun removeViewAt(index: Int) {
124
+ println("🥲 removeViewAt: $index id: ${mHostView.getChildAt(index).id}")
125
+ UiThreadUtil.assertOnUiThread()
126
+ dismiss()
127
+ }
128
+
129
+ private fun onDropInstance() {
130
+ println("🥲 onDropInstance")
131
+ (context as ReactContext).removeLifecycleEventListener(this)
132
+ dismiss()
133
+ }
134
+
135
+ fun dismiss() {
136
+ println("🥲 dismiss")
137
+ UiThreadUtil.assertOnUiThread()
138
+ this.sheet?.dismissAllowingStateLoss()
139
+ }
140
+ override fun addChildrenForAccessibility(outChildren: ArrayList<View?>?) {}
141
+
142
+ override fun dispatchPopulateAccessibilityEvent(event: AccessibilityEvent?) = false
143
+ override fun onHostResume() { showOrUpdate() }
144
+ override fun onHostPause() {}
145
+
146
+ override fun onHostDestroy() { onDropInstance() }
147
+
148
+ override fun onLayout(changed: Boolean, l: Int, t: Int, r: Int, b: Int) {}
149
+ }
@@ -0,0 +1,73 @@
1
+ package com.sheet
2
+
3
+ import android.content.Context
4
+ import android.view.MotionEvent
5
+ import android.view.View
6
+ import com.facebook.react.bridge.ReactContext
7
+ import com.facebook.react.config.ReactFeatureFlags
8
+ import com.facebook.react.uimanager.JSPointerDispatcher
9
+ import com.facebook.react.uimanager.JSTouchDispatcher
10
+ import com.facebook.react.uimanager.RootView
11
+ import com.facebook.react.uimanager.UIManagerModule
12
+ import com.facebook.react.uimanager.events.EventDispatcher
13
+ import com.facebook.react.views.view.ReactViewGroup
14
+
15
+ open class BaseRNView(context: Context?) : ReactViewGroup(context), RootView {
16
+ private val reactContext: ReactContext
17
+ get() = context as ReactContext
18
+ private val mJSTouchDispatcher = JSTouchDispatcher(this)
19
+ private var mJSPointerDispatcher: JSPointerDispatcher? = null
20
+
21
+ init {
22
+ if (ReactFeatureFlags.dispatchPointerEvents) {
23
+ mJSPointerDispatcher = JSPointerDispatcher(this)
24
+ }
25
+ }
26
+
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)
36
+ }
37
+
38
+ override fun onChildStartedNativeGesture(p0: MotionEvent?) {
39
+ this.onChildStartedNativeGesture(null, p0)
40
+ }
41
+
42
+ override fun onChildEndedNativeGesture(p0: View?, p1: MotionEvent?) {
43
+ mJSTouchDispatcher.onChildEndedNativeGesture(p1, eventDispatcher)
44
+ mJSPointerDispatcher?.onChildEndedNativeGesture()
45
+ }
46
+
47
+ override fun handleException(t: Throwable?) {
48
+ reactContext.handleException(RuntimeException(t))
49
+ }
50
+
51
+ override fun onInterceptTouchEvent(event: MotionEvent): Boolean {
52
+ mJSTouchDispatcher.handleTouchEvent(event, eventDispatcher)
53
+ mJSPointerDispatcher?.handleMotionEvent(event, eventDispatcher, true)
54
+ return super.onInterceptTouchEvent(event)
55
+ }
56
+
57
+ 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
63
+ }
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
+ return true
68
+ }
69
+
70
+ // No-op - override in order to still receive events to onInterceptTouchEvent
71
+ // even when some other view disallow that
72
+ override fun requestDisallowInterceptTouchEvent(disallowIntercept: Boolean) = Unit
73
+ }