react-native-sheet2 1.2.4 → 1.2.6
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/ios/SheetViewManager.swift +7 -5
- package/package.json +1 -1
- package/src/FittedSheet.tsx +5 -1
- package/src/FittedSheet.js +0 -111
- package/src/TopModal.js +0 -44
- package/src/index.js +0 -3
|
@@ -25,7 +25,7 @@ class ModalHostShadowView: RCTShadowView {
|
|
|
25
25
|
subview.position = .absolute
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
|
-
|
|
28
|
+
|
|
29
29
|
func renderSizes(subviews: [RCTShadowView]?) {
|
|
30
30
|
guard let subviews else { return }
|
|
31
31
|
for v in subviews {
|
|
@@ -33,10 +33,10 @@ class ModalHostShadowView: RCTShadowView {
|
|
|
33
33
|
renderSizes(subviews: v.reactSubviews())
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
|
-
|
|
36
|
+
|
|
37
37
|
override func layoutSubviews(with layoutContext: RCTLayoutContext) {
|
|
38
38
|
super.layoutSubviews(with: layoutContext)
|
|
39
|
-
|
|
39
|
+
|
|
40
40
|
RCTExecuteOnMainQueue { [weak self] in
|
|
41
41
|
guard let self else { return }
|
|
42
42
|
let view = RCTBridge.current().uiManager.view(
|
|
@@ -116,7 +116,7 @@ class HostFittedSheet: UIView {
|
|
|
116
116
|
var sheetMinHeightSize: NSNumber?
|
|
117
117
|
private var topLeftRightCornerRadius: NSNumber?
|
|
118
118
|
private var sheetBackgroundColor: UIColor?
|
|
119
|
-
|
|
119
|
+
|
|
120
120
|
@objc
|
|
121
121
|
func setPassScrollViewReactTag(_ tag: NSNumber) {
|
|
122
122
|
debugPrint("😀 setPassScrollViewReactTag", tag)
|
|
@@ -277,7 +277,9 @@ class HostFittedSheet: UIView {
|
|
|
277
277
|
ModalHostShadowView.attachedViews.removeValue(forKey: self.reactTag.intValue)
|
|
278
278
|
self._modalViewController = nil
|
|
279
279
|
self._reactSubview?.removeFromSuperview()
|
|
280
|
-
|
|
280
|
+
if let v = self._reactSubview {
|
|
281
|
+
self._touchHandler?.detach(from: self._reactSubview)
|
|
282
|
+
}
|
|
281
283
|
self._touchHandler = nil
|
|
282
284
|
self._bridge = nil
|
|
283
285
|
self.onSheetDismiss = nil
|
package/package.json
CHANGED
package/src/FittedSheet.tsx
CHANGED
|
@@ -56,7 +56,11 @@ interface Context {
|
|
|
56
56
|
const FittedSheetContext = createContext<Context | null>(null);
|
|
57
57
|
|
|
58
58
|
export const useFittedSheetContext = () => {
|
|
59
|
-
|
|
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> {
|
package/src/FittedSheet.js
DELETED
|
@@ -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