react-native-sheet2 6.1.19 → 7.12.4
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 +754 -80
- package/{Sheet.podspec → Sheet2.podspec} +2 -2
- package/android/build.gradle +2 -25
- package/android/check.jks +0 -0
- package/android/src/main/AndroidManifest.xml +1 -2
- package/android/src/main/cpp/react/renderer/components/SheetViewSpec/SheetViewComponentDescriptor.h +12 -0
- package/android/src/main/cpp/react/renderer/components/SheetViewSpec/SheetViewShadowNode.cpp +17 -0
- package/android/src/main/cpp/react/renderer/components/SheetViewSpec/SheetViewShadowNode.h +36 -0
- package/android/src/main/cpp/react/renderer/components/SheetViewSpec/SheetViewState.h +52 -0
- package/android/src/main/java/com/behavior/BottomSheetBehavior.java +84 -16
- package/android/src/main/java/com/sheet2/AppFittedSheet.kt +431 -0
- package/android/src/main/java/com/{sheet → sheet2}/BaseRNView.kt +38 -31
- package/android/src/main/java/com/sheet2/CenteredSheetDialog.kt +272 -0
- package/android/src/main/java/com/{sheet → sheet2}/CustomBottomSheetDialog.java +32 -4
- package/android/src/main/java/com/{sheet → sheet2}/DialogRootViewGroup.kt +54 -12
- package/android/src/main/java/com/sheet2/FragmentModalBottomSheet.kt +161 -0
- package/android/src/main/java/com/sheet2/InlineFooterPresenter.kt +74 -0
- package/android/src/main/java/com/sheet2/InlineSheetPresenter.kt +249 -0
- package/android/src/main/java/com/sheet2/PassThroughLayouts.kt +17 -0
- package/android/src/main/java/com/{sheet → sheet2}/SafeAreaUtils.kt +4 -5
- package/android/src/main/java/com/sheet2/Sheet2Package.kt +44 -0
- package/android/src/main/java/com/sheet2/Sheet2View.kt +5 -0
- package/android/src/main/java/com/sheet2/Sheet2ViewManager.kt +163 -0
- package/android/src/main/java/com/{sheet → sheet2}/SheetDismissEvent.kt +1 -1
- package/android/src/main/java/com/{sheet → sheet2}/SheetModule.kt +14 -3
- package/android/src/main/java/com/{sheet → sheet2}/SheetPackage.kt +2 -3
- package/android/src/main/java/com/sheet2/SheetTreeLog.kt +78 -0
- package/android/src/main/java/com/{sheet → sheet2}/utils.kt +1 -2
- package/android/src/main/jni/CMakeLists.txt +72 -0
- package/android/src/main/jni/SheetViewSpec.h +40 -0
- package/ios/FittedSheets/SheetOptions.swift +5 -0
- package/ios/FittedSheets/SheetTransition.swift +83 -4
- package/ios/FittedSheets/SheetViewController.swift +222 -24
- package/ios/HostFittedSheet.swift +440 -51
- package/ios/SheetModule.h +5 -4
- package/ios/SheetModule.mm +11 -1
- package/ios/SheetTreeLog.swift +52 -0
- package/ios/SheetView.mm +118 -31
- package/ios/SheetViewComponentDescriptor.h +24 -0
- package/ios/SheetViewShadowNode.cpp +17 -0
- package/ios/SheetViewShadowNode.h +37 -0
- package/ios/SheetViewState.h +54 -0
- package/package.json +44 -74
- package/react-native.config.js +6 -4
- package/src/FittedSheet.tsx +131 -71
- package/src/GlobalSheetView.tsx +209 -0
- package/src/NativeSheet.ts +4 -0
- package/src/PublicSheetView.tsx +2 -1
- package/src/SheetTreeLog.ts +39 -0
- package/src/SheetViewNativeComponent.ts +25 -4
- package/src/index.tsx +29 -4
- package/src/logger.ts +16 -0
- package/android/generated/java/com/facebook/react/viewmanagers/SheetViewManagerDelegate.java +0 -67
- package/android/generated/java/com/facebook/react/viewmanagers/SheetViewManagerInterface.java +0 -27
- package/android/generated/java/com/sheet/NativeSheetSpec.java +0 -78
- package/android/generated/jni/CMakeLists.txt +0 -36
- package/android/generated/jni/RNSheetViewSpec-generated.cpp +0 -50
- package/android/generated/jni/RNSheetViewSpec.h +0 -31
- package/android/generated/jni/react/renderer/components/RNSheetViewSpec/ComponentDescriptors.cpp +0 -22
- package/android/generated/jni/react/renderer/components/RNSheetViewSpec/ComponentDescriptors.h +0 -24
- package/android/generated/jni/react/renderer/components/RNSheetViewSpec/EventEmitters.cpp +0 -24
- package/android/generated/jni/react/renderer/components/RNSheetViewSpec/EventEmitters.h +0 -25
- package/android/generated/jni/react/renderer/components/RNSheetViewSpec/Props.cpp +0 -33
- package/android/generated/jni/react/renderer/components/RNSheetViewSpec/Props.h +0 -36
- package/android/generated/jni/react/renderer/components/RNSheetViewSpec/RNSheetViewSpecJSI-generated.cpp +0 -46
- package/android/generated/jni/react/renderer/components/RNSheetViewSpec/RNSheetViewSpecJSI.h +0 -98
- package/android/generated/jni/react/renderer/components/RNSheetViewSpec/ShadowNodes.cpp +0 -17
- package/android/generated/jni/react/renderer/components/RNSheetViewSpec/ShadowNodes.h +0 -32
- package/android/generated/jni/react/renderer/components/RNSheetViewSpec/States.cpp +0 -16
- package/android/generated/jni/react/renderer/components/RNSheetViewSpec/States.h +0 -29
- package/android/src/main/AndroidManifestNew.xml +0 -2
- package/android/src/main/java/com/sheet/AppFittedSheet.kt +0 -214
- package/android/src/main/java/com/sheet/FragmentModalBottomSheet.kt +0 -67
- package/android/src/main/java/com/sheet/SheetView.kt +0 -5
- package/android/src/main/java/com/sheet/SheetViewManager.kt +0 -106
- package/ios/generated/RNSheetViewSpec/ComponentDescriptors.cpp +0 -22
- package/ios/generated/RNSheetViewSpec/ComponentDescriptors.h +0 -24
- package/ios/generated/RNSheetViewSpec/EventEmitters.cpp +0 -24
- package/ios/generated/RNSheetViewSpec/EventEmitters.h +0 -25
- package/ios/generated/RNSheetViewSpec/Props.cpp +0 -33
- package/ios/generated/RNSheetViewSpec/Props.h +0 -36
- package/ios/generated/RNSheetViewSpec/RCTComponentViewHelpers.h +0 -44
- package/ios/generated/RNSheetViewSpec/RNSheetViewSpec-generated.mm +0 -60
- package/ios/generated/RNSheetViewSpec/RNSheetViewSpec.h +0 -100
- package/ios/generated/RNSheetViewSpec/ShadowNodes.cpp +0 -17
- package/ios/generated/RNSheetViewSpec/ShadowNodes.h +0 -32
- package/ios/generated/RNSheetViewSpec/States.cpp +0 -16
- package/ios/generated/RNSheetViewSpec/States.h +0 -29
- package/ios/generated/RNSheetViewSpecJSI-generated.cpp +0 -46
- package/ios/generated/RNSheetViewSpecJSI.h +0 -98
- package/lib/module/FittedSheet.js +0 -153
- package/lib/module/FittedSheet.js.map +0 -1
- package/lib/module/NativeSheet.ts +0 -17
- package/lib/module/PublicSheetView.js +0 -48
- package/lib/module/PublicSheetView.js.map +0 -1
- package/lib/module/SheetViewNativeComponent.ts +0 -31
- package/lib/module/index.js +0 -17
- package/lib/module/index.js.map +0 -1
- package/lib/module/package.json +0 -1
- package/lib/typescript/package.json +0 -1
- package/lib/typescript/src/FittedSheet.d.ts +0 -51
- package/lib/typescript/src/FittedSheet.d.ts.map +0 -1
- package/lib/typescript/src/NativeSheet.d.ts +0 -16
- package/lib/typescript/src/NativeSheet.d.ts.map +0 -1
- package/lib/typescript/src/PublicSheetView.d.ts +0 -12
- package/lib/typescript/src/PublicSheetView.d.ts.map +0 -1
- package/lib/typescript/src/SheetViewNativeComponent.d.ts +0 -22
- package/lib/typescript/src/SheetViewNativeComponent.d.ts.map +0 -1
- package/lib/typescript/src/index.d.ts +0 -12
- package/lib/typescript/src/index.d.ts.map +0 -1
package/src/FittedSheet.tsx
CHANGED
|
@@ -4,39 +4,72 @@ import {
|
|
|
4
4
|
type LayoutChangeEvent,
|
|
5
5
|
Platform,
|
|
6
6
|
StatusBar,
|
|
7
|
+
type StyleProp,
|
|
7
8
|
View,
|
|
9
|
+
type ViewStyle,
|
|
8
10
|
} from 'react-native';
|
|
9
11
|
|
|
10
12
|
import She, { Commands } from './SheetViewNativeComponent';
|
|
13
|
+
import { sheetLog } from './logger';
|
|
11
14
|
import SheetModule from './NativeSheet';
|
|
12
|
-
import { Portal } from '@gorhom/portal';
|
|
13
15
|
|
|
14
16
|
const _FittedSheet = She;
|
|
15
17
|
|
|
16
18
|
export interface FittedSheetParams {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
19
|
+
applyMaxHeightToMinHeight?: boolean;
|
|
20
|
+
dismissable?: boolean;
|
|
21
|
+
maxPortraitWidth?: number;
|
|
22
|
+
maxLandscapeWidth?: number;
|
|
23
|
+
maxHeight?: number;
|
|
24
|
+
minHeight?: number;
|
|
25
|
+
topLeftRightCornerRadius?: number;
|
|
26
|
+
backgroundColor?: string;
|
|
27
|
+
/**
|
|
28
|
+
* iOS only. Window level for the sheet.
|
|
29
|
+
* 'normal' | 'statusBar' | 'alert' (default: 'alert')
|
|
30
|
+
*/
|
|
31
|
+
windowLevel?: 'normal' | 'statusBar' | 'alert';
|
|
32
|
+
/**
|
|
33
|
+
* iOS only. When true, presents the sheet in the current view controller
|
|
34
|
+
* instead of creating a separate UIWindow. Default: false.
|
|
35
|
+
*/
|
|
36
|
+
useInlinePresentation?: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Presentation placement.
|
|
39
|
+
* - 'bottom' (default): anchored to the bottom of the screen.
|
|
40
|
+
* - 'center': floats in the vertical center as a dialog card, the whole
|
|
41
|
+
* screen is dimmed, dismissed by swiping down or tapping the dim.
|
|
42
|
+
* - 'footer': with `useInlinePresentation`, a static bar pinned to the bottom
|
|
43
|
+
* of the screen above inline sheets; no gestures, no dim. Android only for now.
|
|
44
|
+
* When 'center', `useInlinePresentation` is ignored (always modal).
|
|
45
|
+
*/
|
|
46
|
+
presentationStyle?: 'bottom' | 'center' | 'footer';
|
|
47
|
+
/**
|
|
48
|
+
* Enter/exit animation for `presentationStyle: 'center'`. Ignored otherwise.
|
|
49
|
+
* - 'fade' (default): fades + scales in at the center.
|
|
50
|
+
* - 'slide': slides up from the bottom and settles at the center.
|
|
51
|
+
*/
|
|
52
|
+
centerAnimation?: 'fade' | 'slide';
|
|
53
|
+
dismissOnOverlayTap?: boolean;
|
|
54
|
+
overlayOpacity?: number;
|
|
55
|
+
collapsedHeight?: number;
|
|
25
56
|
/**
|
|
26
57
|
* Android only
|
|
27
58
|
*/
|
|
28
|
-
|
|
59
|
+
isSystemUILight?: boolean;
|
|
29
60
|
}
|
|
30
61
|
|
|
31
|
-
type
|
|
62
|
+
type FittedSheetChildren =
|
|
32
63
|
| ((data: any) => React.ReactElement)
|
|
33
64
|
| React.ReactElement
|
|
34
65
|
| React.ReactElement[];
|
|
35
66
|
|
|
36
67
|
export interface SheetProps {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
68
|
+
params?: FittedSheetParams;
|
|
69
|
+
onSheetDismiss?: (passThroughParam?: any) => void;
|
|
70
|
+
children?: FittedSheetChildren;
|
|
71
|
+
overlay?: React.ReactNode;
|
|
72
|
+
rootViewStyle?: StyleProp<Omit<ViewStyle, 'flex' | 'flexGrow' | 'position'>>;
|
|
40
73
|
}
|
|
41
74
|
|
|
42
75
|
interface State {
|
|
@@ -47,15 +80,18 @@ interface State {
|
|
|
47
80
|
isLandscape: boolean;
|
|
48
81
|
}
|
|
49
82
|
|
|
83
|
+
let index = 0;
|
|
50
84
|
export class PrivateFittedSheet extends React.PureComponent<SheetProps, State> {
|
|
51
85
|
private cleanup?: () => void;
|
|
52
86
|
private onHidePassThroughParam?: any;
|
|
53
87
|
private sheetRef = React.createRef<any>();
|
|
88
|
+
private uniqueId = 0;
|
|
54
89
|
|
|
55
90
|
private dimensions: { width: number; height: number };
|
|
56
91
|
|
|
57
92
|
constructor(props: SheetProps) {
|
|
58
93
|
super(props);
|
|
94
|
+
this.uniqueId = ++index;
|
|
59
95
|
this.dimensions = this.viewportSize();
|
|
60
96
|
|
|
61
97
|
this.state = {
|
|
@@ -65,25 +101,30 @@ export class PrivateFittedSheet extends React.PureComponent<SheetProps, State> {
|
|
|
65
101
|
};
|
|
66
102
|
}
|
|
67
103
|
|
|
104
|
+
private log = (key: string, message: any | undefined = undefined) => {
|
|
105
|
+
if (message) sheetLog(`${this.uniqueId} - FittedSheet.${key}`, message);
|
|
106
|
+
else sheetLog(`${this.uniqueId} - FittedSheet.${key}`);
|
|
107
|
+
};
|
|
108
|
+
|
|
68
109
|
show = (data?: any) => {
|
|
69
110
|
this.setState({ show: true, data });
|
|
70
111
|
};
|
|
71
112
|
|
|
72
113
|
onLayout = (e: LayoutChangeEvent) => {
|
|
73
|
-
|
|
74
|
-
console.log('[FittedSheet.onLayout]', e.nativeEvent.layout.height);
|
|
114
|
+
this.log('onLayout', e.nativeEvent.layout.height);
|
|
75
115
|
this.setState({ height: e.nativeEvent.layout.height });
|
|
76
116
|
};
|
|
77
117
|
|
|
78
118
|
attachScrollViewToSheet = () => {
|
|
79
|
-
|
|
119
|
+
this.log(`attachScrollViewToSheet`);
|
|
80
120
|
this.setState({ passScrollViewReactTag: Date.now().toString() });
|
|
81
121
|
};
|
|
82
122
|
|
|
83
123
|
hide = (passThroughParam?: any) => {
|
|
84
124
|
if (!this.state.show) return;
|
|
85
125
|
this.onHidePassThroughParam = passThroughParam;
|
|
86
|
-
|
|
126
|
+
this.log('hide', Commands.dismissSheet);
|
|
127
|
+
//@ts-ignore
|
|
87
128
|
Commands.dismissSheet(this.sheetRef.current);
|
|
88
129
|
};
|
|
89
130
|
|
|
@@ -97,7 +138,7 @@ export class PrivateFittedSheet extends React.PureComponent<SheetProps, State> {
|
|
|
97
138
|
|
|
98
139
|
// @ts-ignore
|
|
99
140
|
private onDismiss = () => {
|
|
100
|
-
|
|
141
|
+
this.log('onDismiss');
|
|
101
142
|
this.setState({ show: false, height: undefined });
|
|
102
143
|
const passValue = this.onHidePassThroughParam;
|
|
103
144
|
this.onHidePassThroughParam = undefined;
|
|
@@ -109,7 +150,7 @@ export class PrivateFittedSheet extends React.PureComponent<SheetProps, State> {
|
|
|
109
150
|
}
|
|
110
151
|
|
|
111
152
|
componentDidMount() {
|
|
112
|
-
|
|
153
|
+
this.log('componentDidMount');
|
|
113
154
|
this.cleanup = Dimensions.addEventListener('change', () => {
|
|
114
155
|
this.dimensions = this.viewportSize();
|
|
115
156
|
const isLandscape = this.dimensions.width > this.dimensions.height;
|
|
@@ -118,8 +159,9 @@ export class PrivateFittedSheet extends React.PureComponent<SheetProps, State> {
|
|
|
118
159
|
}
|
|
119
160
|
|
|
120
161
|
componentWillUnmount() {
|
|
121
|
-
|
|
122
|
-
|
|
162
|
+
this.log('componentWillUnmount');
|
|
163
|
+
// The native view tears the sheet down when it is removed; a command sent to a view
|
|
164
|
+
// that is being deleted crashes Fabric.
|
|
123
165
|
this.cleanup?.();
|
|
124
166
|
this.cleanup = undefined;
|
|
125
167
|
}
|
|
@@ -137,9 +179,13 @@ export class PrivateFittedSheet extends React.PureComponent<SheetProps, State> {
|
|
|
137
179
|
|
|
138
180
|
render() {
|
|
139
181
|
if (!this.state.show) return null;
|
|
182
|
+
const insetsHeight =
|
|
183
|
+
this.props.params?.presentationStyle === 'footer'
|
|
184
|
+
? 0
|
|
185
|
+
: this.insets().top + this.insets().bottom;
|
|
140
186
|
let maxHeight = Math.min(
|
|
141
187
|
this.props.params?.maxHeight ?? Number.MAX_VALUE,
|
|
142
|
-
this.dimensions.height -
|
|
188
|
+
this.dimensions.height - insetsHeight
|
|
143
189
|
);
|
|
144
190
|
const paramsMaxWidth = this.state.isLandscape
|
|
145
191
|
? this.props.params?.maxLandscapeWidth
|
|
@@ -160,61 +206,75 @@ export class PrivateFittedSheet extends React.PureComponent<SheetProps, State> {
|
|
|
160
206
|
}
|
|
161
207
|
|
|
162
208
|
if (__DEV__) {
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
2
|
|
177
|
-
)
|
|
209
|
+
//@ts-ignore
|
|
210
|
+
const logJson = JSON.stringify(
|
|
211
|
+
{
|
|
212
|
+
maxHeight,
|
|
213
|
+
maxWidth,
|
|
214
|
+
nativeHeight,
|
|
215
|
+
isLandscape: this.state.isLandscape,
|
|
216
|
+
h: Dimensions.get('window').height,
|
|
217
|
+
sb: StatusBar.currentHeight,
|
|
218
|
+
dimensions: this.dimensions,
|
|
219
|
+
},
|
|
220
|
+
undefined,
|
|
221
|
+
2
|
|
178
222
|
);
|
|
223
|
+
this.log('render');
|
|
179
224
|
}
|
|
180
225
|
const background = this.props?.params?.backgroundColor;
|
|
181
226
|
return (
|
|
182
|
-
<
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
227
|
+
<_FittedSheet
|
|
228
|
+
key={this.uniqueId.toString()}
|
|
229
|
+
onSheetDismiss={this.onDismiss}
|
|
230
|
+
uniqueId={this.uniqueId.toString()}
|
|
231
|
+
ref={this.sheetRef}
|
|
232
|
+
onStartShouldSetResponder={this._shouldSetResponder}
|
|
233
|
+
style={{ width: maxWidth, position: 'absolute' }}
|
|
234
|
+
dismissable={this.props.params?.dismissable ?? true}
|
|
235
|
+
maxWidth={maxWidth}
|
|
236
|
+
maxHeight={maxHeight}
|
|
237
|
+
sheetBackgroundColor={background}
|
|
238
|
+
minHeight={minHeight}
|
|
239
|
+
topLeftRightCornerRadius={
|
|
240
|
+
this.props.params?.topLeftRightCornerRadius ?? 20
|
|
241
|
+
}
|
|
242
|
+
windowLevel={this.props.params?.windowLevel}
|
|
243
|
+
useInlinePresentation={this.props.params?.useInlinePresentation}
|
|
244
|
+
presentationStyle={this.props.params?.presentationStyle ?? 'bottom'}
|
|
245
|
+
centerAnimation={this.props.params?.centerAnimation ?? 'fade'}
|
|
246
|
+
dismissOnOverlayTap={
|
|
247
|
+
this.props.params?.dismissOnOverlayTap ??
|
|
248
|
+
this.props.params?.dismissable ??
|
|
249
|
+
true
|
|
250
|
+
}
|
|
251
|
+
overlayOpacity={this.props.params?.overlayOpacity ?? -1}
|
|
252
|
+
collapsedHeight={this.props.params?.collapsedHeight ?? 0}
|
|
253
|
+
isSystemUILight={this.props.params?.isSystemUILight ?? true}
|
|
254
|
+
calculatedHeight={nativeHeight}
|
|
255
|
+
passScrollViewReactTag={this.state.passScrollViewReactTag}
|
|
256
|
+
>
|
|
257
|
+
<View
|
|
258
|
+
nativeID={'fitted-sheet-root-view'}
|
|
259
|
+
onLayout={this.onLayout}
|
|
260
|
+
style={[
|
|
261
|
+
{
|
|
203
262
|
width: maxWidth,
|
|
204
263
|
maxHeight,
|
|
205
264
|
backgroundColor: background,
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
</
|
|
217
|
-
|
|
265
|
+
},
|
|
266
|
+
this.props.rootViewStyle,
|
|
267
|
+
]}
|
|
268
|
+
>
|
|
269
|
+
{this.props.children &&
|
|
270
|
+
typeof this.props.children === 'function' &&
|
|
271
|
+
this.props.children(this.state.data)}
|
|
272
|
+
{this.props.children &&
|
|
273
|
+
typeof this.props.children !== 'function' &&
|
|
274
|
+
this.props.children}
|
|
275
|
+
</View>
|
|
276
|
+
{this.props.overlay}
|
|
277
|
+
</_FittedSheet>
|
|
218
278
|
);
|
|
219
279
|
}
|
|
220
280
|
}
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import React, { memo, useEffect, useState } from 'react';
|
|
2
|
+
import { FittedSheet, type FittedSheetRef } from './index';
|
|
3
|
+
import type { SheetProps } from './FittedSheet';
|
|
4
|
+
import { sheetLog, sheetWarn } from './logger';
|
|
5
|
+
|
|
6
|
+
type GlobalProps = {
|
|
7
|
+
name: string;
|
|
8
|
+
onDismiss?: () => void;
|
|
9
|
+
sheetProps?: SheetProps;
|
|
10
|
+
children: React.ReactElement | React.ReactElement[];
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export function presentGlobalFittedSheet(params: GlobalProps): void {
|
|
14
|
+
sheetLog('[presentGlobalFittedSheet] called', { name: params.name });
|
|
15
|
+
presentGlobalSheet?.(params);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function dismissGlobalFittedSheet(name: string): void {
|
|
19
|
+
sheetLog('[dismissGlobalFittedSheet] called', { name });
|
|
20
|
+
dismissGlobalSheet?.(name);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function attachScrollViewToGlobalFittedSheet(name: string): boolean {
|
|
24
|
+
sheetLog('[attachScrollViewToGlobalFittedSheet] called', { name });
|
|
25
|
+
const ref = sheetRefs.get(name);
|
|
26
|
+
if (!ref) {
|
|
27
|
+
sheetWarn(
|
|
28
|
+
`[attachScrollViewToGlobalFittedSheet] Sheet "${name}" not found`
|
|
29
|
+
);
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
ref.attachScrollViewToSheet();
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
interface Props {
|
|
37
|
+
props: SheetProps | undefined;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Global state at module level
|
|
41
|
+
const sheetRefs = new Map<string, FittedSheetRef>();
|
|
42
|
+
const sheets = new Map<string, GlobalProps>();
|
|
43
|
+
let forceUpdate: () => void;
|
|
44
|
+
|
|
45
|
+
let presentGlobalSheet: (params: GlobalProps) => void;
|
|
46
|
+
let dismissGlobalSheet: (name: string) => void;
|
|
47
|
+
|
|
48
|
+
// Global stable callbacks
|
|
49
|
+
const handleSheetRef = (name: string, ref: FittedSheetRef | null) => {
|
|
50
|
+
if (ref) {
|
|
51
|
+
const isNewSheet = !sheetRefs.has(name);
|
|
52
|
+
sheetLog('[GlobalSheetView.handleSheetRef] mounting', {
|
|
53
|
+
name,
|
|
54
|
+
isNewSheet,
|
|
55
|
+
totalRefs: sheetRefs.size,
|
|
56
|
+
});
|
|
57
|
+
sheetRefs.set(name, ref);
|
|
58
|
+
if (isNewSheet) {
|
|
59
|
+
ref.show();
|
|
60
|
+
}
|
|
61
|
+
} else {
|
|
62
|
+
const hadRef = sheetRefs.has(name);
|
|
63
|
+
sheetRefs.delete(name);
|
|
64
|
+
sheetLog('[GlobalSheetView.handleSheetRef] unmounting', {
|
|
65
|
+
name,
|
|
66
|
+
hadRef,
|
|
67
|
+
totalRefs: sheetRefs.size,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
const handleSheetDismiss = (name: string) => {
|
|
73
|
+
sheetLog('[GlobalSheetView.handleSheetDismiss] start', {
|
|
74
|
+
name,
|
|
75
|
+
totalSheets: sheets.size,
|
|
76
|
+
totalRefs: sheetRefs.size,
|
|
77
|
+
});
|
|
78
|
+
const dataToRender = sheets.get(name);
|
|
79
|
+
dataToRender?.onDismiss?.();
|
|
80
|
+
sheets.delete(name);
|
|
81
|
+
// Note: Don't delete from sheetRefs here - let React unmounting clean it up via handleSheetRef
|
|
82
|
+
sheetLog('[GlobalSheetView.handleSheetDismiss] after cleanup', {
|
|
83
|
+
name,
|
|
84
|
+
totalSheets: sheets.size,
|
|
85
|
+
totalRefs: sheetRefs.size,
|
|
86
|
+
});
|
|
87
|
+
forceUpdate?.();
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
// Memoized sheet component to avoid unnecessary re-renders
|
|
91
|
+
const GlobalSheetItem = memo<{
|
|
92
|
+
name: string;
|
|
93
|
+
defaultProps: SheetProps | undefined;
|
|
94
|
+
}>(
|
|
95
|
+
({ name, defaultProps }) => {
|
|
96
|
+
sheetLog('[GlobalSheetItem] render', { name });
|
|
97
|
+
const dataToRender = sheets.get(name);
|
|
98
|
+
if (!dataToRender) {
|
|
99
|
+
sheetLog('[GlobalSheetItem] no data, returning null', { name });
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return (
|
|
104
|
+
<FittedSheet
|
|
105
|
+
ref={(ref) => handleSheetRef(name, ref)}
|
|
106
|
+
name={name}
|
|
107
|
+
params={dataToRender.sheetProps?.params ?? defaultProps?.params}
|
|
108
|
+
rootViewStyle={
|
|
109
|
+
dataToRender.sheetProps?.rootViewStyle ?? defaultProps?.rootViewStyle
|
|
110
|
+
}
|
|
111
|
+
onSheetDismiss={() => handleSheetDismiss(name)}
|
|
112
|
+
children={dataToRender?.children}
|
|
113
|
+
/>
|
|
114
|
+
);
|
|
115
|
+
},
|
|
116
|
+
(prevProps, nextProps) => {
|
|
117
|
+
// Custom comparison to log when memo blocks re-renders
|
|
118
|
+
const shouldSkip =
|
|
119
|
+
prevProps.name === nextProps.name &&
|
|
120
|
+
prevProps.defaultProps === nextProps.defaultProps;
|
|
121
|
+
sheetLog('[GlobalSheetItem] memo check', {
|
|
122
|
+
name: prevProps.name,
|
|
123
|
+
shouldSkip,
|
|
124
|
+
propsChanged: !shouldSkip,
|
|
125
|
+
});
|
|
126
|
+
return shouldSkip;
|
|
127
|
+
}
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
export const GlobalSheetView: React.FC<Props> = memo((props) => {
|
|
131
|
+
const [tick, setTick] = useState(0);
|
|
132
|
+
sheetLog('[GlobalSheetView] render', {
|
|
133
|
+
tick,
|
|
134
|
+
totalSheets: sheets.size,
|
|
135
|
+
totalRefs: sheetRefs.size,
|
|
136
|
+
sheetNames: Array.from(sheets.keys()),
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
useEffect(() => {
|
|
140
|
+
sheetLog('[GlobalSheetView] mounted - initializing global functions');
|
|
141
|
+
|
|
142
|
+
forceUpdate = () => {
|
|
143
|
+
sheetLog('[GlobalSheetView.forceUpdate] triggering re-render');
|
|
144
|
+
setTick((t) => t + 1);
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
presentGlobalSheet = (params) => {
|
|
148
|
+
sheetLog('[GlobalSheetView.presentGlobalSheet]', {
|
|
149
|
+
name: params.name,
|
|
150
|
+
beforeAdd: sheets.size,
|
|
151
|
+
});
|
|
152
|
+
sheets.set(params.name, params);
|
|
153
|
+
sheetLog('[GlobalSheetView.presentGlobalSheet] after add', {
|
|
154
|
+
name: params.name,
|
|
155
|
+
afterAdd: sheets.size,
|
|
156
|
+
});
|
|
157
|
+
forceUpdate();
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
dismissGlobalSheet = (name) => {
|
|
161
|
+
sheetLog('[GlobalSheetView.dismissGlobalSheet]', {
|
|
162
|
+
name,
|
|
163
|
+
beforeDelete: sheets.size,
|
|
164
|
+
});
|
|
165
|
+
sheets.delete(name);
|
|
166
|
+
sheetRefs.delete(name); // Also clean up ref to prevent memory leak
|
|
167
|
+
sheetLog('[GlobalSheetView.dismissGlobalSheet] after delete', {
|
|
168
|
+
name,
|
|
169
|
+
afterDelete: sheets.size,
|
|
170
|
+
});
|
|
171
|
+
forceUpdate();
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
return () => {
|
|
175
|
+
sheetLog('[GlobalSheetView] unmounting - cleaning up', {
|
|
176
|
+
sheetsToClean: sheets.size,
|
|
177
|
+
refsToClean: sheetRefs.size,
|
|
178
|
+
});
|
|
179
|
+
// Clean up all sheets and refs to prevent memory leaks
|
|
180
|
+
sheets.clear();
|
|
181
|
+
sheetRefs.clear();
|
|
182
|
+
|
|
183
|
+
// Reset functions to no-op
|
|
184
|
+
presentGlobalSheet = () => {
|
|
185
|
+
sheetWarn('[GlobalSheetView] presentGlobalSheet called after unmount!');
|
|
186
|
+
};
|
|
187
|
+
dismissGlobalSheet = () => {
|
|
188
|
+
sheetWarn('[GlobalSheetView] dismissGlobalSheet called after unmount!');
|
|
189
|
+
};
|
|
190
|
+
forceUpdate = () => {};
|
|
191
|
+
|
|
192
|
+
sheetLog('[GlobalSheetView] cleanup complete');
|
|
193
|
+
};
|
|
194
|
+
}, []);
|
|
195
|
+
|
|
196
|
+
if (sheets.size === 0) {
|
|
197
|
+
sheetLog('[GlobalSheetView] rendering null (no sheets)');
|
|
198
|
+
return null;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
sheetLog('[GlobalSheetView] rendering sheets', Array.from(sheets.keys()));
|
|
202
|
+
return (
|
|
203
|
+
<>
|
|
204
|
+
{Array.from(sheets.keys()).map((name) => (
|
|
205
|
+
<GlobalSheetItem key={name} name={name} defaultProps={props.props} />
|
|
206
|
+
))}
|
|
207
|
+
</>
|
|
208
|
+
);
|
|
209
|
+
});
|
package/src/NativeSheet.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { type TurboModule, TurboModuleRegistry } from 'react-native';
|
|
|
2
2
|
import type {
|
|
3
3
|
Double,
|
|
4
4
|
UnsafeObject,
|
|
5
|
+
//@ts-ignore
|
|
5
6
|
} from 'react-native/Libraries/Types/CodegenTypes';
|
|
6
7
|
|
|
7
8
|
export interface Spec extends TurboModule {
|
|
@@ -10,8 +11,11 @@ export interface Spec extends TurboModule {
|
|
|
10
11
|
};
|
|
11
12
|
|
|
12
13
|
viewportSize(): { width: Double; height: Double };
|
|
14
|
+
setLogsEnabled(enabled: boolean): void;
|
|
13
15
|
dismissAll(): void;
|
|
14
16
|
dismissPresented(): void;
|
|
17
|
+
/** Last native view-tree moves this library made — see SheetTreeLog. */
|
|
18
|
+
getTreeLog(): string[];
|
|
15
19
|
}
|
|
16
20
|
|
|
17
21
|
export default TurboModuleRegistry.getEnforcing<Spec>('Sheet');
|
package/src/PublicSheetView.tsx
CHANGED
|
@@ -6,6 +6,7 @@ import React, {
|
|
|
6
6
|
useRef,
|
|
7
7
|
} from 'react';
|
|
8
8
|
import { PrivateFittedSheet, type SheetProps } from './FittedSheet';
|
|
9
|
+
import { sheetWarn } from './logger';
|
|
9
10
|
|
|
10
11
|
const handles: {
|
|
11
12
|
[name: string]: React.RefObject<PrivateFittedSheet | null>;
|
|
@@ -52,7 +53,7 @@ export const PublicSheetView = memo(
|
|
|
52
53
|
useEffect(() => {
|
|
53
54
|
if (props.name) {
|
|
54
55
|
if (handles[props.name])
|
|
55
|
-
|
|
56
|
+
sheetWarn(`Sheet with name ${props.name} exists`);
|
|
56
57
|
handles[props.name] = sheetRef;
|
|
57
58
|
}
|
|
58
59
|
return () => {
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { DeviceEventEmitter, type EmitterSubscription } from 'react-native';
|
|
2
|
+
|
|
3
|
+
import SheetModule from './NativeSheet';
|
|
4
|
+
|
|
5
|
+
const EVENT = 'sheet2:tree';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Native view-tree operations this library performs on views React Native
|
|
9
|
+
* believes it owns: presenting and dismissing a sheet moves them between
|
|
10
|
+
* containers, and an overlay child never reaches the host view at all.
|
|
11
|
+
*
|
|
12
|
+
* The mounting crashes those operations can end in name nothing of ours — the
|
|
13
|
+
* Android one is "addViewAt: failed to insert view [child] into parent [parent]
|
|
14
|
+
* at index N" with a stack made of React Native and framework frames. Each entry
|
|
15
|
+
* here names the views by the id React Native uses as the tag, so an app that
|
|
16
|
+
* turns these into breadcrumbs can answer, from the crash report alone, whether
|
|
17
|
+
* a sheet had touched the views in question.
|
|
18
|
+
*
|
|
19
|
+
* Android only for now; the iOS side is not wired yet.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* addSheetTreeListener(entry =>
|
|
23
|
+
* Sentry.addBreadcrumb({ category: 'sheet2', message: entry, level: 'info' }),
|
|
24
|
+
* )
|
|
25
|
+
*/
|
|
26
|
+
export function addSheetTreeListener(
|
|
27
|
+
handler: (entry: string) => void
|
|
28
|
+
): EmitterSubscription {
|
|
29
|
+
return DeviceEventEmitter.addListener(EVENT, handler);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The last native view-tree moves, newest last (32 are kept). iOS has no event
|
|
34
|
+
* channel yet, so this is how the trail is read there — for a report attached by
|
|
35
|
+
* hand, or from a debug screen.
|
|
36
|
+
*/
|
|
37
|
+
export function getSheetTreeLog(): string[] {
|
|
38
|
+
return SheetModule.getTreeLog();
|
|
39
|
+
}
|
|
@@ -1,10 +1,16 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
type ColorValue,
|
|
3
|
+
type HostComponent,
|
|
4
|
+
type ViewProps,
|
|
5
|
+
codegenNativeComponent,
|
|
6
|
+
codegenNativeCommands,
|
|
7
|
+
} from 'react-native';
|
|
3
8
|
import type {
|
|
4
9
|
DirectEventHandler,
|
|
5
10
|
Double,
|
|
11
|
+
//@ts-ignore
|
|
6
12
|
} from 'react-native/Libraries/Types/CodegenTypes';
|
|
7
|
-
import
|
|
13
|
+
import React from 'react';
|
|
8
14
|
|
|
9
15
|
interface NativeProps extends ViewProps {
|
|
10
16
|
dismissable: boolean;
|
|
@@ -15,11 +21,26 @@ interface NativeProps extends ViewProps {
|
|
|
15
21
|
topLeftRightCornerRadius?: Double;
|
|
16
22
|
isSystemUILight: boolean;
|
|
17
23
|
passScrollViewReactTag?: string;
|
|
24
|
+
uniqueId: string;
|
|
18
25
|
sheetBackgroundColor?: ColorValue;
|
|
26
|
+
windowLevel?: string;
|
|
27
|
+
useInlinePresentation?: boolean;
|
|
28
|
+
presentationStyle?: string;
|
|
29
|
+
centerAnimation?: string;
|
|
30
|
+
dismissOnOverlayTap?: boolean;
|
|
31
|
+
overlayOpacity?: Double;
|
|
32
|
+
collapsedHeight?: Double;
|
|
19
33
|
onSheetDismiss: DirectEventHandler<null>;
|
|
20
34
|
}
|
|
21
35
|
|
|
22
|
-
|
|
36
|
+
// `interfaceOnly: true` tells codegen NOT to emit a default
|
|
37
|
+
// `SheetViewShadowNode` typedef / ComponentDescriptor. The library provides
|
|
38
|
+
// those itself in `android/src/main/cpp/` so that the custom shadow node can
|
|
39
|
+
// override `getContentOriginOffset` (needed to keep Pressability coords in
|
|
40
|
+
// sync when the Android host view is re-parented for inline presentation).
|
|
41
|
+
export default codegenNativeComponent<NativeProps>('SheetView', {
|
|
42
|
+
interfaceOnly: true,
|
|
43
|
+
});
|
|
23
44
|
|
|
24
45
|
type MyNativeViewType = HostComponent<NativeProps>;
|
|
25
46
|
export interface NativeCommands {
|