react-native-sheet2 1.2.6 → 6.1.18

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.
Files changed (117) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +51 -32
  3. package/{react-native-sheet.podspec → Sheet.podspec} +7 -6
  4. package/android/build.gradle +43 -25
  5. package/android/generated/java/com/facebook/react/viewmanagers/SheetViewManagerDelegate.java +67 -0
  6. package/android/generated/java/com/facebook/react/viewmanagers/SheetViewManagerInterface.java +27 -0
  7. package/android/generated/java/com/sheet/NativeSheetSpec.java +78 -0
  8. package/android/generated/jni/CMakeLists.txt +36 -0
  9. package/android/generated/jni/RNSheetViewSpec-generated.cpp +50 -0
  10. package/android/generated/jni/RNSheetViewSpec.h +31 -0
  11. package/android/generated/jni/react/renderer/components/RNSheetViewSpec/ComponentDescriptors.cpp +22 -0
  12. package/android/generated/jni/react/renderer/components/RNSheetViewSpec/ComponentDescriptors.h +24 -0
  13. package/android/generated/jni/react/renderer/components/RNSheetViewSpec/EventEmitters.cpp +24 -0
  14. package/android/generated/jni/react/renderer/components/RNSheetViewSpec/EventEmitters.h +25 -0
  15. package/android/generated/jni/react/renderer/components/RNSheetViewSpec/Props.cpp +33 -0
  16. package/android/generated/jni/react/renderer/components/RNSheetViewSpec/Props.h +36 -0
  17. package/android/generated/jni/react/renderer/components/RNSheetViewSpec/RNSheetViewSpecJSI-generated.cpp +46 -0
  18. package/android/generated/jni/react/renderer/components/RNSheetViewSpec/RNSheetViewSpecJSI.h +98 -0
  19. package/android/generated/jni/react/renderer/components/RNSheetViewSpec/ShadowNodes.cpp +17 -0
  20. package/android/generated/jni/react/renderer/components/RNSheetViewSpec/ShadowNodes.h +32 -0
  21. package/android/generated/jni/react/renderer/components/RNSheetViewSpec/States.cpp +16 -0
  22. package/android/generated/jni/react/renderer/components/RNSheetViewSpec/States.h +29 -0
  23. package/android/gradle.properties +4 -5
  24. package/android/src/main/AndroidManifest.xml +0 -9
  25. package/android/src/main/AndroidManifestNew.xml +2 -0
  26. package/android/src/main/java/com/behavior/BottomSheetBehavior.java +10 -17
  27. package/android/src/main/java/com/sheet/AppFittedSheet.kt +107 -39
  28. package/android/src/main/java/com/sheet/BaseRNView.kt +81 -33
  29. package/android/src/main/java/com/sheet/CustomBottomSheetDialog.java +8 -0
  30. package/android/src/main/java/com/sheet/DialogRootViewGroup.kt +44 -33
  31. package/android/src/main/java/com/sheet/FragmentModalBottomSheet.kt +12 -2
  32. package/android/src/main/java/com/sheet/SafeAreaUtils.kt +90 -0
  33. package/android/src/main/java/com/sheet/SheetDismissEvent.kt +20 -0
  34. package/android/src/main/java/com/sheet/SheetModule.kt +37 -0
  35. package/android/src/main/java/com/sheet/SheetPackage.kt +32 -6
  36. package/android/src/main/java/com/sheet/SheetView.kt +5 -0
  37. package/android/src/main/java/com/sheet/SheetViewManager.kt +77 -56
  38. package/android/src/main/java/com/sheet/utils.kt +2 -10
  39. package/android/src/main/res/layout/dialog_bottom_sheet.xml +2 -2
  40. package/android/src/main/res/values/styles.xml +9 -0
  41. package/ios/FittedSheets/SheetContentViewController.swift +4 -4
  42. package/ios/FittedSheets/SheetViewController.swift +29 -100
  43. package/ios/HostFittedSheet.swift +271 -0
  44. package/ios/Sheet-Bridging-Header.h +1 -0
  45. package/ios/SheetModule.h +10 -0
  46. package/ios/SheetModule.mm +67 -0
  47. package/ios/SheetView.h +14 -0
  48. package/ios/SheetView.mm +129 -0
  49. package/ios/generated/RNSheetViewSpec/ComponentDescriptors.cpp +22 -0
  50. package/ios/generated/RNSheetViewSpec/ComponentDescriptors.h +24 -0
  51. package/ios/generated/RNSheetViewSpec/EventEmitters.cpp +24 -0
  52. package/ios/generated/RNSheetViewSpec/EventEmitters.h +25 -0
  53. package/ios/generated/RNSheetViewSpec/Props.cpp +33 -0
  54. package/ios/generated/RNSheetViewSpec/Props.h +36 -0
  55. package/ios/generated/RNSheetViewSpec/RCTComponentViewHelpers.h +44 -0
  56. package/ios/generated/RNSheetViewSpec/RNSheetViewSpec-generated.mm +60 -0
  57. package/ios/generated/RNSheetViewSpec/RNSheetViewSpec.h +100 -0
  58. package/ios/generated/RNSheetViewSpec/ShadowNodes.cpp +17 -0
  59. package/ios/generated/RNSheetViewSpec/ShadowNodes.h +32 -0
  60. package/ios/generated/RNSheetViewSpec/States.cpp +16 -0
  61. package/ios/generated/RNSheetViewSpec/States.h +29 -0
  62. package/ios/generated/RNSheetViewSpecJSI-generated.cpp +46 -0
  63. package/ios/generated/RNSheetViewSpecJSI.h +98 -0
  64. package/lib/module/FittedSheet.js +153 -0
  65. package/lib/module/FittedSheet.js.map +1 -0
  66. package/lib/module/NativeSheet.ts +17 -0
  67. package/lib/module/PublicSheetView.js +48 -0
  68. package/lib/module/PublicSheetView.js.map +1 -0
  69. package/lib/module/SheetViewNativeComponent.ts +31 -0
  70. package/lib/module/index.js +13 -0
  71. package/lib/module/index.js.map +1 -0
  72. package/lib/module/package.json +1 -0
  73. package/lib/typescript/package.json +1 -0
  74. package/lib/typescript/src/FittedSheet.d.ts +51 -0
  75. package/lib/typescript/src/FittedSheet.d.ts.map +1 -0
  76. package/lib/typescript/src/NativeSheet.d.ts +16 -0
  77. package/lib/typescript/src/NativeSheet.d.ts.map +1 -0
  78. package/lib/typescript/src/PublicSheetView.d.ts +12 -0
  79. package/lib/typescript/src/PublicSheetView.d.ts.map +1 -0
  80. package/lib/typescript/src/SheetViewNativeComponent.d.ts +22 -0
  81. package/lib/typescript/src/SheetViewNativeComponent.d.ts.map +1 -0
  82. package/lib/typescript/src/index.d.ts +8 -0
  83. package/lib/typescript/src/index.d.ts.map +1 -0
  84. package/package.json +109 -42
  85. package/react-native.config.js +12 -0
  86. package/src/FittedSheet.tsx +118 -95
  87. package/src/NativeSheet.ts +17 -0
  88. package/src/PublicSheetView.tsx +66 -0
  89. package/src/SheetViewNativeComponent.ts +31 -0
  90. package/src/index.tsx +26 -8
  91. package/android/src/main/java/com/modal/FullScreenDialog.kt +0 -100
  92. package/android/src/main/java/com/modal/TopModalView.kt +0 -77
  93. package/android/src/main/java/com/modal/TopModalViewManager.kt +0 -83
  94. package/android/src/main/java/com/modal/TopModalViewModule.kt +0 -40
  95. package/android/src/main/java/com/sheet/SheetViewModule.kt +0 -41
  96. package/ios/LBBottomSheet/BottomSheetConstant.swift +0 -48
  97. package/ios/LBBottomSheet/Model/BottomSheetController+Behavior.swift +0 -262
  98. package/ios/LBBottomSheet/Model/BottomSheetController+Theme.swift +0 -156
  99. package/ios/LBBottomSheet/Protocols/BottomSheetInteractionDelegate.swift +0 -29
  100. package/ios/LBBottomSheet/Protocols/BottomSheetPositionDelegate.swift +0 -31
  101. package/ios/LBBottomSheet/UI/BottomSheet.storyboard +0 -105
  102. package/ios/LBBottomSheet/UI/BottomSheetController.swift +0 -601
  103. package/ios/LBBottomSheet/Utils/Components/ForwardingEventsView.swift +0 -60
  104. package/ios/LBBottomSheet/Utils/Extensions/CACornerMask+Extension.swift +0 -33
  105. package/ios/LBBottomSheet/Utils/Extensions/Mirror+Extension.swift +0 -47
  106. package/ios/LBBottomSheet/Utils/Extensions/UIApplication+Extension.swift +0 -35
  107. package/ios/LBBottomSheet/Utils/Extensions/UIColor+Extension.swift +0 -61
  108. package/ios/LBBottomSheet/Utils/Extensions/UIGestureRecognizer+Extensions.swift +0 -28
  109. package/ios/LBBottomSheet/Utils/Extensions/UIScreen+Extension.swift +0 -28
  110. package/ios/LBBottomSheet/Utils/Extensions/UIScrollView+Extension.swift +0 -25
  111. package/ios/LBBottomSheet/Utils/Extensions/UIView+Extension.swift +0 -52
  112. package/ios/LBBottomSheet/Utils/Extensions/UIViewController+Extension.swift +0 -104
  113. package/ios/Sheet.xcodeproj/project.pbxproj +0 -377
  114. package/ios/SheetViewManager.m +0 -25
  115. package/ios/SheetViewManager.swift +0 -324
  116. package/ios/TopModalViewManager.swift +0 -196
  117. package/src/TopModal.tsx +0 -94
