react-native-sheet2 1.1.19

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 (74) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +79 -0
  3. package/android/build.gradle +83 -0
  4. package/android/gradle.properties +6 -0
  5. package/android/src/main/AndroidManifest.xml +12 -0
  6. package/android/src/main/java/com/behavior/BottomSheetBehavior.java +2329 -0
  7. package/android/src/main/java/com/behavior/InsetsAnimationCallback.java +83 -0
  8. package/android/src/main/java/com/modal/FullScreenDialog.kt +100 -0
  9. package/android/src/main/java/com/modal/TopModalView.kt +77 -0
  10. package/android/src/main/java/com/modal/TopModalViewManager.kt +83 -0
  11. package/android/src/main/java/com/modal/TopModalViewModule.kt +36 -0
  12. package/android/src/main/java/com/sheet/AppFittedSheet.kt +149 -0
  13. package/android/src/main/java/com/sheet/BaseRNView.kt +73 -0
  14. package/android/src/main/java/com/sheet/CustomBottomSheetDialog.java +238 -0
  15. package/android/src/main/java/com/sheet/DialogRootViewGroup.kt +159 -0
  16. package/android/src/main/java/com/sheet/FragmentModalBottomSheet.kt +54 -0
  17. package/android/src/main/java/com/sheet/ReactNativeReflection.java +24 -0
  18. package/android/src/main/java/com/sheet/SheetPackage.kt +20 -0
  19. package/android/src/main/java/com/sheet/SheetViewManager.kt +144 -0
  20. package/android/src/main/java/com/sheet/SheetViewModule.kt +43 -0
  21. package/android/src/main/java/com/sheet/utils.kt +71 -0
  22. package/android/src/main/java/com/transparent/activity/ActivityModalView.kt +71 -0
  23. package/android/src/main/java/com/transparent/activity/TransparentActivity.kt +48 -0
  24. package/android/src/main/java/com/transparent/activity/TransparentActivityManager.kt +63 -0
  25. package/android/src/main/java/com/transparent/activity/TransparentActivityModule.kt +28 -0
  26. package/android/src/main/res/anim/fade_in.xml +8 -0
  27. package/android/src/main/res/anim/fade_out.xml +11 -0
  28. package/android/src/main/res/anim/slide_down.xml +8 -0
  29. package/android/src/main/res/anim/slide_up.xml +8 -0
  30. package/android/src/main/res/layout/dialog_bottom_sheet.xml +64 -0
  31. package/android/src/main/res/layout/item_full.xml +14 -0
  32. package/android/src/main/res/values/colors.xml +15 -0
  33. package/android/src/main/res/values/styles.xml +75 -0
  34. package/ios/FittedSheets/Compatible.swift +55 -0
  35. package/ios/FittedSheets/InitialTouchPanGestureRecognizer.swift +19 -0
  36. package/ios/FittedSheets/SheetContentViewController.swift +326 -0
  37. package/ios/FittedSheets/SheetContentViewDelegate.swift +17 -0
  38. package/ios/FittedSheets/SheetOptions.swift +100 -0
  39. package/ios/FittedSheets/SheetSize.swift +20 -0
  40. package/ios/FittedSheets/SheetTransition.swift +153 -0
  41. package/ios/FittedSheets/SheetView.swift +21 -0
  42. package/ios/FittedSheets/SheetViewController.swift +761 -0
  43. package/ios/FittedSheets/SheetViewDelegate.swift +16 -0
  44. package/ios/FittedSheets/UIColorExtension.swift +59 -0
  45. package/ios/FittedSheets/UIViewControllerExtension.swift +27 -0
  46. package/ios/FittedSheets/Yalta.swift +420 -0
  47. package/ios/LBBottomSheet/BottomSheetConstant.swift +48 -0
  48. package/ios/LBBottomSheet/Model/BottomSheetController+Behavior.swift +262 -0
  49. package/ios/LBBottomSheet/Model/BottomSheetController+Theme.swift +156 -0
  50. package/ios/LBBottomSheet/Protocols/BottomSheetInteractionDelegate.swift +29 -0
  51. package/ios/LBBottomSheet/Protocols/BottomSheetPositionDelegate.swift +31 -0
  52. package/ios/LBBottomSheet/UI/BottomSheet.storyboard +105 -0
  53. package/ios/LBBottomSheet/UI/BottomSheetController.swift +601 -0
  54. package/ios/LBBottomSheet/Utils/Components/ForwardingEventsView.swift +60 -0
  55. package/ios/LBBottomSheet/Utils/Extensions/CACornerMask+Extension.swift +33 -0
  56. package/ios/LBBottomSheet/Utils/Extensions/Mirror+Extension.swift +47 -0
  57. package/ios/LBBottomSheet/Utils/Extensions/UIApplication+Extension.swift +35 -0
  58. package/ios/LBBottomSheet/Utils/Extensions/UIColor+Extension.swift +61 -0
  59. package/ios/LBBottomSheet/Utils/Extensions/UIGestureRecognizer+Extensions.swift +28 -0
  60. package/ios/LBBottomSheet/Utils/Extensions/UIScreen+Extension.swift +28 -0
  61. package/ios/LBBottomSheet/Utils/Extensions/UIScrollView+Extension.swift +25 -0
  62. package/ios/LBBottomSheet/Utils/Extensions/UIView+Extension.swift +52 -0
  63. package/ios/LBBottomSheet/Utils/Extensions/UIViewController+Extension.swift +104 -0
  64. package/ios/Sheet-Bridging-Header.h +1 -0
  65. package/ios/Sheet.xcodeproj/project.pbxproj +377 -0
  66. package/ios/SheetViewManager.m +27 -0
  67. package/ios/SheetViewManager.swift +351 -0
  68. package/ios/TopModalViewManager.swift +196 -0
  69. package/package.json +103 -0
  70. package/react-native-sheet.podspec +21 -0
  71. package/src/FittedSheet.tsx +177 -0
  72. package/src/TopModal.tsx +94 -0
  73. package/src/TransparentActivity.tsx +98 -0
  74. package/src/index.tsx +16 -0
