react-native-sheet2 1.2.4 → 1.2.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-sheet2",
3
- "version": "1.2.4",
3
+ "version": "1.2.5",
4
4
  "description": "Native implementation of Bottom sheet",
5
5
  "main": "src/index",
6
6
  "module": "src/index",
@@ -56,7 +56,11 @@ interface Context {
56
56
  const FittedSheetContext = createContext<Context | null>(null);
57
57
 
58
58
  export const useFittedSheetContext = () => {
59
- return useContext(FittedSheetContext)!;
59
+ try {
60
+ return useContext(FittedSheetContext);
61
+ } catch {
62
+ return undefined;
63
+ }
60
64
  };
61
65
 
62
66
  export class FittedSheet extends React.PureComponent<Props, State> {
@@ -1,111 +0,0 @@
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/TopModal.js DELETED
@@ -1,44 +0,0 @@
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/index.js DELETED
@@ -1,3 +0,0 @@
1
- import { FITTED_SHEET_SCROLL_VIEW, FittedSheet, useFittedSheetContext, } from './FittedSheet';
2
- export { FittedSheet, FITTED_SHEET_SCROLL_VIEW, useFittedSheetContext };
3
- export { TopModal } from './TopModal';