@@ -1,16 +1,17 @@
1
- import React, { createContext, useContext } from 'react';
1
+ import React from 'react';
2
2
  import {
3
3
  Dimensions,
4
- findNodeHandle,
5
4
  type LayoutChangeEvent,
6
- NativeModules,
7
- processColor,
8
- requireNativeComponent,
5
+ Platform,
9
6
  StatusBar,
10
7
  View,
11
8
  } from 'react-native';
12
9
 
13
- export const _FittedSheet = requireNativeComponent<any>('SheetView');
10
+ import She, { Commands } from './SheetViewNativeComponent';
11
+ import SheetModule from './NativeSheet';
12
+ import { Portal } from '@gorhom/portal';
13
+
14
+ const _FittedSheet = She;
14
15
 
15
16
  export interface FittedSheetParams {
16
17
  readonly applyMaxHeightToMinHeight?: boolean;
@@ -32,7 +33,7 @@ type Children =
32
33
  | React.ReactElement
33
34
  | React.ReactElement[];
34
35
 
35
- interface Props {
36
+ export interface SheetProps {
36
37
  readonly params?: FittedSheetParams;
37
38
  readonly onSheetDismiss?: (passThroughParam?: any) => void;
38
39
  readonly children?: Children;
@@ -41,146 +42,168 @@ interface Props {
41
42
  interface State {
42
43
  show: boolean;
43
44
  data: any | null;
44
- maxHeight: number;
45
+ height?: number;
46
+ passScrollViewReactTag?: string;
47
+ isLandscape: boolean;
45
48
  }
46
49
 
47
- export const FITTED_SHEET_SCROLL_VIEW = 'fittedSheetScrollView';
48
-
49
- interface Context {
50
- hide: (passThroughParam?: any) => void;
51
- increaseHeight: (by: number) => void;
52
- decreaseHeight: (by: number) => void;
53
- passScrollViewReactTag: (nativeId: string) => void;
54
- }
55
-
56
- const FittedSheetContext = createContext<Context | null>(null);
57
-
58
- export const useFittedSheetContext = () => {
59
- try {
60
- return useContext(FittedSheetContext);
61
- } catch {
62
- return undefined;
63
- }
64
- };
65
-
66
- export class FittedSheet extends React.PureComponent<Props, State> {
50
+ export class PrivateFittedSheet extends React.PureComponent<SheetProps, State> {
67
51
  private cleanup?: () => void;
68
- private shouldShowBack = false;
69
52
  private onHidePassThroughParam?: any;
70
53
  private sheetRef = React.createRef<any>();
71
- constructor(props: Props) {
54
+
55
+ private dimensions: { width: number; height: number };
56
+
57
+ constructor(props: SheetProps) {
72
58
  super(props);
73
- this.state = { show: false, data: null, maxHeight: -1 };
59
+ this.dimensions = this.viewportSize();
60
+
61
+ this.state = {
62
+ show: false,
63
+ data: null,
64
+ isLandscape: this.dimensions.width > this.dimensions.height,
65
+ };
74
66
  }
75
67
 
76
68
  show = (data?: any) => {
77
69
  this.setState({ show: true, data });
78
70
  };
79
71
 
80
- data = () => this.state.data;
81
-
82
72
  onLayout = (e: LayoutChangeEvent) => {
83
- this.setState({ maxHeight: e.nativeEvent.layout.height });
73
+ if (__DEV__)
74
+ console.log('[FittedSheet.onLayout]', e.nativeEvent.layout.height);
75
+ this.setState({ height: e.nativeEvent.layout.height });
84
76
  };
85
77
 
86
- toggle = () => {
87
- this.setState({ show: !this.state.show });
78
+ attachScrollViewToSheet = () => {
79
+ console.log('[FittedSheet.attachScrollViewToSheet]');
80
+ this.setState({ passScrollViewReactTag: Date.now().toString() });
88
81
  };
89
82
 
90
- passScrollViewReactTag = (nativeId: string) => {
91
- console.log('🍓[FittedSheet.passScrollViewReactTag]', nativeId);
92
- this.sheetRef.current?.setNativeProps({ passScrollViewReactTag: nativeId });
83
+ hide = (passThroughParam?: any) => {
84
+ if (!this.state.show) return;
85
+ this.onHidePassThroughParam = passThroughParam;
86
+ console.log('[FittedSheet.hide]', Commands.dismissSheet);
87
+ Commands.dismissSheet(this.sheetRef.current);
93
88
  };
94
89
 
95
- increaseHeight = (by: number) => {
96
- //this.sheetRef.current?.setNativeProps({ increaseHeight: by });
97
- this.setState({ maxHeight: this.state.maxHeight + by });
90
+ static dismissAll = () => {
91
+ SheetModule.dismissAll();
98
92
  };
99
93
 
100
- decreaseHeight = (by: number) => {
101
- const minHeight = this.props.params?.minHeight;
102
- this.setState({
103
- maxHeight: Math.max(minHeight ?? 0, this.state.maxHeight - by),
104
- });
105
- //this.sheetRef.current?.setNativeProps({ decreaseHeight: by });
106
- };
107
-
108
- hide = (passThroughParam?: any) => {
109
- if (!this.state.show) return;
110
- this.onHidePassThroughParam = passThroughParam;
111
- const tag = findNodeHandle(this.sheetRef.current);
112
- if (!tag) return;
113
- NativeModules.SheetView.dismiss(tag);
94
+ static dismissPresented = () => {
95
+ SheetModule.dismissPresented();
114
96
  };
115
97
 
98
+ // @ts-ignore
116
99
  private onDismiss = () => {
117
- if (this.shouldShowBack) {
118
- this.setState({ show: false }, () => this.show(this.state.data));
119
- this.shouldShowBack = false;
120
- return;
121
- }
122
- this.setState({ show: false });
100
+ if (__DEV__) console.log('[FittedSheet.onDismiss]');
101
+ this.setState({ show: false, height: undefined });
123
102
  const passValue = this.onHidePassThroughParam;
124
103
  this.onHidePassThroughParam = undefined;
125
104
  this.props.onSheetDismiss?.(passValue);
126
105
  };
127
106
 
107
+ private insets(): { top: number; bottom: number } {
108
+ return (SheetModule.getConstants().insets as any) ?? { top: 0, bottom: 0 };
109
+ }
110
+
128
111
  componentDidMount() {
112
+ if (__DEV__) console.log('[FittedSheet.componentDidMount]', this.insets());
129
113
  this.cleanup = Dimensions.addEventListener('change', () => {
130
- if (!this.state.show) return;
131
- if (this.shouldShowBack) return;
132
- this.shouldShowBack = true;
133
- this.hide();
114
+ this.dimensions = this.viewportSize();
115
+ const isLandscape = this.dimensions.width > this.dimensions.height;
116
+ this.setState({ isLandscape });
134
117
  }).remove;
135
118
  }
136
119
 
137
120
  componentWillUnmount() {
121
+ if (__DEV__) console.log('[FittedSheet.componentWillUnmount]');
138
122
  this.hide();
139
123
  this.cleanup?.();
140
124
  this.cleanup = undefined;
141
125
  }
142
126
 
143
- render() {
144
- if (!this.state.show) return null;
127
+ private viewportSize(): { width: number; height: number } {
128
+ if (Platform.OS === 'ios') {
129
+ return SheetModule.viewportSize();
130
+ }
131
+ return Dimensions.get('window');
132
+ }
145
133
 
146
- const dim = Dimensions.get('screen');
147
- const isLandscape = dim.width > dim.height;
134
+ private _shouldSetResponder(): boolean {
135
+ return true;
136
+ }
148
137
 
138
+ render() {
139
+ if (!this.state.show) return null;
149
140
  let maxHeight = Math.min(
150
141
  this.props.params?.maxHeight ?? Number.MAX_VALUE,
151
- dim.height - (StatusBar.currentHeight ?? 0)
142
+ this.dimensions.height - this.insets().top - this.insets().bottom
152
143
  );
153
-
154
- const paramsMaxWidth = isLandscape
144
+ const paramsMaxWidth = this.state.isLandscape
155
145
  ? this.props.params?.maxLandscapeWidth
156
146
  : this.props.params?.maxPortraitWidth;
157
- let maxWidth = Math.min(paramsMaxWidth ?? Number.MAX_VALUE, dim.width);
147
+ let maxWidth = Math.min(
148
+ paramsMaxWidth ?? Number.MAX_VALUE,
149
+ this.dimensions.width
150
+ );
158
151
  let minHeight = this.props.params?.minHeight;
159
152
  if (this.props.params?.applyMaxHeightToMinHeight) {
160
153
  minHeight = maxHeight;
161
154
  }
155
+
156
+ let nativeHeight = this.state.height;
157
+ if (nativeHeight) {
158
+ nativeHeight = Math.max(nativeHeight ?? 0, minHeight ?? 0);
159
+ nativeHeight = Math.min(nativeHeight, maxHeight);
160
+ }
161
+
162
+ if (__DEV__) {
163
+ console.log(
164
+ '[FittedSheet.render]',
165
+ JSON.stringify(
166
+ {
167
+ maxHeight,
168
+ maxWidth,
169
+ nativeHeight,
170
+ isLandscape: this.state.isLandscape,
171
+ h: Dimensions.get('window').height,
172
+ sb: StatusBar.currentHeight,
173
+ dimensions: this.dimensions,
174
+ },
175
+ undefined,
176
+ 2
177
+ )
178
+ );
179
+ }
180
+ const background = this.props?.params?.backgroundColor;
162
181
  return (
163
- <_FittedSheet
164
- onSheetDismiss={this.onDismiss}
165
- ref={this.sheetRef}
166
- style={{ width: maxWidth, maxHeight, minHeight, position: 'absolute' }}
167
- fittedSheetParams={
168
- this.props.params
169
- ? {
170
- ...this.props.params,
171
- maxHeight,
172
- maxWidth,
173
- backgroundColor: this.props.params.backgroundColor
174
- ? processColor(this.props.params.backgroundColor)
175
- : undefined,
176
- }
177
- : {}
178
- }
179
- >
180
- <FittedSheetContext.Provider value={this}>
182
+ <Portal hostName={'SheetHost'}>
183
+ <_FittedSheet
184
+ onSheetDismiss={this.onDismiss}
185
+ ref={this.sheetRef}
186
+ onStartShouldSetResponder={this._shouldSetResponder}
187
+ style={{ width: maxWidth, position: 'absolute' }}
188
+ dismissable={this.props.params?.dismissable ?? true}
189
+ maxWidth={maxWidth}
190
+ maxHeight={maxHeight}
191
+ sheetBackgroundColor={background}
192
+ minHeight={minHeight}
193
+ topLeftRightCornerRadius={
194
+ this.props.params?.topLeftRightCornerRadius ?? 20
195
+ }
196
+ isSystemUILight={this.props.params?.isSystemUILight ?? true}
197
+ calculatedHeight={nativeHeight}
198
+ passScrollViewReactTag={this.state.passScrollViewReactTag}
199
+ >
181
200
  <View
182
201
  nativeID={'fitted-sheet-root-view'}
183
- style={{ maxHeight, minHeight, maxWidth }}
202
+ style={{
203
+ width: maxWidth,
204
+ maxHeight,
205
+ backgroundColor: background,
206
+ }}
184
207
  onLayout={this.onLayout}
185
208
  >
186
209
  {this.props.children &&
@@ -190,8 +213,8 @@ export class FittedSheet extends React.PureComponent<Props, State> {
190
213
  typeof this.props.children !== 'function' &&
191
214
  this.props.children}
192
215
  </View>
193
- </FittedSheetContext.Provider>
194
- </_FittedSheet>
216
+ </_FittedSheet>
217
+ </Portal>
195
218
  );
196
219
  }
197
220
  }
@@ -0,0 +1,17 @@
1
+ import { type TurboModule, TurboModuleRegistry } from 'react-native';
2
+ import type {
3
+ Double,
4
+ UnsafeObject,
5
+ } from 'react-native/Libraries/Types/CodegenTypes';
6
+
7
+ export interface Spec extends TurboModule {
8
+ getConstants: () => {
9
+ insets: UnsafeObject;
10
+ };
11
+
12
+ viewportSize(): { width: Double; height: Double };
13
+ dismissAll(): void;
14
+ dismissPresented(): void;
15
+ }
16
+
17
+ export default TurboModuleRegistry.getEnforcing<Spec>('Sheet');
@@ -0,0 +1,66 @@
1
+ import React, {
2
+ forwardRef,
3
+ memo,
4
+ useEffect,
5
+ useImperativeHandle,
6
+ useRef,
7
+ } from 'react';
8
+ import { PrivateFittedSheet, type SheetProps } from './FittedSheet';
9
+
10
+ const handles: {
11
+ [name: string]: React.RefObject<PrivateFittedSheet | null>;
12
+ } = {};
13
+ export function presentFittedSheet(name: string, data?: any): boolean {
14
+ if (!handles[name]) return false;
15
+ handles[name]?.current?.show(data);
16
+ return true;
17
+ }
18
+
19
+ export function attachScrollViewToFittedSheet(name: string): boolean {
20
+ if (!handles[name]) return false;
21
+ handles[name]?.current?.attachScrollViewToSheet();
22
+ return true;
23
+ }
24
+
25
+ export function dismissFittedSheet(name: string): boolean {
26
+ if (!handles[name]) return false;
27
+ handles[name]?.current?.hide();
28
+ return true;
29
+ }
30
+
31
+ export function dismissFittedSheetsAll(): boolean {
32
+ PrivateFittedSheet.dismissAll();
33
+ return true;
34
+ }
35
+
36
+ export function dismissFittedPresented(): boolean {
37
+ PrivateFittedSheet.dismissPresented();
38
+ return true;
39
+ }
40
+
41
+ type Props = SheetProps & { name?: string };
42
+ export type FittedSheetRef = Pick<
43
+ PrivateFittedSheet,
44
+ 'show' | 'hide' | 'attachScrollViewToSheet'
45
+ >;
46
+ export const PublicSheetView = memo(
47
+ forwardRef<FittedSheetRef, Props>((props, ref) => {
48
+ const sheetRef = useRef<PrivateFittedSheet>(null);
49
+
50
+ useImperativeHandle(ref, () => sheetRef.current!, []);
51
+
52
+ useEffect(() => {
53
+ if (props.name) {
54
+ if (handles[props.name])
55
+ console.warn(`Sheet with name ${props.name} exists`);
56
+ handles[props.name] = sheetRef;
57
+ }
58
+ return () => {
59
+ if (!props.name) return;
60
+ delete handles[props.name];
61
+ };
62
+ }, [props.name]);
63
+
64
+ return <PrivateFittedSheet ref={sheetRef} {...props} />;
65
+ })
66
+ );
@@ -0,0 +1,31 @@
1
+ import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';
2
+ import type { ColorValue, HostComponent, ViewProps } from 'react-native';
3
+ import type {
4
+ DirectEventHandler,
5
+ Double,
6
+ } from 'react-native/Libraries/Types/CodegenTypes';
7
+ import codegenNativeCommands from 'react-native/Libraries/Utilities/codegenNativeCommands';
8
+
9
+ interface NativeProps extends ViewProps {
10
+ dismissable: boolean;
11
+ maxWidth?: Double;
12
+ maxHeight?: Double;
13
+ minHeight?: Double;
14
+ calculatedHeight?: Double;
15
+ topLeftRightCornerRadius?: Double;
16
+ isSystemUILight: boolean;
17
+ passScrollViewReactTag?: string;
18
+ sheetBackgroundColor?: ColorValue;
19
+ onSheetDismiss: DirectEventHandler<null>;
20
+ }
21
+
22
+ export default codegenNativeComponent<NativeProps>('SheetView');
23
+
24
+ type MyNativeViewType = HostComponent<NativeProps>;
25
+ export interface NativeCommands {
26
+ dismissSheet: (viewRef: React.ElementRef<MyNativeViewType>) => void;
27
+ }
28
+
29
+ export const Commands = codegenNativeCommands<NativeCommands>({
30
+ supportedCommands: ['dismissSheet'],
31
+ });
package/src/index.tsx CHANGED
@@ -1,12 +1,30 @@
1
+ import type { FittedSheetParams } from './FittedSheet';
1
2
  import {
2
- FITTED_SHEET_SCROLL_VIEW,
3
- FittedSheet,
4
- useFittedSheetContext,
5
- FittedSheetParams,
6
- } from './FittedSheet';
3
+ attachScrollViewToFittedSheet,
4
+ dismissFittedSheet,
5
+ type FittedSheetRef,
6
+ presentFittedSheet,
7
+ PublicSheetView,
8
+ dismissFittedSheetsAll,
9
+ dismissFittedPresented,
10
+ } from './PublicSheetView';
7
11
 
8
- export { FittedSheet, FITTED_SHEET_SCROLL_VIEW, useFittedSheetContext };
12
+ import { PortalProvider } from '@gorhom/portal';
13
+ import type { ReactNode } from 'react';
9
14
 
10
- export type { FittedSheetParams };
15
+ export function SheetProvider(props: { children: ReactNode }) {
16
+ return (
17
+ <PortalProvider rootHostName={'SheetHost'}>{props.children}</PortalProvider>
18
+ );
19
+ }
11
20
 
12
- export { TopModal } from './TopModal';
21
+ export {
22
+ PublicSheetView as FittedSheet,
23
+ type FittedSheetRef,
24
+ presentFittedSheet,
25
+ dismissFittedSheet,
26
+ dismissFittedSheetsAll,
27
+ dismissFittedPresented,
28
+ attachScrollViewToFittedSheet,
29
+ type FittedSheetParams,
30
+ };
@@ -1,100 +0,0 @@
1
- package com.modal
2
-
3
- import android.content.DialogInterface
4
- import android.graphics.Color
5
- import android.graphics.PixelFormat
6
- import android.graphics.drawable.ColorDrawable
7
- import android.os.Bundle
8
- import android.view.LayoutInflater
9
- import android.view.View
10
- import android.view.ViewGroup
11
- import android.view.WindowManager
12
- import android.widget.FrameLayout
13
- import androidx.coordinatorlayout.widget.CoordinatorLayout
14
- import androidx.fragment.app.DialogFragment
15
- import androidx.fragment.app.FragmentManager
16
- import com.sheet.R
17
- import com.sheet.setStatusBarStyle
18
-
19
-
20
- fun androidx.fragment.app.Fragment.safeShow(
21
- manager: FragmentManager,
22
- tag: String?
23
- ) {
24
- val ft = manager.beginTransaction()
25
- ft.add(this, tag)
26
- ft.commitNowAllowingStateLoss()
27
- }
28
-
29
- class FullScreenDialog(
30
- private val presentView: View,
31
- private val animated: Boolean,
32
- // "slide" || "fade"
33
- private val animationType: String,
34
- private val isEdgeToEdge: Boolean,
35
- private val isSystemUILight: Boolean,
36
- private val onDismiss: () -> Unit
37
- ) : DialogFragment() {
38
- override fun onCreate(savedInstanceState: Bundle?) {
39
- super.onCreate(savedInstanceState)
40
- if (isEdgeToEdge) {
41
- setStyle(STYLE_NORMAL, R.style.Custom_Theme_EdgeToEdgeDialog)
42
- } else {
43
- setStyle(STYLE_NORMAL, R.style.Custom_Theme_FullScreenDialog)
44
- }
45
- }
46
-
47
- override fun onStart() {
48
- super.onStart()
49
- isCancelable = false
50
-
51
- dialog?.window?.let {
52
- if (animated) {
53
- if (animationType == "slide") {
54
- it.setWindowAnimations(R.style.Custom_Theme_FullScreenDialog_Slide)
55
- }
56
- // Fade is applied by Default
57
- } else {
58
- it.setWindowAnimations(R.style.Custom_Theme_FullScreenDialog_NoAnimation)
59
- }
60
-
61
- if (isEdgeToEdge) {
62
- it.navigationBarColor = Color.TRANSPARENT
63
- it.statusBarColor = Color.TRANSPARENT
64
- it.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE or
65
- View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
66
-
67
- it.setStatusBarStyle(isSystemUILight)
68
- } else {
69
- val width = ViewGroup.LayoutParams.MATCH_PARENT
70
- val height = ViewGroup.LayoutParams.MATCH_PARENT
71
- it.setLayout(width, height)
72
- it.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND)
73
- }
74
-
75
- it.setFormat(PixelFormat.TRANSLUCENT)
76
- it.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
77
- }
78
- }
79
-
80
- override fun onCreateView(
81
- inflater: LayoutInflater,
82
- container: ViewGroup?,
83
- savedInstanceState: Bundle?
84
- ): View {
85
- super.onCreateView(inflater, container, savedInstanceState)
86
- val parent = inflater.inflate(R.layout.item_full, container, false) as CoordinatorLayout
87
- return parent
88
- }
89
-
90
- override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
91
- super.onViewCreated(view, savedInstanceState)
92
- view.findViewById<FrameLayout>(R.id.container).addView(presentView)
93
- }
94
-
95
- override fun onDismiss(dialog: DialogInterface) {
96
- super.onDismiss(dialog)
97
- println("⚽️ FullScreenDialog.onDismiss")
98
- onDismiss()
99
- }
100
- }
@@ -1,77 +0,0 @@
1
- package com.modal
2
-
3
- import android.content.Context
4
- import android.view.View
5
- import android.view.accessibility.AccessibilityEvent
6
- import androidx.appcompat.app.AppCompatActivity
7
- import com.sheet.BaseRNView
8
- import com.facebook.react.bridge.Arguments
9
- import com.facebook.react.bridge.LifecycleEventListener
10
- import com.facebook.react.bridge.ReactContext
11
- import com.facebook.react.bridge.UiThreadUtil
12
- import com.facebook.react.uimanager.events.RCTEventEmitter
13
- import com.facebook.react.views.view.ReactViewGroup
14
-
15
- fun TopModalView.onModalDismiss() {
16
- (context as ReactContext).getJSModule(RCTEventEmitter::class.java)
17
- .receiveEvent(id, "onModalDismiss", Arguments.createMap())
18
- }
19
-
20
- class TopModalView(context: Context?) : ReactViewGroup(context) {
21
- private var dialog: FullScreenDialog? = null
22
- private var rnView = BaseRNView(context)
23
-
24
- var isEdgeToEdge = false
25
- var isSystemUILight = false
26
- var animated = true
27
- // "slide" || "fade"
28
- var animationType = "slide"
29
-
30
- init {
31
- println("⚽️ init")
32
- }
33
-
34
- private fun getCurrentActivity(): AppCompatActivity? {
35
- return (context as? ReactContext)?.currentActivity as? AppCompatActivity
36
- }
37
-
38
- override fun addView(child: View, index: Int) {
39
- val activity = getCurrentActivity() ?: return
40
- rnView.addView(child)
41
- dialog = FullScreenDialog(
42
- presentView = rnView,
43
- animated = animated,
44
- animationType = animationType,
45
- isEdgeToEdge = isEdgeToEdge,
46
- isSystemUILight = isSystemUILight,
47
- ::onModalDismiss,
48
- )
49
- dialog?.safeShow(activity.supportFragmentManager, "TopModalView")
50
- dialog?.isCancelable = true
51
-
52
- }
53
-
54
- override fun addChildrenForAccessibility(outChildren: ArrayList<View?>?) {}
55
- override fun dispatchPopulateAccessibilityEvent(event: AccessibilityEvent?) = false
56
-
57
-
58
- override fun removeView(child: View?) {
59
- println("⚽️ removeView")
60
- UiThreadUtil.assertOnUiThread()
61
- dismiss()
62
- }
63
-
64
- override fun removeViewAt(index: Int) {
65
- println("⚽️ removeViewAt: $index")
66
- UiThreadUtil.assertOnUiThread()
67
- dismiss()
68
- }
69
-
70
- fun dismiss() {
71
- dialog?.let {
72
- println("⚽️ dismiss")
73
- dialog?.dismissAllowingStateLoss()
74
- dialog = null
75
- }
76
- }
77
- }