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.
- package/LICENSE +20 -0
- package/README.md +79 -0
- package/android/build.gradle +83 -0
- package/android/gradle.properties +6 -0
- package/android/src/main/AndroidManifest.xml +12 -0
- package/android/src/main/java/com/behavior/BottomSheetBehavior.java +2329 -0
- package/android/src/main/java/com/behavior/InsetsAnimationCallback.java +83 -0
- package/android/src/main/java/com/modal/FullScreenDialog.kt +100 -0
- package/android/src/main/java/com/modal/TopModalView.kt +77 -0
- package/android/src/main/java/com/modal/TopModalViewManager.kt +83 -0
- package/android/src/main/java/com/modal/TopModalViewModule.kt +36 -0
- package/android/src/main/java/com/sheet/AppFittedSheet.kt +149 -0
- package/android/src/main/java/com/sheet/BaseRNView.kt +73 -0
- package/android/src/main/java/com/sheet/CustomBottomSheetDialog.java +238 -0
- package/android/src/main/java/com/sheet/DialogRootViewGroup.kt +159 -0
- package/android/src/main/java/com/sheet/FragmentModalBottomSheet.kt +54 -0
- package/android/src/main/java/com/sheet/ReactNativeReflection.java +24 -0
- package/android/src/main/java/com/sheet/SheetPackage.kt +20 -0
- package/android/src/main/java/com/sheet/SheetViewManager.kt +144 -0
- package/android/src/main/java/com/sheet/SheetViewModule.kt +43 -0
- package/android/src/main/java/com/sheet/utils.kt +71 -0
- package/android/src/main/java/com/transparent/activity/ActivityModalView.kt +71 -0
- package/android/src/main/java/com/transparent/activity/TransparentActivity.kt +48 -0
- package/android/src/main/java/com/transparent/activity/TransparentActivityManager.kt +63 -0
- package/android/src/main/java/com/transparent/activity/TransparentActivityModule.kt +28 -0
- package/android/src/main/res/anim/fade_in.xml +8 -0
- package/android/src/main/res/anim/fade_out.xml +11 -0
- package/android/src/main/res/anim/slide_down.xml +8 -0
- package/android/src/main/res/anim/slide_up.xml +8 -0
- package/android/src/main/res/layout/dialog_bottom_sheet.xml +64 -0
- package/android/src/main/res/layout/item_full.xml +14 -0
- package/android/src/main/res/values/colors.xml +15 -0
- package/android/src/main/res/values/styles.xml +75 -0
- package/ios/FittedSheets/Compatible.swift +55 -0
- package/ios/FittedSheets/InitialTouchPanGestureRecognizer.swift +19 -0
- package/ios/FittedSheets/SheetContentViewController.swift +326 -0
- package/ios/FittedSheets/SheetContentViewDelegate.swift +17 -0
- package/ios/FittedSheets/SheetOptions.swift +100 -0
- package/ios/FittedSheets/SheetSize.swift +20 -0
- package/ios/FittedSheets/SheetTransition.swift +153 -0
- package/ios/FittedSheets/SheetView.swift +21 -0
- package/ios/FittedSheets/SheetViewController.swift +761 -0
- package/ios/FittedSheets/SheetViewDelegate.swift +16 -0
- package/ios/FittedSheets/UIColorExtension.swift +59 -0
- package/ios/FittedSheets/UIViewControllerExtension.swift +27 -0
- package/ios/FittedSheets/Yalta.swift +420 -0
- package/ios/LBBottomSheet/BottomSheetConstant.swift +48 -0
- package/ios/LBBottomSheet/Model/BottomSheetController+Behavior.swift +262 -0
- package/ios/LBBottomSheet/Model/BottomSheetController+Theme.swift +156 -0
- package/ios/LBBottomSheet/Protocols/BottomSheetInteractionDelegate.swift +29 -0
- package/ios/LBBottomSheet/Protocols/BottomSheetPositionDelegate.swift +31 -0
- package/ios/LBBottomSheet/UI/BottomSheet.storyboard +105 -0
- package/ios/LBBottomSheet/UI/BottomSheetController.swift +601 -0
- package/ios/LBBottomSheet/Utils/Components/ForwardingEventsView.swift +60 -0
- package/ios/LBBottomSheet/Utils/Extensions/CACornerMask+Extension.swift +33 -0
- package/ios/LBBottomSheet/Utils/Extensions/Mirror+Extension.swift +47 -0
- package/ios/LBBottomSheet/Utils/Extensions/UIApplication+Extension.swift +35 -0
- package/ios/LBBottomSheet/Utils/Extensions/UIColor+Extension.swift +61 -0
- package/ios/LBBottomSheet/Utils/Extensions/UIGestureRecognizer+Extensions.swift +28 -0
- package/ios/LBBottomSheet/Utils/Extensions/UIScreen+Extension.swift +28 -0
- package/ios/LBBottomSheet/Utils/Extensions/UIScrollView+Extension.swift +25 -0
- package/ios/LBBottomSheet/Utils/Extensions/UIView+Extension.swift +52 -0
- package/ios/LBBottomSheet/Utils/Extensions/UIViewController+Extension.swift +104 -0
- package/ios/Sheet-Bridging-Header.h +1 -0
- package/ios/Sheet.xcodeproj/project.pbxproj +377 -0
- package/ios/SheetViewManager.m +27 -0
- package/ios/SheetViewManager.swift +351 -0
- package/ios/TopModalViewManager.swift +196 -0
- package/package.json +103 -0
- package/react-native-sheet.podspec +21 -0
- package/src/FittedSheet.tsx +177 -0
- package/src/TopModal.tsx +94 -0
- package/src/TransparentActivity.tsx +98 -0
- package/src/index.tsx +16 -0
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
package com.sheet;
|
|
2
|
+
|
|
3
|
+
import android.annotation.SuppressLint;
|
|
4
|
+
import android.util.TypedValue;
|
|
5
|
+
import android.view.View;
|
|
6
|
+
import android.view.ViewGroup;
|
|
7
|
+
import android.widget.FrameLayout;
|
|
8
|
+
|
|
9
|
+
import androidx.annotation.IdRes;
|
|
10
|
+
import androidx.annotation.LayoutRes;
|
|
11
|
+
import androidx.annotation.NonNull;
|
|
12
|
+
import androidx.annotation.Nullable;
|
|
13
|
+
import androidx.annotation.StyleRes;
|
|
14
|
+
import androidx.appcompat.app.AppCompatDialog;
|
|
15
|
+
|
|
16
|
+
import com.behavior.BottomSheetBehavior;
|
|
17
|
+
|
|
18
|
+
public class CustomBottomSheetDialog extends AppCompatDialog {
|
|
19
|
+
private BottomSheetBehavior<FrameLayout> behavior;
|
|
20
|
+
private FrameLayout container;
|
|
21
|
+
boolean dismissWithAnimation;
|
|
22
|
+
boolean cancelable = true;
|
|
23
|
+
|
|
24
|
+
protected int startState = BottomSheetBehavior.STATE_EXPANDED;
|
|
25
|
+
|
|
26
|
+
public void setNewNestedScrollView(View view) {
|
|
27
|
+
behavior.setNewNestedScrollView(view);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
public void setSheetBackgroundColor(int sheetBackgroundColor) {
|
|
31
|
+
ViewGroup contentContainer = getContentContainer();
|
|
32
|
+
if (contentContainer == null) return;
|
|
33
|
+
contentContainer.setBackgroundColor(sheetBackgroundColor);
|
|
34
|
+
}
|
|
35
|
+
public ViewGroup getContainerView() {
|
|
36
|
+
ensureContainerAndBehavior();
|
|
37
|
+
return container;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
@LayoutRes
|
|
41
|
+
public int getDialogLayout() {
|
|
42
|
+
return R.layout.dialog_bottom_sheet;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
@IdRes
|
|
46
|
+
public int getContentContainerId() {
|
|
47
|
+
return R.id.dialog_bottom_sheet_content_container;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
@Nullable
|
|
51
|
+
public ViewGroup getContentContainer() {
|
|
52
|
+
return getContainerView().findViewById(getContentContainerId());
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
public CustomBottomSheetDialog(@NonNull android.content.Context context, @StyleRes int theme) {
|
|
56
|
+
super(context, getThemeResId(context, theme));
|
|
57
|
+
// We hide the title bar for any style configuration. Otherwise, there will be a gap
|
|
58
|
+
// above the bottom sheet when it is expanded.
|
|
59
|
+
supportRequestWindowFeature(android.view.Window.FEATURE_NO_TITLE);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
@Override
|
|
63
|
+
public void setContentView(@LayoutRes int layoutResId) {
|
|
64
|
+
super.setContentView(wrapInBottomSheet(layoutResId, null, null));
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
@Override
|
|
68
|
+
protected void onCreate(android.os.Bundle savedInstanceState) {
|
|
69
|
+
super.onCreate(savedInstanceState);
|
|
70
|
+
android.view.Window window = getWindow();
|
|
71
|
+
if (window != null) {
|
|
72
|
+
window.clearFlags(android.view.WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
|
|
73
|
+
window.addFlags(android.view.WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
|
|
74
|
+
window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
@Override
|
|
79
|
+
public void setContentView(View view) {
|
|
80
|
+
super.setContentView(wrapInBottomSheet(0, view, null));
|
|
81
|
+
setup();
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
@Override
|
|
85
|
+
public void setContentView(View view, ViewGroup.LayoutParams params) {
|
|
86
|
+
super.setContentView(wrapInBottomSheet(0, view, params));
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
@Override
|
|
90
|
+
public void setCancelable(boolean cancelable) {
|
|
91
|
+
super.setCancelable(cancelable);
|
|
92
|
+
if (this.cancelable != cancelable) {
|
|
93
|
+
this.cancelable = cancelable;
|
|
94
|
+
if (behavior != null) {
|
|
95
|
+
behavior.setHideable(cancelable);
|
|
96
|
+
behavior.setDraggable(cancelable);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
private void setup() {
|
|
102
|
+
behavior.setPeekHeight(10, true);
|
|
103
|
+
behavior.setSkipCollapsed(true);
|
|
104
|
+
startState = BottomSheetBehavior.STATE_EXPANDED;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
@Override
|
|
108
|
+
protected void onStart() {
|
|
109
|
+
super.onStart();
|
|
110
|
+
if (behavior != null && behavior.getState() == BottomSheetBehavior.STATE_HIDDEN) {
|
|
111
|
+
behavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
|
|
112
|
+
}
|
|
113
|
+
if (behavior != null) behavior.setState(startState);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* This function can be called from a few different use cases, including Swiping the dialog down
|
|
118
|
+
* or calling `dismiss()` from a `BottomSheetDialogFragment`, tapping outside a dialog, etc...
|
|
119
|
+
*
|
|
120
|
+
* <p>If this function is called from a swipe down interaction, or dismissWithAnimation is false,
|
|
121
|
+
* then keep the default behavior.
|
|
122
|
+
*
|
|
123
|
+
* <p>Else, since this is a terminal event which will finish this dialog, we override the attached
|
|
124
|
+
* {@link BottomSheetBehavior.BottomSheetCallback} to call this function, after {@link
|
|
125
|
+
* BottomSheetBehavior#STATE_HIDDEN} is set. This will enforce the swipe down animation before
|
|
126
|
+
* canceling this dialog.
|
|
127
|
+
*/
|
|
128
|
+
@Override
|
|
129
|
+
public void cancel() {
|
|
130
|
+
BottomSheetBehavior<FrameLayout> behavior = getBehavior();
|
|
131
|
+
|
|
132
|
+
if (!dismissWithAnimation || behavior.getState() == BottomSheetBehavior.STATE_HIDDEN) {
|
|
133
|
+
super.cancel();
|
|
134
|
+
} else {
|
|
135
|
+
behavior.setState(BottomSheetBehavior.STATE_HIDDEN);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
@NonNull
|
|
140
|
+
public BottomSheetBehavior<FrameLayout> getBehavior() {
|
|
141
|
+
if (behavior == null) {
|
|
142
|
+
// The content hasn't been set, so the behavior doesn't exist yet. Let's create it.
|
|
143
|
+
ensureContainerAndBehavior();
|
|
144
|
+
}
|
|
145
|
+
return behavior;
|
|
146
|
+
}
|
|
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
|
+
/**
|
|
167
|
+
* Creates the container layout which must exist to find the behavior
|
|
168
|
+
*/
|
|
169
|
+
private FrameLayout ensureContainerAndBehavior() {
|
|
170
|
+
if (container == null) {
|
|
171
|
+
container =
|
|
172
|
+
(FrameLayout) View.inflate(getContext(), getDialogLayout(), null);
|
|
173
|
+
|
|
174
|
+
FrameLayout bottomSheet = (FrameLayout) container.findViewById(R.id.design_bottom_sheet);
|
|
175
|
+
behavior = BottomSheetBehavior.from(bottomSheet);
|
|
176
|
+
behavior.addBottomSheetCallback(bottomSheetCallback);
|
|
177
|
+
behavior.setHideable(cancelable);
|
|
178
|
+
}
|
|
179
|
+
return container;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
@SuppressLint("ClickableViewAccessibility")
|
|
183
|
+
private View wrapInBottomSheet(
|
|
184
|
+
int layoutResId, @Nullable View view, @Nullable ViewGroup.LayoutParams params) {
|
|
185
|
+
ensureContainerAndBehavior();
|
|
186
|
+
androidx.coordinatorlayout.widget.CoordinatorLayout coordinator = container.findViewById(R.id.coordinator);
|
|
187
|
+
if (layoutResId != 0 && view == null) {
|
|
188
|
+
view = getLayoutInflater().inflate(layoutResId, coordinator, false);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
FrameLayout bottomSheet = container.findViewById(R.id.design_bottom_sheet);
|
|
192
|
+
FrameLayout contentContainer = (FrameLayout) getContentContainer();
|
|
193
|
+
contentContainer.removeAllViews();
|
|
194
|
+
if (params == null) {
|
|
195
|
+
contentContainer.addView(view);
|
|
196
|
+
} else {
|
|
197
|
+
contentContainer.addView(view, params);
|
|
198
|
+
}
|
|
199
|
+
// We treat the CoordinatorLayout as outside the dialog though it is technically inside
|
|
200
|
+
coordinator
|
|
201
|
+
.findViewById(R.id.touch_outside)
|
|
202
|
+
.setOnClickListener(
|
|
203
|
+
view12 -> {if (cancelable && isShowing()) cancel();});
|
|
204
|
+
// Handle accessibility events
|
|
205
|
+
bottomSheet.setOnTouchListener((view1, event) -> true);
|
|
206
|
+
return container;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
private static int getThemeResId(@NonNull android.content.Context context, int themeId) {
|
|
210
|
+
if (themeId == 0) {
|
|
211
|
+
// If the provided theme is 0, then retrieve the dialogTheme from our theme
|
|
212
|
+
TypedValue outValue = new TypedValue();
|
|
213
|
+
if (context.getTheme().resolveAttribute(com.google.android.material.R.attr.bottomSheetDialogTheme, outValue, true)) {
|
|
214
|
+
themeId = outValue.resourceId;
|
|
215
|
+
} else {
|
|
216
|
+
// bottomSheetDialogTheme is not provided; we default to our light theme
|
|
217
|
+
themeId = com.google.android.material.R.style.Theme_Design_Light_BottomSheetDialog;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
return themeId;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
@NonNull
|
|
224
|
+
private BottomSheetBehavior.BottomSheetCallback bottomSheetCallback =
|
|
225
|
+
new BottomSheetBehavior.BottomSheetCallback() {
|
|
226
|
+
@Override
|
|
227
|
+
public void onStateChanged(
|
|
228
|
+
@NonNull View bottomSheet, @BottomSheetBehavior.State int newState) {
|
|
229
|
+
if (newState == BottomSheetBehavior.STATE_HIDDEN) {
|
|
230
|
+
cancel();
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
@Override
|
|
235
|
+
public void onSlide(@NonNull View bottomSheet, float slideOffset) {
|
|
236
|
+
}
|
|
237
|
+
};
|
|
238
|
+
}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
package com.sheet
|
|
2
|
+
|
|
3
|
+
import android.content.Context
|
|
4
|
+
import android.content.res.Resources
|
|
5
|
+
import android.graphics.Outline
|
|
6
|
+
import android.util.TypedValue
|
|
7
|
+
import android.view.MotionEvent
|
|
8
|
+
import android.view.View
|
|
9
|
+
import android.view.ViewGroup
|
|
10
|
+
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
|
|
18
|
+
import kotlin.math.max
|
|
19
|
+
import kotlin.math.min
|
|
20
|
+
|
|
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
|
|
29
|
+
var reactView: View? = null
|
|
30
|
+
|
|
31
|
+
var sheetMaxHeightSize: Double = -1.0
|
|
32
|
+
var sheetMaxWidthSize: Double = -1.0
|
|
33
|
+
var sheetMinHeightSize: Double = -1.0
|
|
34
|
+
|
|
35
|
+
private val metrics: Resources by lazy { Resources.getSystem() }
|
|
36
|
+
|
|
37
|
+
fun setCornerRadius(r: Float) {
|
|
38
|
+
setOutlineProvider(object : ViewOutlineProvider() {
|
|
39
|
+
override fun getOutline(view: View, outline: Outline) {
|
|
40
|
+
val left = 0
|
|
41
|
+
val top = 0
|
|
42
|
+
val right = view.width
|
|
43
|
+
val bottom = view.height
|
|
44
|
+
val cornerRadius =
|
|
45
|
+
TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, r, view.resources.displayMetrics)
|
|
46
|
+
.toInt()
|
|
47
|
+
outline.setRoundRect(left, top, right, bottom + cornerRadius, cornerRadius.toFloat())
|
|
48
|
+
}
|
|
49
|
+
})
|
|
50
|
+
setClipToOutline(true)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
private val screenHeight: Int
|
|
54
|
+
get() = metrics.displayMetrics.heightPixels
|
|
55
|
+
|
|
56
|
+
private val screenWidth: Int
|
|
57
|
+
get() = metrics.displayMetrics.widthPixels
|
|
58
|
+
val currentHeight: Int
|
|
59
|
+
get() = layoutParams?.height ?: 0
|
|
60
|
+
val currentWidth: Int
|
|
61
|
+
get() = layoutParams?.width ?: 0
|
|
62
|
+
|
|
63
|
+
init {
|
|
64
|
+
if (ReactFeatureFlags.dispatchPointerEvents) {
|
|
65
|
+
mJSPointerDispatcher = JSPointerDispatcher(this)
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
private fun allowedHeight(): Int {
|
|
70
|
+
var returnValue = if (sheetMaxHeightSize >= 0) {
|
|
71
|
+
min(sheetMaxHeightSize.toInt(), screenHeight)
|
|
72
|
+
} else {
|
|
73
|
+
screenHeight
|
|
74
|
+
}
|
|
75
|
+
returnValue = max(returnValue, sheetMinHeightSize.toInt())
|
|
76
|
+
return returnValue
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
private fun allowedWidth(): Int {
|
|
80
|
+
if (sheetMaxWidthSize >= 0) return min(sheetMaxWidthSize.toInt(), screenWidth)
|
|
81
|
+
return screenWidth
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
private fun ensureLayoutParams() {
|
|
85
|
+
if (layoutParams != null) return
|
|
86
|
+
layoutParams = LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
fun setVirtualHeight(h: Float) {
|
|
90
|
+
if (reactView == null) return
|
|
91
|
+
ensureLayoutParams()
|
|
92
|
+
this.sheetMaxHeightSize = h.toDouble()
|
|
93
|
+
val newHeight = allowedHeight()
|
|
94
|
+
val newWidth = allowedWidth()
|
|
95
|
+
println("😀 DialogRootViewGroup.setVirtualHeight ${newHeight.toDP()} :${newWidth.toDP()}")
|
|
96
|
+
translationX = ((screenWidth - newWidth) / 2).toFloat()
|
|
97
|
+
layoutParams?.height = newHeight
|
|
98
|
+
layoutParams?.width = newWidth
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
override fun addView(child: View, index: Int, params: LayoutParams) {
|
|
102
|
+
println("😀 DialogRootViewGroup.addView ${child.id}")
|
|
103
|
+
if (reactView != null) removeView(reactView)
|
|
104
|
+
super.addView(child, -1, params)
|
|
105
|
+
reactView = child
|
|
106
|
+
setVirtualHeight(sheetMaxHeightSize.toFloat())
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
override fun removeView(view: View?) {
|
|
110
|
+
if (view == reactView) releaseReactView()
|
|
111
|
+
super.removeView(view)
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
override fun removeViewAt(index: Int) {
|
|
115
|
+
if (getChildAt(index) === reactView) releaseReactView()
|
|
116
|
+
super.removeViewAt(index)
|
|
117
|
+
}
|
|
118
|
+
|
|
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
|
+
override fun onLayout(changed: Boolean, l: Int, t: Int, r: Int, b: Int) {}
|
|
154
|
+
|
|
155
|
+
private fun releaseReactView() {
|
|
156
|
+
sheetMaxHeightSize = -1.0
|
|
157
|
+
reactView = null
|
|
158
|
+
}
|
|
159
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
package com.sheet
|
|
2
|
+
|
|
3
|
+
import android.app.Dialog
|
|
4
|
+
import android.content.DialogInterface
|
|
5
|
+
import android.graphics.Color
|
|
6
|
+
import android.os.Bundle
|
|
7
|
+
import android.view.LayoutInflater
|
|
8
|
+
import android.view.View
|
|
9
|
+
import android.view.ViewGroup
|
|
10
|
+
import android.view.Window
|
|
11
|
+
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
|
|
12
|
+
import java.lang.ref.WeakReference
|
|
13
|
+
|
|
14
|
+
class FragmentModalBottomSheet(
|
|
15
|
+
private val modalView: ViewGroup,
|
|
16
|
+
private val dismissible: Boolean,
|
|
17
|
+
private val isDark: Boolean,
|
|
18
|
+
private val isStatusBarBgLight: Boolean,
|
|
19
|
+
private val onDismiss: () -> Unit
|
|
20
|
+
) : BottomSheetDialogFragment() {
|
|
21
|
+
|
|
22
|
+
companion object {
|
|
23
|
+
var presentedWindow: WeakReference<Window>? = null
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
override fun onCreateView(
|
|
27
|
+
inflater: LayoutInflater,
|
|
28
|
+
container: ViewGroup?,
|
|
29
|
+
savedInstanceState: Bundle?
|
|
30
|
+
): View = modalView
|
|
31
|
+
|
|
32
|
+
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
|
33
|
+
this.isCancelable = dismissible
|
|
34
|
+
val dialog = CustomBottomSheetDialog(requireContext(), if (isDark) R.style.AppBottomSheetDialog_Dark else R.style.AppBottomSheetDialog)
|
|
35
|
+
dialog.setSheetBackgroundColor(Color.TRANSPARENT)
|
|
36
|
+
dialog.window?.let {
|
|
37
|
+
presentedWindow = WeakReference(it)
|
|
38
|
+
|
|
39
|
+
it.updateStatusBar(isStatusBarBgLight)
|
|
40
|
+
}
|
|
41
|
+
return dialog
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
fun setNewNestedScrollView(view: View) {
|
|
45
|
+
(dialog as CustomBottomSheetDialog).setNewNestedScrollView(view)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
override fun onDismiss(dialog: DialogInterface) {
|
|
49
|
+
super.onDismiss(dialog)
|
|
50
|
+
presentedWindow?.clear()
|
|
51
|
+
presentedWindow = null
|
|
52
|
+
onDismiss()
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
package com.sheet
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.ReactPackage
|
|
4
|
+
import com.facebook.react.bridge.NativeModule
|
|
5
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
6
|
+
import com.facebook.react.uimanager.ViewManager
|
|
7
|
+
import com.modal.TopModalViewManager
|
|
8
|
+
import com.modal.TopModalViewModule
|
|
9
|
+
import com.transparent.activity.TransparentActivityManager
|
|
10
|
+
import com.transparent.activity.TransparentActivityModule
|
|
11
|
+
|
|
12
|
+
class SheetPackage : ReactPackage {
|
|
13
|
+
override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
|
|
14
|
+
return listOf(SheetViewModule(reactContext), TopModalViewModule(reactContext), TransparentActivityModule(reactContext))
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
|
|
18
|
+
return listOf(SheetViewManager(), TopModalViewManager(), TransparentActivityManager())
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
package com.sheet
|
|
2
|
+
|
|
3
|
+
import android.view.View
|
|
4
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
5
|
+
import com.facebook.react.bridge.ReactContext
|
|
6
|
+
import com.facebook.react.bridge.ReadableMap
|
|
7
|
+
import com.facebook.react.common.MapBuilder
|
|
8
|
+
import com.facebook.react.uimanager.LayoutShadowNode
|
|
9
|
+
import com.facebook.react.uimanager.NativeViewHierarchyOptimizer
|
|
10
|
+
import com.facebook.react.uimanager.PixelUtil
|
|
11
|
+
import com.facebook.react.uimanager.ReactShadowNodeImpl
|
|
12
|
+
import com.facebook.react.uimanager.ReactStylesDiffMap
|
|
13
|
+
import com.facebook.react.uimanager.StateWrapper
|
|
14
|
+
import com.facebook.react.uimanager.ThemedReactContext
|
|
15
|
+
import com.facebook.react.uimanager.UIManagerHelper
|
|
16
|
+
import com.facebook.react.uimanager.UIViewOperationQueue
|
|
17
|
+
import com.facebook.react.uimanager.ViewGroupManager
|
|
18
|
+
import com.facebook.react.uimanager.annotations.ReactProp
|
|
19
|
+
import com.facebook.react.uimanager.util.ReactFindViewUtil
|
|
20
|
+
import com.facebook.yoga.YogaPositionType
|
|
21
|
+
|
|
22
|
+
internal class ModalHostShadowNode : LayoutShadowNode() {
|
|
23
|
+
companion object {
|
|
24
|
+
val attachedViews = mutableMapOf<Int, AppFittedSheet>()
|
|
25
|
+
}
|
|
26
|
+
|
|
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
|
+
override fun dispatchUpdates(absoluteX: Float, absoluteY: Float, uiViewOperationQueue: UIViewOperationQueue?, nativeViewHierarchyOptimizer: NativeViewHierarchyOptimizer?) {
|
|
63
|
+
super.dispatchUpdates(absoluteX, absoluteY, uiViewOperationQueue, nativeViewHierarchyOptimizer)
|
|
64
|
+
val newHeight = getChildAt(0).layoutHeight
|
|
65
|
+
attachedViews[reactTag]?.mHostView?.let {
|
|
66
|
+
if (it.reactView == null) {
|
|
67
|
+
it.sheetMaxHeightSize = newHeight.toDouble()
|
|
68
|
+
} else {
|
|
69
|
+
it.setVirtualHeight(newHeight)
|
|
70
|
+
getChildAt(0).setStyleWidth(it.currentWidth.toFloat())
|
|
71
|
+
println("😀 dispatchUpdates ${it.currentWidth.toDP()} pa: ${it.currentHeight.toDP()}")
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
class SheetViewManager : ViewGroupManager<AppFittedSheet>() {
|
|
78
|
+
override fun getName() = "SheetView"
|
|
79
|
+
|
|
80
|
+
override fun createViewInstance(reactContext: ThemedReactContext): AppFittedSheet {
|
|
81
|
+
return AppFittedSheet(reactContext)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
override fun createViewInstance(reactTag: Int, reactContext: ThemedReactContext, initialProps: ReactStylesDiffMap?, stateWrapper: StateWrapper?): AppFittedSheet {
|
|
85
|
+
val view = super.createViewInstance(reactTag, reactContext, initialProps, stateWrapper)
|
|
86
|
+
println("🥲 createViewInstance id: $reactTag view: $view")
|
|
87
|
+
ModalHostShadowNode.attachedViews[view.id] = view
|
|
88
|
+
return view
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
@ReactProp(name = "fittedSheetParams")
|
|
92
|
+
fun fittedSheetParams(view: AppFittedSheet, params: ReadableMap) {
|
|
93
|
+
println("🥲 fittedSheetParams $params")
|
|
94
|
+
view.params = params
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
@ReactProp(name = "passScrollViewReactTag")
|
|
98
|
+
fun passScrollViewReactTag(view: AppFittedSheet, nativeId: String) {
|
|
99
|
+
val v = ReactFindViewUtil.findView(view, nativeId) ?: return
|
|
100
|
+
view.setNewNestedScrollView(v)
|
|
101
|
+
}
|
|
102
|
+
|
|
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
|
+
override fun getExportedCustomDirectEventTypeConstants(): Map<String, Any>? {
|
|
121
|
+
return MapBuilder.builder<String, Any>()
|
|
122
|
+
.put("onSheetDismiss", MapBuilder.of("registrationName", "onSheetDismiss"))
|
|
123
|
+
.build()
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
override fun getShadowNodeClass(): Class<LayoutShadowNode> {
|
|
127
|
+
return ModalHostShadowNode::class.java as Class<LayoutShadowNode>
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
override fun createShadowNodeInstance(): LayoutShadowNode {
|
|
131
|
+
println("🥲 createShadowNodeInstance")
|
|
132
|
+
return ModalHostShadowNode()
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
override fun createShadowNodeInstance(context: ReactApplicationContext): LayoutShadowNode {
|
|
136
|
+
println("🥲 createShadowNodeInstance")
|
|
137
|
+
return ModalHostShadowNode()
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
override fun onAfterUpdateTransaction(view: AppFittedSheet) {
|
|
141
|
+
super.onAfterUpdateTransaction(view)
|
|
142
|
+
view.showOrUpdate()
|
|
143
|
+
}
|
|
144
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
package com.sheet
|
|
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 = SheetViewModule.TAG)
|
|
13
|
+
class SheetViewModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext) {
|
|
14
|
+
companion object {
|
|
15
|
+
const val TAG = "SheetView"
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
override fun getName(): String {
|
|
19
|
+
return TAG
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
private fun findSheetView(viewId: Int): AppFittedSheet? {
|
|
23
|
+
try {
|
|
24
|
+
Log.d(TAG, "Finding view $viewId...")
|
|
25
|
+
val view = if (reactApplicationContext != null) UIManagerHelper.getUIManager(reactApplicationContext, viewId)?.resolveView(viewId) as AppFittedSheet? else null
|
|
26
|
+
Log.d(TAG, if (reactApplicationContext != null) "Found view $viewId!" else "Couldn't find view $viewId!")
|
|
27
|
+
return view ?: throw RuntimeException("ViewNotFound($viewId)")
|
|
28
|
+
} catch (e: Throwable) {
|
|
29
|
+
if (BuildConfig.DEBUG) {
|
|
30
|
+
e.printStackTrace()
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return null
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
@ReactMethod
|
|
37
|
+
fun dismiss(viewTag: Int) {
|
|
38
|
+
Handler(Looper.getMainLooper()).post {
|
|
39
|
+
val view = findSheetView(viewTag)
|
|
40
|
+
view?.dismiss()
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|