@onekeyfe/react-native-native-sheet 3.0.125
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/LICENSE +21 -0
- package/NativeSheet.podspec +22 -0
- package/README.md +56 -0
- package/android/build.gradle +82 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/com/onekey/nativesheet/NativeSheetEvents.kt +37 -0
- package/android/src/main/java/com/onekey/nativesheet/NativeSheetPackage.kt +16 -0
- package/android/src/main/java/com/onekey/nativesheet/NativeSheetView.kt +354 -0
- package/android/src/main/java/com/onekey/nativesheet/NativeSheetViewManager.kt +118 -0
- package/ios/NativeSheetContainerView.swift +441 -0
- package/ios/RCTNativeSheetComponentView.h +11 -0
- package/ios/RCTNativeSheetComponentView.mm +156 -0
- package/lib/module/NativeSheetNativeComponent.ts +35 -0
- package/lib/module/codegen-types.d.js +2 -0
- package/lib/module/codegen-types.d.js.map +1 -0
- package/lib/module/index.js +92 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/NativeSheetNativeComponent.d.ts +25 -0
- package/lib/typescript/src/NativeSheetNativeComponent.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +40 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/package.json +171 -0
- package/react-native.config.js +12 -0
- package/src/NativeSheetNativeComponent.ts +35 -0
- package/src/codegen-types.d.ts +9 -0
- package/src/index.tsx +145 -0
package/src/index.tsx
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createContext,
|
|
3
|
+
type PropsWithChildren,
|
|
4
|
+
useCallback,
|
|
5
|
+
useContext,
|
|
6
|
+
} from 'react';
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
type ColorValue,
|
|
10
|
+
type NativeSyntheticEvent,
|
|
11
|
+
StyleSheet,
|
|
12
|
+
useWindowDimensions,
|
|
13
|
+
View,
|
|
14
|
+
} from 'react-native';
|
|
15
|
+
|
|
16
|
+
import RNCNativeSheet, {
|
|
17
|
+
type NativeSheetDismissEvent,
|
|
18
|
+
type NativeSheetPresentedEvent,
|
|
19
|
+
} from './NativeSheetNativeComponent';
|
|
20
|
+
|
|
21
|
+
export type NativeSheetDismissReason =
|
|
22
|
+
| 'back'
|
|
23
|
+
| 'backdrop'
|
|
24
|
+
| 'pan'
|
|
25
|
+
| 'programmatic'
|
|
26
|
+
| 'security'
|
|
27
|
+
| 'system';
|
|
28
|
+
|
|
29
|
+
export interface NativeSheetProps extends PropsWithChildren {
|
|
30
|
+
/** Controls whether the sheet is presented. */
|
|
31
|
+
open: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Fixed outer height for this presentation, in points/dp. Content updates do
|
|
34
|
+
* not change this value, so asynchronously loaded children cannot resize the
|
|
35
|
+
* native sheet mid-transition.
|
|
36
|
+
*/
|
|
37
|
+
height: number;
|
|
38
|
+
onDismiss?: (reason: NativeSheetDismissReason) => void;
|
|
39
|
+
onPresented?: (height: number) => void;
|
|
40
|
+
dismissOnPanDown?: boolean;
|
|
41
|
+
dismissOnBackdropPress?: boolean;
|
|
42
|
+
dismissOnBackPress?: boolean;
|
|
43
|
+
showHandle?: boolean;
|
|
44
|
+
cornerRadius?: number;
|
|
45
|
+
dimAmount?: number;
|
|
46
|
+
backgroundColor?: ColorValue;
|
|
47
|
+
testID?: string;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const NativeSheetSecurityContext = createContext(false);
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Blocks every descendant sheet while security UI is visible. Consumers must
|
|
54
|
+
* place this provider above all NativeSheet instances and bind `blocked` to the
|
|
55
|
+
* app-lock state. A blocked transition is dismissed natively without animation.
|
|
56
|
+
*/
|
|
57
|
+
export function NativeSheetSecurityProvider({
|
|
58
|
+
blocked,
|
|
59
|
+
children,
|
|
60
|
+
}: PropsWithChildren<{ blocked: boolean }>) {
|
|
61
|
+
return (
|
|
62
|
+
<NativeSheetSecurityContext.Provider value={blocked}>
|
|
63
|
+
{children}
|
|
64
|
+
</NativeSheetSecurityContext.Provider>
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Presents arbitrary React Native children inside a native sheet container.
|
|
70
|
+
* The native component is staged off-screen before presentation; once opened,
|
|
71
|
+
* Fabric mounts the same child view into the platform sheet without serializing
|
|
72
|
+
* business content through the native bridge.
|
|
73
|
+
*/
|
|
74
|
+
export function NativeSheet({
|
|
75
|
+
open,
|
|
76
|
+
height,
|
|
77
|
+
children,
|
|
78
|
+
onDismiss,
|
|
79
|
+
onPresented,
|
|
80
|
+
dismissOnPanDown = true,
|
|
81
|
+
dismissOnBackdropPress = false,
|
|
82
|
+
dismissOnBackPress = true,
|
|
83
|
+
showHandle = true,
|
|
84
|
+
cornerRadius = 32,
|
|
85
|
+
dimAmount = 0.4,
|
|
86
|
+
backgroundColor,
|
|
87
|
+
testID,
|
|
88
|
+
}: NativeSheetProps) {
|
|
89
|
+
const securityBlocked = useContext(NativeSheetSecurityContext);
|
|
90
|
+
const { width } = useWindowDimensions();
|
|
91
|
+
|
|
92
|
+
const handleDismiss = useCallback(
|
|
93
|
+
(event: NativeSyntheticEvent<NativeSheetDismissEvent>) => {
|
|
94
|
+
onDismiss?.(event.nativeEvent.reason as NativeSheetDismissReason);
|
|
95
|
+
},
|
|
96
|
+
[onDismiss]
|
|
97
|
+
);
|
|
98
|
+
const handlePresented = useCallback(
|
|
99
|
+
(event: NativeSyntheticEvent<NativeSheetPresentedEvent>) => {
|
|
100
|
+
onPresented?.(event.nativeEvent.height);
|
|
101
|
+
},
|
|
102
|
+
[onPresented]
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
return (
|
|
106
|
+
<RNCNativeSheet
|
|
107
|
+
testID={testID}
|
|
108
|
+
open={open}
|
|
109
|
+
sheetHeight={height}
|
|
110
|
+
securityBlocked={securityBlocked}
|
|
111
|
+
dismissOnPanDown={dismissOnPanDown}
|
|
112
|
+
dismissOnBackdropPress={dismissOnBackdropPress}
|
|
113
|
+
dismissOnBackPress={dismissOnBackPress}
|
|
114
|
+
showHandle={showHandle}
|
|
115
|
+
cornerRadius={cornerRadius}
|
|
116
|
+
dimAmount={dimAmount}
|
|
117
|
+
sheetBackgroundColor={backgroundColor}
|
|
118
|
+
onDismiss={handleDismiss}
|
|
119
|
+
onPresented={handlePresented}
|
|
120
|
+
style={[styles.stagingHost, { width, height }]}
|
|
121
|
+
>
|
|
122
|
+
<View pointerEvents="auto" style={styles.content} collapsable={false}>
|
|
123
|
+
{children}
|
|
124
|
+
</View>
|
|
125
|
+
</RNCNativeSheet>
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const styles = StyleSheet.create({
|
|
130
|
+
stagingHost: {
|
|
131
|
+
position: 'absolute',
|
|
132
|
+
left: -100_000,
|
|
133
|
+
bottom: 0,
|
|
134
|
+
opacity: 0,
|
|
135
|
+
},
|
|
136
|
+
content: {
|
|
137
|
+
flex: 1,
|
|
138
|
+
},
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
export type {
|
|
142
|
+
NativeSheetDismissEvent,
|
|
143
|
+
NativeSheetNativeProps,
|
|
144
|
+
NativeSheetPresentedEvent,
|
|
145
|
+
} from './NativeSheetNativeComponent';
|