react-native-sheet2 1.2.1 → 1.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +42 -17
- package/android/src/main/java/com/modal/FullScreenDialog.kt +3 -3
- package/android/src/main/java/com/modal/TopModalView.kt +2 -2
- package/android/src/main/java/com/modal/TopModalViewManager.kt +3 -3
- package/android/src/main/java/com/sheet/AppFittedSheet.kt +6 -9
- package/android/src/main/java/com/sheet/FragmentModalBottomSheet.kt +10 -7
- package/android/src/main/java/com/sheet/utils.kt +25 -6
- package/package.json +1 -1
- package/src/FittedSheet.js +111 -0
- package/src/FittedSheet.tsx +2 -5
- package/src/TopModal.js +44 -0
- package/src/TopModal.tsx +2 -2
- package/src/index.js +3 -0
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@ Native implementation of Bottom sheet
|
|
|
7
7
|
## Installation
|
|
8
8
|
|
|
9
9
|
```sh
|
|
10
|
-
"react-native-sheet": "
|
|
10
|
+
"react-native-sheet": "1.2.1"
|
|
11
11
|
```
|
|
12
12
|
|
|
13
13
|
## Usage
|
|
@@ -16,21 +16,39 @@ Native implementation of Bottom sheet
|
|
|
16
16
|
import {
|
|
17
17
|
FITTED_SHEET_SCROLL_VIEW,
|
|
18
18
|
FittedSheet,
|
|
19
|
+
useFittedSheetContext,
|
|
19
20
|
} from 'react-native-sheet';
|
|
20
21
|
import { ScrollView, TouchableOpacity } from 'react-native';
|
|
21
22
|
|
|
23
|
+
|
|
24
|
+
const RenderSheetComponent: React.FC = () => {
|
|
25
|
+
// context available in bottom sheet
|
|
26
|
+
// these are methods available: hide, passScrollViewReactTag
|
|
27
|
+
// method hide accepts parameters which will be passed to onDimiss callback from bottomSheet
|
|
28
|
+
const sheetContext = useFittedSheetContext()
|
|
29
|
+
|
|
30
|
+
return (
|
|
31
|
+
<ScrollView
|
|
32
|
+
// used for find scrollView in Native Code
|
|
33
|
+
nativeId={FITTED_SHEET_SCROLL_VIEW}
|
|
34
|
+
/>
|
|
35
|
+
)
|
|
36
|
+
}
|
|
37
|
+
|
|
22
38
|
const App: React.FC = () => {
|
|
23
39
|
const sheetRef = useRef<FittedSheet>(null);
|
|
40
|
+
|
|
41
|
+
useEffect(() => {
|
|
42
|
+
// if scrollView creates dynamically in bottom sheet (for example after loading)
|
|
43
|
+
// you have to pass nativeID of scroll view by calling passScrollViewReactTag
|
|
44
|
+
sheetRef.current?.passScrollViewReactTag('scrollView')
|
|
45
|
+
}, [])
|
|
24
46
|
|
|
25
47
|
return (
|
|
26
48
|
<>
|
|
27
49
|
<TouchableOpacity onPress={() => {
|
|
28
|
-
//
|
|
29
|
-
sheetRef.current?.show(
|
|
30
|
-
|
|
31
|
-
// also there is `showElement` method
|
|
32
|
-
// which accept function for lazy require component and render it
|
|
33
|
-
sheetRef.current?.showElement(() => require('./someLazyView').default, {field: 'value'})
|
|
50
|
+
// show also accept params which will be passed to render function
|
|
51
|
+
sheetRef.current?.show()
|
|
34
52
|
}}>
|
|
35
53
|
<Text>Show sheet</Text>
|
|
36
54
|
</TouchableOpacity>
|
|
@@ -38,28 +56,35 @@ const App: React.FC = () => {
|
|
|
38
56
|
|
|
39
57
|
<FittedSheet
|
|
40
58
|
ref={sheetRef}
|
|
59
|
+
onSheetDismiss={(paramsPassedToHideMethod) => {
|
|
60
|
+
// called when sheet completely hided
|
|
61
|
+
}}
|
|
41
62
|
params={{
|
|
42
63
|
// top left right corner sheet view radius
|
|
43
64
|
topLeftRightCornerRadius: 20,
|
|
44
65
|
// background color of sheet view
|
|
45
66
|
backgroundColor: 'purple',
|
|
46
67
|
// max allowed height of sheet view
|
|
47
|
-
maxHeight: 600
|
|
68
|
+
maxHeight: 600,
|
|
69
|
+
// min height of sheet view
|
|
70
|
+
minHeight: 600,
|
|
71
|
+
// max allowed width in portrait view
|
|
72
|
+
maxPortraitWidth: 300
|
|
73
|
+
// max allowed width in landscape view
|
|
74
|
+
maxLandscapeWidth: 300,
|
|
75
|
+
// should status bar on android be either dark of light
|
|
76
|
+
isSystemUILight: false
|
|
48
77
|
}}
|
|
49
|
-
ref={sheetRef}
|
|
50
78
|
>
|
|
51
|
-
//
|
|
52
|
-
// was call as FittedSheet will render require component
|
|
79
|
+
// data which was passed to .show() method
|
|
53
80
|
{(data) => {
|
|
54
81
|
return (
|
|
55
|
-
<
|
|
56
|
-
// used for find scrollView in Native Code
|
|
57
|
-
nativeId={FITTED_SHEET_SCROLL_VIEW}
|
|
58
|
-
// used in android which allows scrollView/FlatList scroll
|
|
59
|
-
nestedScrollEnabled
|
|
60
|
-
/>
|
|
82
|
+
<RenderSheetComponent/>
|
|
61
83
|
);
|
|
62
84
|
}}
|
|
85
|
+
|
|
86
|
+
// if you do not need data you can omit render function and pass just component
|
|
87
|
+
<RenderSheetComponent/>
|
|
63
88
|
</FittedSheet>
|
|
64
89
|
</>
|
|
65
90
|
)
|
|
@@ -14,7 +14,7 @@ import androidx.coordinatorlayout.widget.CoordinatorLayout
|
|
|
14
14
|
import androidx.fragment.app.DialogFragment
|
|
15
15
|
import androidx.fragment.app.FragmentManager
|
|
16
16
|
import com.sheet.R
|
|
17
|
-
import com.sheet.
|
|
17
|
+
import com.sheet.setStatusBarStyle
|
|
18
18
|
|
|
19
19
|
|
|
20
20
|
fun androidx.fragment.app.Fragment.safeShow(
|
|
@@ -32,7 +32,7 @@ class FullScreenDialog(
|
|
|
32
32
|
// "slide" || "fade"
|
|
33
33
|
private val animationType: String,
|
|
34
34
|
private val isEdgeToEdge: Boolean,
|
|
35
|
-
private val
|
|
35
|
+
private val isSystemUILight: Boolean,
|
|
36
36
|
private val onDismiss: () -> Unit
|
|
37
37
|
) : DialogFragment() {
|
|
38
38
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
@@ -64,7 +64,7 @@ class FullScreenDialog(
|
|
|
64
64
|
it.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE or
|
|
65
65
|
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
|
|
66
66
|
|
|
67
|
-
it.
|
|
67
|
+
it.setStatusBarStyle(isSystemUILight)
|
|
68
68
|
} else {
|
|
69
69
|
val width = ViewGroup.LayoutParams.MATCH_PARENT
|
|
70
70
|
val height = ViewGroup.LayoutParams.MATCH_PARENT
|
|
@@ -22,7 +22,7 @@ class TopModalView(context: Context?) : ReactViewGroup(context) {
|
|
|
22
22
|
private var rnView = BaseRNView(context)
|
|
23
23
|
|
|
24
24
|
var isEdgeToEdge = false
|
|
25
|
-
var
|
|
25
|
+
var isSystemUILight = false
|
|
26
26
|
var animated = true
|
|
27
27
|
// "slide" || "fade"
|
|
28
28
|
var animationType = "slide"
|
|
@@ -43,7 +43,7 @@ class TopModalView(context: Context?) : ReactViewGroup(context) {
|
|
|
43
43
|
animated = animated,
|
|
44
44
|
animationType = animationType,
|
|
45
45
|
isEdgeToEdge = isEdgeToEdge,
|
|
46
|
-
|
|
46
|
+
isSystemUILight = isSystemUILight,
|
|
47
47
|
::onModalDismiss,
|
|
48
48
|
)
|
|
49
49
|
dialog?.safeShow(activity.supportFragmentManager, "TopModalView")
|
|
@@ -38,9 +38,9 @@ class TopModalViewManager : ViewGroupManager<TopModalView>() {
|
|
|
38
38
|
fun setIsEdgeToEdge(view: TopModalView, isEdgeToEdge: Boolean) {
|
|
39
39
|
view.isEdgeToEdge = isEdgeToEdge
|
|
40
40
|
}
|
|
41
|
-
@ReactProp(name = "
|
|
42
|
-
fun
|
|
43
|
-
view.
|
|
41
|
+
@ReactProp(name = "isSystemUILight")
|
|
42
|
+
fun setIsSystemUILight(view: TopModalView, isSystemUILight: Boolean) {
|
|
43
|
+
view.isSystemUILight = isSystemUILight
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
@ReactProp(name="animated")
|
|
@@ -39,16 +39,14 @@ class AppFittedSheet(context: Context) : ViewGroup(context), LifecycleEventListe
|
|
|
39
39
|
field = value
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
private val
|
|
43
|
-
get() = params.bool("
|
|
42
|
+
private val dismissable: Boolean
|
|
43
|
+
get() = params.bool("dismissable", true)
|
|
44
44
|
private val topLeftRightCornerRadius: Float
|
|
45
45
|
get() = params.float("topLeftRightCornerRadius", 0f)
|
|
46
46
|
private val backgroundColor: Int
|
|
47
47
|
get() = params?.color("backgroundColor", context) ?: Color.TRANSPARENT
|
|
48
|
-
private val
|
|
49
|
-
get() = params
|
|
50
|
-
private val isStatusBarBgLight: Boolean
|
|
51
|
-
get() = params?.bool("isStatusBarBgLight", false) ?: false
|
|
48
|
+
private val isSystemUILight: Boolean
|
|
49
|
+
get() = params?.bool("isSystemUILight", false) ?: false
|
|
52
50
|
|
|
53
51
|
private fun getCurrentActivity(): AppCompatActivity? {
|
|
54
52
|
return (context as ReactContext)?.currentActivity as? AppCompatActivity
|
|
@@ -67,9 +65,8 @@ class AppFittedSheet(context: Context) : ViewGroup(context), LifecycleEventListe
|
|
|
67
65
|
if (sheet == null) {
|
|
68
66
|
val fragment = FragmentModalBottomSheet(
|
|
69
67
|
modalView = mHostView,
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
isStatusBarBgLight = isStatusBarBgLight
|
|
68
|
+
dismissable = dismissable,
|
|
69
|
+
isSystemUILight = isSystemUILight
|
|
73
70
|
) {
|
|
74
71
|
println("😀 onDismiss")
|
|
75
72
|
val parent = mHostView.parent as? ViewGroup
|
|
@@ -13,9 +13,8 @@ import java.lang.ref.WeakReference
|
|
|
13
13
|
|
|
14
14
|
class FragmentModalBottomSheet(
|
|
15
15
|
private val modalView: ViewGroup,
|
|
16
|
-
private val
|
|
17
|
-
private val
|
|
18
|
-
private val isStatusBarBgLight: Boolean,
|
|
16
|
+
private val dismissable: Boolean,
|
|
17
|
+
private val isSystemUILight: Boolean,
|
|
19
18
|
private val onDismiss: () -> Unit
|
|
20
19
|
) : BottomSheetDialogFragment() {
|
|
21
20
|
|
|
@@ -30,13 +29,17 @@ class FragmentModalBottomSheet(
|
|
|
30
29
|
): View = modalView
|
|
31
30
|
|
|
32
31
|
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
|
33
|
-
this.isCancelable =
|
|
34
|
-
val dialog = CustomBottomSheetDialog(requireContext(),
|
|
32
|
+
this.isCancelable = dismissable
|
|
33
|
+
val dialog = CustomBottomSheetDialog(requireContext(), R.style.AppBottomSheetDialog)
|
|
35
34
|
dialog.setSheetBackgroundColor(Color.TRANSPARENT)
|
|
36
35
|
dialog.window?.let {
|
|
37
36
|
presentedWindow = WeakReference(it)
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
it.setStatusBarStyle(isSystemUILight)
|
|
38
|
+
if (isSystemUILight) {
|
|
39
|
+
it.setSystemUIColor(Color.WHITE)
|
|
40
|
+
} else {
|
|
41
|
+
it.setSystemUIColor(Color.BLACK)
|
|
42
|
+
}
|
|
40
43
|
}
|
|
41
44
|
return dialog
|
|
42
45
|
}
|
|
@@ -2,8 +2,10 @@ package com.sheet
|
|
|
2
2
|
|
|
3
3
|
import android.content.Context
|
|
4
4
|
import android.graphics.Color
|
|
5
|
+
import android.os.Build
|
|
5
6
|
import android.view.View
|
|
6
7
|
import android.view.Window
|
|
8
|
+
import android.view.WindowInsetsController
|
|
7
9
|
import com.facebook.react.bridge.ColorPropConverter
|
|
8
10
|
import com.facebook.react.bridge.ReadableMap
|
|
9
11
|
import com.facebook.react.uimanager.PixelUtil
|
|
@@ -40,12 +42,29 @@ fun ReadableMap.color(value: String, context: Context): Int {
|
|
|
40
42
|
return ColorPropConverter.getColor(getDouble("backgroundColor"), context)
|
|
41
43
|
}
|
|
42
44
|
|
|
43
|
-
fun Window.
|
|
44
|
-
if (
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
fun Window.setStatusBarStyle(isLight: Boolean) {
|
|
46
|
+
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) return
|
|
47
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
|
48
|
+
decorView.windowInsetsController?.setSystemBarsAppearance(
|
|
49
|
+
if (!isLight) WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS else 0,
|
|
50
|
+
WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS
|
|
51
|
+
);
|
|
47
52
|
} else {
|
|
48
|
-
|
|
49
|
-
|
|
53
|
+
if (isLight) {
|
|
54
|
+
// Draw light icons on a dark background color
|
|
55
|
+
decorView.systemUiVisibility =
|
|
56
|
+
decorView.systemUiVisibility and View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR.inv()
|
|
57
|
+
} else {
|
|
58
|
+
// Draw dark icons on a light background color
|
|
59
|
+
decorView.systemUiVisibility =
|
|
60
|
+
decorView.systemUiVisibility or View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
fun Window.setSystemUIColor(color: Int) {
|
|
66
|
+
navigationBarColor = color
|
|
67
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
|
68
|
+
isNavigationBarContrastEnforced = false
|
|
50
69
|
}
|
|
51
70
|
}
|
package/package.json
CHANGED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import React, { createContext, useContext } from 'react';
|
|
2
|
+
import { Dimensions, findNodeHandle, NativeModules, processColor, requireNativeComponent, StatusBar, View, } from 'react-native';
|
|
3
|
+
export const _FittedSheet = requireNativeComponent('SheetView');
|
|
4
|
+
export const FITTED_SHEET_SCROLL_VIEW = 'fittedSheetScrollView';
|
|
5
|
+
const FittedSheetContext = createContext(null);
|
|
6
|
+
export const useFittedSheetContext = () => {
|
|
7
|
+
return useContext(FittedSheetContext);
|
|
8
|
+
};
|
|
9
|
+
export class FittedSheet extends React.PureComponent {
|
|
10
|
+
cleanup;
|
|
11
|
+
shouldShowBack = false;
|
|
12
|
+
onHidePassThroughParam;
|
|
13
|
+
sheetRef = React.createRef();
|
|
14
|
+
constructor(props) {
|
|
15
|
+
super(props);
|
|
16
|
+
this.state = { show: false, data: null, maxHeight: -1 };
|
|
17
|
+
}
|
|
18
|
+
show = (data) => {
|
|
19
|
+
this.setState({ show: true, data });
|
|
20
|
+
};
|
|
21
|
+
data = () => this.state.data;
|
|
22
|
+
onLayout = (e) => {
|
|
23
|
+
this.setState({ maxHeight: e.nativeEvent.layout.height });
|
|
24
|
+
};
|
|
25
|
+
toggle = () => {
|
|
26
|
+
this.setState({ show: !this.state.show });
|
|
27
|
+
};
|
|
28
|
+
passScrollViewReactTag = (nativeId) => {
|
|
29
|
+
console.log('🍓[FittedSheet.passScrollViewReactTag]', nativeId);
|
|
30
|
+
this.sheetRef.current?.setNativeProps({ passScrollViewReactTag: nativeId });
|
|
31
|
+
};
|
|
32
|
+
increaseHeight = (by) => {
|
|
33
|
+
//this.sheetRef.current?.setNativeProps({ increaseHeight: by });
|
|
34
|
+
this.setState({ maxHeight: this.state.maxHeight + by });
|
|
35
|
+
};
|
|
36
|
+
decreaseHeight = (by) => {
|
|
37
|
+
const minHeight = this.props.params?.minHeight;
|
|
38
|
+
this.setState({
|
|
39
|
+
maxHeight: Math.max(minHeight ?? 0, this.state.maxHeight - by),
|
|
40
|
+
});
|
|
41
|
+
//this.sheetRef.current?.setNativeProps({ decreaseHeight: by });
|
|
42
|
+
};
|
|
43
|
+
hide = (passThroughParam) => {
|
|
44
|
+
if (!this.state.show)
|
|
45
|
+
return;
|
|
46
|
+
this.onHidePassThroughParam = passThroughParam;
|
|
47
|
+
const tag = findNodeHandle(this.sheetRef.current);
|
|
48
|
+
if (!tag)
|
|
49
|
+
return;
|
|
50
|
+
NativeModules.SheetView.dismiss(tag);
|
|
51
|
+
};
|
|
52
|
+
onDismiss = () => {
|
|
53
|
+
if (this.shouldShowBack) {
|
|
54
|
+
this.setState({ show: false }, () => this.show(this.state.data));
|
|
55
|
+
this.shouldShowBack = false;
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
this.setState({ show: false });
|
|
59
|
+
const passValue = this.onHidePassThroughParam;
|
|
60
|
+
this.onHidePassThroughParam = undefined;
|
|
61
|
+
this.props.onSheetDismiss?.(passValue);
|
|
62
|
+
};
|
|
63
|
+
componentDidMount() {
|
|
64
|
+
this.cleanup = Dimensions.addEventListener('change', () => {
|
|
65
|
+
if (!this.state.show)
|
|
66
|
+
return;
|
|
67
|
+
if (this.shouldShowBack)
|
|
68
|
+
return;
|
|
69
|
+
this.shouldShowBack = true;
|
|
70
|
+
this.hide();
|
|
71
|
+
}).remove;
|
|
72
|
+
}
|
|
73
|
+
componentWillUnmount() {
|
|
74
|
+
this.hide();
|
|
75
|
+
this.cleanup?.();
|
|
76
|
+
this.cleanup = undefined;
|
|
77
|
+
}
|
|
78
|
+
render() {
|
|
79
|
+
if (!this.state.show)
|
|
80
|
+
return null;
|
|
81
|
+
const dim = Dimensions.get('screen');
|
|
82
|
+
const isLandscape = dim.width > dim.height;
|
|
83
|
+
let maxHeight = Math.min(this.props.params?.maxHeight ?? Number.MAX_VALUE, dim.height - (StatusBar.currentHeight ?? 0));
|
|
84
|
+
const paramsMaxWidth = isLandscape
|
|
85
|
+
? this.props.params?.maxLandscapeWidth
|
|
86
|
+
: this.props.params?.maxPortraitWidth;
|
|
87
|
+
let maxWidth = Math.min(paramsMaxWidth ?? Number.MAX_VALUE, dim.width);
|
|
88
|
+
let minHeight = this.props.params?.minHeight;
|
|
89
|
+
if (this.props.params?.applyMaxHeightToMinHeight) {
|
|
90
|
+
minHeight = maxHeight;
|
|
91
|
+
}
|
|
92
|
+
return (React.createElement(_FittedSheet, { onSheetDismiss: this.onDismiss, ref: this.sheetRef, style: { width: maxWidth, maxHeight, minHeight, position: 'absolute' }, fittedSheetParams: this.props.params
|
|
93
|
+
? {
|
|
94
|
+
...this.props.params,
|
|
95
|
+
maxHeight,
|
|
96
|
+
maxWidth,
|
|
97
|
+
backgroundColor: this.props.params.backgroundColor
|
|
98
|
+
? processColor(this.props.params.backgroundColor)
|
|
99
|
+
: undefined,
|
|
100
|
+
}
|
|
101
|
+
: {} },
|
|
102
|
+
React.createElement(FittedSheetContext.Provider, { value: this },
|
|
103
|
+
React.createElement(View, { nativeID: 'fitted-sheet-root-view', style: { maxHeight, minHeight, maxWidth }, onLayout: this.onLayout },
|
|
104
|
+
this.props.children &&
|
|
105
|
+
typeof this.props.children === 'function' &&
|
|
106
|
+
this.props.children(this.state.data),
|
|
107
|
+
this.props.children &&
|
|
108
|
+
typeof this.props.children !== 'function' &&
|
|
109
|
+
this.props.children))));
|
|
110
|
+
}
|
|
111
|
+
}
|
package/src/FittedSheet.tsx
CHANGED
|
@@ -14,18 +14,17 @@ export const _FittedSheet = requireNativeComponent<any>('SheetView');
|
|
|
14
14
|
|
|
15
15
|
export interface FittedSheetParams {
|
|
16
16
|
readonly applyMaxHeightToMinHeight?: boolean;
|
|
17
|
-
readonly
|
|
17
|
+
readonly dismissable?: boolean;
|
|
18
18
|
readonly maxPortraitWidth?: number;
|
|
19
19
|
readonly maxLandscapeWidth?: number;
|
|
20
20
|
readonly maxHeight?: number;
|
|
21
21
|
readonly minHeight?: number;
|
|
22
|
-
readonly isDark?: boolean;
|
|
23
22
|
readonly topLeftRightCornerRadius?: number;
|
|
24
23
|
readonly backgroundColor?: string;
|
|
25
24
|
/**
|
|
26
25
|
* Android only
|
|
27
26
|
*/
|
|
28
|
-
readonly
|
|
27
|
+
readonly isSystemUILight?: boolean;
|
|
29
28
|
}
|
|
30
29
|
|
|
31
30
|
type Children =
|
|
@@ -77,7 +76,6 @@ export class FittedSheet extends React.PureComponent<Props, State> {
|
|
|
77
76
|
data = () => this.state.data;
|
|
78
77
|
|
|
79
78
|
onLayout = (e: LayoutChangeEvent) => {
|
|
80
|
-
console.log('🍓[FittedSheet.onLayout]', e.nativeEvent.layout.height);
|
|
81
79
|
this.setState({ maxHeight: e.nativeEvent.layout.height });
|
|
82
80
|
};
|
|
83
81
|
|
|
@@ -166,7 +164,6 @@ export class FittedSheet extends React.PureComponent<Props, State> {
|
|
|
166
164
|
this.props.params
|
|
167
165
|
? {
|
|
168
166
|
...this.props.params,
|
|
169
|
-
isDark: this.props.params.isDark ?? false,
|
|
170
167
|
maxHeight,
|
|
171
168
|
maxWidth,
|
|
172
169
|
backgroundColor: this.props.params.backgroundColor
|
package/src/TopModal.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { findNodeHandle, NativeModules, requireNativeComponent, StyleSheet, View, } from 'react-native';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
const TopModalView = requireNativeComponent('TopModalView');
|
|
4
|
+
export class TopModal extends React.PureComponent {
|
|
5
|
+
sheetRef = React.createRef();
|
|
6
|
+
constructor(props) {
|
|
7
|
+
super(props);
|
|
8
|
+
this.state = {
|
|
9
|
+
show: false,
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
show = () => {
|
|
13
|
+
if (this.state.show)
|
|
14
|
+
return;
|
|
15
|
+
this.setState({ show: true });
|
|
16
|
+
};
|
|
17
|
+
hide = () => {
|
|
18
|
+
if (!this.state.show)
|
|
19
|
+
return;
|
|
20
|
+
const tag = findNodeHandle(this.sheetRef.current);
|
|
21
|
+
if (!tag)
|
|
22
|
+
return;
|
|
23
|
+
console.log('[TopModal.hide]', tag);
|
|
24
|
+
NativeModules.TopModalView.dismiss(tag);
|
|
25
|
+
};
|
|
26
|
+
onDismiss = () => {
|
|
27
|
+
console.log('[FittedSheet.onDismiss]');
|
|
28
|
+
this.setState({ show: false });
|
|
29
|
+
this.props.onModalDismiss?.();
|
|
30
|
+
};
|
|
31
|
+
componentWillUnmount() {
|
|
32
|
+
this.hide();
|
|
33
|
+
console.log('[TopModal.componentWillUnmount]');
|
|
34
|
+
}
|
|
35
|
+
render() {
|
|
36
|
+
if (!this.state.show) {
|
|
37
|
+
this.hide();
|
|
38
|
+
console.log('[TopModal.render.remove]');
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
return (React.createElement(TopModalView, { ref: this.sheetRef, onModalDismiss: this.onDismiss, animated: this.props.animated ?? true, animationType: this.props.animationType ?? 'slide', isEdgeToEdge: this.props.isEdgeToEdge ?? false, isStatusBarBgLight: this.props.isSystemUILight ?? false },
|
|
42
|
+
React.createElement(View, { accessibilityLabel: 'top-modal-root-view', nativeID: 'top-modal-root-view', style: StyleSheet.absoluteFill, children: this.props.children })));
|
|
43
|
+
}
|
|
44
|
+
}
|
package/src/TopModal.tsx
CHANGED
|
@@ -22,7 +22,7 @@ interface Props {
|
|
|
22
22
|
* @default false
|
|
23
23
|
* @platform Android
|
|
24
24
|
*/
|
|
25
|
-
|
|
25
|
+
isSystemUILight?: boolean;
|
|
26
26
|
|
|
27
27
|
animated?: boolean;
|
|
28
28
|
/** @default "slide" */
|
|
@@ -80,7 +80,7 @@ export class TopModal extends React.PureComponent<Props, State> {
|
|
|
80
80
|
animated={this.props.animated ?? true}
|
|
81
81
|
animationType={this.props.animationType ?? 'slide'}
|
|
82
82
|
isEdgeToEdge={this.props.isEdgeToEdge ?? false}
|
|
83
|
-
isStatusBarBgLight={this.props.
|
|
83
|
+
isStatusBarBgLight={this.props.isSystemUILight ?? false}
|
|
84
84
|
>
|
|
85
85
|
<View
|
|
86
86
|
accessibilityLabel={'top-modal-root-view'}
|
package/src/index.js
ADDED