@@ -0,0 +1,177 @@
1
+ import React, { createContext, useContext } from 'react';
2
+ import {
3
+ Dimensions,
4
+ findNodeHandle,
5
+ NativeModules,
6
+ processColor,
7
+ requireNativeComponent,
8
+ StatusBar,
9
+ View,
10
+ } from 'react-native';
11
+
12
+ export const _FittedSheet = requireNativeComponent<any>('SheetView');
13
+
14
+ export interface FittedSheetParams {
15
+ readonly applyMaxHeightToMinHeight?: boolean;
16
+ readonly dismissible?: boolean;
17
+ readonly maxPortraitWidth?: number;
18
+ readonly maxLandscapeWidth?: number;
19
+ readonly maxHeight?: number;
20
+ readonly minHeight?: number;
21
+ readonly isDark?: boolean;
22
+ readonly topLeftRightCornerRadius?: number;
23
+ readonly backgroundColor?: string;
24
+ /**
25
+ * Android only
26
+ */
27
+ readonly isStatusBarBgLight?: boolean;
28
+ }
29
+
30
+ type Children =
31
+ | ((data: any) => React.ReactElement)
32
+ | React.ReactElement
33
+ | React.ReactElement[];
34
+
35
+ interface Props {
36
+ readonly params?: FittedSheetParams;
37
+ readonly onSheetDismiss?: (passThroughParam?: any) => void;
38
+ readonly children?: Children;
39
+ }
40
+
41
+ interface State {
42
+ show: boolean;
43
+ data: any | null;
44
+ }
45
+
46
+ export const FITTED_SHEET_SCROLL_VIEW = 'fittedSheetScrollView';
47
+
48
+ interface Context {
49
+ hide: (passThroughParam?: any) => void;
50
+ increaseHeight: (by: number) => void;
51
+ decreaseHeight: (by: number) => void;
52
+ passScrollViewReactTag: (nativeId: string) => void;
53
+ }
54
+
55
+ const FittedSheetContext = createContext<Context | null>(null);
56
+
57
+ export const useFittedSheetContext = () => {
58
+ return useContext(FittedSheetContext)!;
59
+ };
60
+
61
+ export class FittedSheet extends React.PureComponent<Props, State> {
62
+ private cleanup?: () => void;
63
+ private shouldShowBack = false;
64
+ private onHidePassThroughParam?: any;
65
+ private sheetRef = React.createRef<any>();
66
+ constructor(props: Props) {
67
+ super(props);
68
+ this.state = { show: false, data: null };
69
+ }
70
+
71
+ show = (data?: any) => {
72
+ this.setState({ show: true, data });
73
+ };
74
+
75
+ data = () => this.state.data;
76
+
77
+ toggle = () => {
78
+ this.setState({ show: !this.state.show });
79
+ };
80
+
81
+ passScrollViewReactTag = (nativeId: string) => {
82
+ console.log('🍓[FittedSheet.passScrollViewReactTag]', nativeId);
83
+ this.sheetRef.current?.setNativeProps({ passScrollViewReactTag: nativeId });
84
+ };
85
+
86
+ increaseHeight = (by: number) => {
87
+ this.sheetRef.current?.setNativeProps({ increaseHeight: by });
88
+ };
89
+
90
+ decreaseHeight = (by: number) => {
91
+ this.sheetRef.current?.setNativeProps({ decreaseHeight: by });
92
+ };
93
+
94
+ hide = (passThroughParam?: any) => {
95
+ if (!this.state.show) return;
96
+ this.onHidePassThroughParam = passThroughParam;
97
+ const tag = findNodeHandle(this.sheetRef.current);
98
+ if (!tag) return;
99
+ NativeModules.SheetView.dismiss(tag);
100
+ };
101
+
102
+ private onDismiss = () => {
103
+ if (this.shouldShowBack) {
104
+ this.setState({ show: false }, () => this.show(this.state.data));
105
+ this.shouldShowBack = false;
106
+ return;
107
+ }
108
+ this.setState({ show: false });
109
+ const passValue = this.onHidePassThroughParam;
110
+ this.onHidePassThroughParam = undefined;
111
+ this.props.onSheetDismiss?.(passValue);
112
+ };
113
+
114
+ componentDidMount() {
115
+ this.cleanup = Dimensions.addEventListener('change', () => {
116
+ if (!this.state.show) return;
117
+ if (this.shouldShowBack) return;
118
+ this.shouldShowBack = true;
119
+ this.hide();
120
+ }).remove;
121
+ }
122
+
123
+ componentWillUnmount() {
124
+ this.hide();
125
+ this.cleanup?.();
126
+ this.cleanup = undefined;
127
+ }
128
+
129
+ render() {
130
+ if (!this.state.show) return null;
131
+ const dim = Dimensions.get('screen');
132
+ const isLandscape = dim.width > dim.height;
133
+ const maxHeight = Math.min(
134
+ this.props.params?.maxHeight ?? Number.MAX_VALUE,
135
+ dim.height - (StatusBar.currentHeight ?? 0)
136
+ );
137
+ const paramsMaxWidth = isLandscape
138
+ ? this.props.params?.maxLandscapeWidth
139
+ : this.props.params?.maxPortraitWidth;
140
+ let maxWidth = Math.min(paramsMaxWidth ?? Number.MAX_VALUE, dim.width);
141
+ let minHeight = this.props.params?.minHeight;
142
+ if (this.props.params?.applyMaxHeightToMinHeight) {
143
+ minHeight = maxHeight;
144
+ }
145
+ return (
146
+ <_FittedSheet
147
+ onSheetDismiss={this.onDismiss}
148
+ ref={this.sheetRef}
149
+ style={{ width: maxWidth, maxHeight, minHeight, position: 'absolute' }}
150
+ fittedSheetParams={
151
+ this.props.params
152
+ ? {
153
+ ...this.props.params,
154
+ isDark: this.props.params.isDark ?? false,
155
+ maxHeight,
156
+ maxWidth,
157
+ backgroundColor: this.props.params.backgroundColor
158
+ ? processColor(this.props.params.backgroundColor)
159
+ : undefined,
160
+ }
161
+ : {}
162
+ }
163
+ >
164
+ <FittedSheetContext.Provider value={this}>
165
+ <View nativeID={'fitted-sheet-root-view'}>
166
+ {this.props.children &&
167
+ typeof this.props.children === 'function' &&
168
+ this.props.children(this.state.data)}
169
+ {this.props.children &&
170
+ typeof this.props.children !== 'function' &&
171
+ this.props.children}
172
+ </View>
173
+ </FittedSheetContext.Provider>
174
+ </_FittedSheet>
175
+ );
176
+ }
177
+ }
@@ -0,0 +1,94 @@
1
+ import {
2
+ findNodeHandle,
3
+ NativeModules,
4
+ requireNativeComponent,
5
+ StyleSheet,
6
+ View,
7
+ } from 'react-native';
8
+ import React from 'react';
9
+
10
+ const TopModalView = requireNativeComponent<any>('TopModalView');
11
+
12
+ interface Props {
13
+ onModalDismiss?: () => void;
14
+ children: React.ReactNode;
15
+
16
+ /**
17
+ * @default false
18
+ * @platform Android
19
+ */
20
+ isEdgeToEdge?: boolean;
21
+ /**
22
+ * @default false
23
+ * @platform Android
24
+ */
25
+ isStatusBarBgLight?: boolean;
26
+
27
+ animated?: boolean;
28
+ /** @default "slide" */
29
+ animationType?: 'slide' | 'fade' | 'none';
30
+ }
31
+
32
+ interface State {
33
+ show: boolean;
34
+ }
35
+
36
+ export class TopModal extends React.PureComponent<Props, State> {
37
+ private sheetRef = React.createRef<any>();
38
+
39
+ constructor(props: Props) {
40
+ super(props);
41
+ this.state = {
42
+ show: false,
43
+ };
44
+ }
45
+
46
+ show = () => {
47
+ if (this.state.show) return;
48
+ this.setState({ show: true });
49
+ };
50
+
51
+ hide = () => {
52
+ if (!this.state.show) return;
53
+ const tag = findNodeHandle(this.sheetRef.current);
54
+ if (!tag) return;
55
+ console.log('[TopModal.hide]', tag);
56
+ NativeModules.TopModalView.dismiss(tag);
57
+ };
58
+
59
+ private onDismiss = () => {
60
+ console.log('[FittedSheet.onDismiss]');
61
+ this.setState({ show: false });
62
+ this.props.onModalDismiss?.();
63
+ };
64
+
65
+ componentWillUnmount() {
66
+ this.hide();
67
+ console.log('[TopModal.componentWillUnmount]');
68
+ }
69
+
70
+ render() {
71
+ if (!this.state.show) {
72
+ this.hide();
73
+ console.log('[TopModal.render.remove]');
74
+ return null;
75
+ }
76
+ return (
77
+ <TopModalView
78
+ ref={this.sheetRef}
79
+ onModalDismiss={this.onDismiss}
80
+ animated={this.props.animated ?? true}
81
+ animationType={this.props.animationType ?? 'slide'}
82
+ isEdgeToEdge={this.props.isEdgeToEdge ?? false}
83
+ isStatusBarBgLight={this.props.isStatusBarBgLight ?? false}
84
+ >
85
+ <View
86
+ accessibilityLabel={'top-modal-root-view'}
87
+ nativeID={'top-modal-root-view'}
88
+ style={StyleSheet.absoluteFill}
89
+ children={this.props.children}
90
+ />
91
+ </TopModalView>
92
+ );
93
+ }
94
+ }
@@ -0,0 +1,98 @@
1
+ import {
2
+ findNodeHandle,
3
+ NativeModules,
4
+ Platform,
5
+ requireNativeComponent,
6
+ StyleSheet,
7
+ View,
8
+ } from 'react-native';
9
+ import React from 'react';
10
+
11
+ const TransparentActivity = requireNativeComponent<any>('TransparentActivity');
12
+ const TopModalView = requireNativeComponent<any>('TopModalView');
13
+
14
+ interface Props {
15
+ onActivityDismiss?: () => void;
16
+ children: React.ReactNode;
17
+ animated?: boolean;
18
+ }
19
+
20
+ interface State {
21
+ show: boolean;
22
+ }
23
+
24
+ export class TransparentActivityView extends React.PureComponent<Props, State> {
25
+ private sheetRef = React.createRef<any>();
26
+
27
+ constructor(props: Props) {
28
+ super(props);
29
+ this.state = { show: false };
30
+ }
31
+
32
+ show = () => {
33
+ if (this.state.show) return;
34
+ this.setState({ show: true });
35
+ };
36
+
37
+ hide = () => {
38
+ if (!this.state.show) return;
39
+ const tag = findNodeHandle(this.sheetRef.current);
40
+ if (!tag) return;
41
+ console.log('[TopModal.hide]', tag);
42
+ if (Platform.OS === 'android')
43
+ NativeModules.TransparentActivity.dismiss(tag);
44
+ else NativeModules.TopModalView.dismiss(tag);
45
+ };
46
+
47
+ private onDismiss = () => {
48
+ console.log('[FittedSheet.onDismiss]');
49
+ this.setState({ show: false });
50
+ this.props.onActivityDismiss?.();
51
+ };
52
+
53
+ componentWillUnmount() {
54
+ this.hide();
55
+ console.log('[TopModal.componentWillUnmount]');
56
+ }
57
+
58
+ render() {
59
+ if (!this.state.show) {
60
+ this.hide();
61
+ console.log('[TopModal.render.remove]');
62
+ return null;
63
+ }
64
+
65
+ if (Platform.OS === 'android') {
66
+ return (
67
+ <TransparentActivity
68
+ onActivityDismiss={this.onDismiss}
69
+ ref={this.sheetRef}
70
+ animated={this.props.animated ?? true}
71
+ >
72
+ <View
73
+ accessibilityLabel={'transparent-activity-root-view'}
74
+ nativeID={'transparent-activity-root-view'}
75
+ style={StyleSheet.absoluteFill}
76
+ children={this.props.children}
77
+ />
78
+ </TransparentActivity>
79
+ );
80
+ }
81
+
82
+ return (
83
+ <TopModalView
84
+ animationType={'none'}
85
+ animated={false}
86
+ onModalDismiss={this.onDismiss}
87
+ ref={this.sheetRef}
88
+ >
89
+ <View
90
+ accessibilityLabel={'transparent-activity-root-view'}
91
+ nativeID={'transparent-activity-root-view'}
92
+ style={StyleSheet.absoluteFill}
93
+ children={this.props.children}
94
+ />
95
+ </TopModalView>
96
+ );
97
+ }
98
+ }
package/src/index.tsx ADDED
@@ -0,0 +1,16 @@
1
+ import {
2
+ FITTED_SHEET_SCROLL_VIEW,
3
+ FittedSheet,
4
+ useFittedSheetContext,
5
+ FittedSheetParams,
6
+ } from './FittedSheet';
7
+
8
+ export {
9
+ FittedSheet,
10
+ FITTED_SHEET_SCROLL_VIEW,
11
+ useFittedSheetContext,
12
+ FittedSheetParams,
13
+ };
14
+
15
+ export { TopModal } from './TopModal';
16
+ export { TransparentActivityView } from './TransparentActivity';