@sdcx/bottom-sheet 0.1.0

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.
@@ -0,0 +1,283 @@
1
+ // !$*UTF8*$!
2
+ {
3
+ archiveVersion = 1;
4
+ classes = {
5
+ };
6
+ objectVersion = 48;
7
+ objects = {
8
+
9
+ /* Begin PBXBuildFile section */
10
+ 91C884A6202C3E8600EC0A20 /* undefined.m in Sources */ = {isa = PBXBuildFile; fileRef = 91C884A1202C3E8600EC0A20 /* undefined.m */; };
11
+ /* End PBXBuildFile section */
12
+
13
+ /* Begin PBXCopyFilesBuildPhase section */
14
+ 910362D01FE9318600F4DA8E /* CopyFiles */ = {
15
+ isa = PBXCopyFilesBuildPhase;
16
+ buildActionMask = 2147483647;
17
+ dstPath = "include/$(PRODUCT_NAME)";
18
+ dstSubfolderSpec = 16;
19
+ files = (
20
+ );
21
+ runOnlyForDeploymentPostprocessing = 0;
22
+ };
23
+ /* End PBXCopyFilesBuildPhase section */
24
+
25
+ /* Begin PBXFileReference section */
26
+ 910362D21FE9318600F4DA8E /* libBottomSheet.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libBottomSheet.a; sourceTree = BUILT_PRODUCTS_DIR; };
27
+ 91C884A1202C3E8600EC0A20 /* undefined.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = undefined.m; sourceTree = "<group>"; };
28
+ 91C884A2202C3E8600EC0A20 /* undefined.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = undefined.h; sourceTree = "<group>"; };
29
+ /* End PBXFileReference section */
30
+
31
+ /* Begin PBXFrameworksBuildPhase section */
32
+ 910362CF1FE9318600F4DA8E /* Frameworks */ = {
33
+ isa = PBXFrameworksBuildPhase;
34
+ buildActionMask = 2147483647;
35
+ files = (
36
+ );
37
+ runOnlyForDeploymentPostprocessing = 0;
38
+ };
39
+ /* End PBXFrameworksBuildPhase section */
40
+
41
+ /* Begin PBXGroup section */
42
+ 910362C91FE9318600F4DA8E = {
43
+ isa = PBXGroup;
44
+ children = (
45
+ 910362D41FE9318600F4DA8E /* BottomSheet */,
46
+ 910362D31FE9318600F4DA8E /* Products */,
47
+ );
48
+ sourceTree = "<group>";
49
+ };
50
+ 910362D31FE9318600F4DA8E /* Products */ = {
51
+ isa = PBXGroup;
52
+ children = (
53
+ 910362D21FE9318600F4DA8E /* libBottomSheet.a */,
54
+ );
55
+ name = Products;
56
+ sourceTree = "<group>";
57
+ };
58
+ 910362D41FE9318600F4DA8E /* BottomSheet */ = {
59
+ isa = PBXGroup;
60
+ children = (
61
+ 91C884A2202C3E8600EC0A20 /* undefined.h */,
62
+ 91C884A1202C3E8600EC0A20 /* undefined.m */,
63
+ );
64
+ path = BottomSheet;
65
+ sourceTree = "<group>";
66
+ };
67
+ /* End PBXGroup section */
68
+
69
+ /* Begin PBXNativeTarget section */
70
+ 910362D11FE9318600F4DA8E /* BottomSheet */ = {
71
+ isa = PBXNativeTarget;
72
+ buildConfigurationList = 910362DB1FE9318600F4DA8E /* Build configuration list for PBXNativeTarget "BottomSheet" */;
73
+ buildPhases = (
74
+ 910362CE1FE9318600F4DA8E /* Sources */,
75
+ 910362CF1FE9318600F4DA8E /* Frameworks */,
76
+ 910362D01FE9318600F4DA8E /* CopyFiles */,
77
+ );
78
+ buildRules = (
79
+ );
80
+ dependencies = (
81
+ );
82
+ name = BottomSheet;
83
+ productName = BottomSheet;
84
+ productReference = 910362D21FE9318600F4DA8E /* libBottomSheet.a */;
85
+ productType = "com.apple.product-type.library.static";
86
+ };
87
+ /* End PBXNativeTarget section */
88
+
89
+ /* Begin PBXProject section */
90
+ 910362CA1FE9318600F4DA8E /* Project object */ = {
91
+ isa = PBXProject;
92
+ attributes = {
93
+ LastUpgradeCheck = 0920;
94
+ ORGANIZATIONNAME = Listen;
95
+ TargetAttributes = {
96
+ 910362D11FE9318600F4DA8E = {
97
+ CreatedOnToolsVersion = 9.2;
98
+ ProvisioningStyle = Automatic;
99
+ };
100
+ };
101
+ };
102
+ buildConfigurationList = 910362CD1FE9318600F4DA8E /* Build configuration list for PBXProject "BottomSheet" */;
103
+ compatibilityVersion = "Xcode 8.0";
104
+ developmentRegion = en;
105
+ hasScannedForEncodings = 0;
106
+ knownRegions = (
107
+ en,
108
+ );
109
+ mainGroup = 910362C91FE9318600F4DA8E;
110
+ productRefGroup = 910362D31FE9318600F4DA8E /* Products */;
111
+ projectDirPath = "";
112
+ projectRoot = "";
113
+ targets = (
114
+ 910362D11FE9318600F4DA8E /* BottomSheet */,
115
+ );
116
+ };
117
+ /* End PBXProject section */
118
+
119
+ /* Begin PBXSourcesBuildPhase section */
120
+ 910362CE1FE9318600F4DA8E /* Sources */ = {
121
+ isa = PBXSourcesBuildPhase;
122
+ buildActionMask = 2147483647;
123
+ files = (
124
+ 91C884A6202C3E8600EC0A20 /* undefined.m in Sources */,
125
+ );
126
+ runOnlyForDeploymentPostprocessing = 0;
127
+ };
128
+ /* End PBXSourcesBuildPhase section */
129
+
130
+ /* Begin XCBuildConfiguration section */
131
+ 910362D91FE9318600F4DA8E /* Debug */ = {
132
+ isa = XCBuildConfiguration;
133
+ buildSettings = {
134
+ ALWAYS_SEARCH_USER_PATHS = NO;
135
+ CLANG_ANALYZER_NONNULL = YES;
136
+ CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
137
+ CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
138
+ CLANG_CXX_LIBRARY = "libc++";
139
+ CLANG_ENABLE_MODULES = YES;
140
+ CLANG_ENABLE_OBJC_ARC = YES;
141
+ CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
142
+ CLANG_WARN_BOOL_CONVERSION = YES;
143
+ CLANG_WARN_COMMA = YES;
144
+ CLANG_WARN_CONSTANT_CONVERSION = YES;
145
+ CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
146
+ CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
147
+ CLANG_WARN_EMPTY_BODY = YES;
148
+ CLANG_WARN_ENUM_CONVERSION = YES;
149
+ CLANG_WARN_INFINITE_RECURSION = YES;
150
+ CLANG_WARN_INT_CONVERSION = YES;
151
+ CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
152
+ CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
153
+ CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
154
+ CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
155
+ CLANG_WARN_STRICT_PROTOTYPES = YES;
156
+ CLANG_WARN_SUSPICIOUS_MOVE = YES;
157
+ CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
158
+ CLANG_WARN_UNREACHABLE_CODE = YES;
159
+ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
160
+ CODE_SIGN_IDENTITY = "iPhone Developer";
161
+ COPY_PHASE_STRIP = NO;
162
+ DEBUG_INFORMATION_FORMAT = dwarf;
163
+ ENABLE_STRICT_OBJC_MSGSEND = YES;
164
+ ENABLE_TESTABILITY = YES;
165
+ GCC_C_LANGUAGE_STANDARD = gnu11;
166
+ GCC_DYNAMIC_NO_PIC = NO;
167
+ GCC_NO_COMMON_BLOCKS = YES;
168
+ GCC_OPTIMIZATION_LEVEL = 0;
169
+ GCC_PREPROCESSOR_DEFINITIONS = (
170
+ "DEBUG=1",
171
+ "$(inherited)",
172
+ );
173
+ GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
174
+ GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
175
+ GCC_WARN_UNDECLARED_SELECTOR = YES;
176
+ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
177
+ GCC_WARN_UNUSED_FUNCTION = YES;
178
+ GCC_WARN_UNUSED_VARIABLE = YES;
179
+ IPHONEOS_DEPLOYMENT_TARGET = 7.0;
180
+ MTL_ENABLE_DEBUG_INFO = YES;
181
+ ONLY_ACTIVE_ARCH = YES;
182
+ SDKROOT = iphoneos;
183
+ };
184
+ name = Debug;
185
+ };
186
+ 910362DA1FE9318600F4DA8E /* Release */ = {
187
+ isa = XCBuildConfiguration;
188
+ buildSettings = {
189
+ ALWAYS_SEARCH_USER_PATHS = NO;
190
+ CLANG_ANALYZER_NONNULL = YES;
191
+ CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
192
+ CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
193
+ CLANG_CXX_LIBRARY = "libc++";
194
+ CLANG_ENABLE_MODULES = YES;
195
+ CLANG_ENABLE_OBJC_ARC = YES;
196
+ CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
197
+ CLANG_WARN_BOOL_CONVERSION = YES;
198
+ CLANG_WARN_COMMA = YES;
199
+ CLANG_WARN_CONSTANT_CONVERSION = YES;
200
+ CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
201
+ CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
202
+ CLANG_WARN_EMPTY_BODY = YES;
203
+ CLANG_WARN_ENUM_CONVERSION = YES;
204
+ CLANG_WARN_INFINITE_RECURSION = YES;
205
+ CLANG_WARN_INT_CONVERSION = YES;
206
+ CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
207
+ CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
208
+ CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
209
+ CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
210
+ CLANG_WARN_STRICT_PROTOTYPES = YES;
211
+ CLANG_WARN_SUSPICIOUS_MOVE = YES;
212
+ CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
213
+ CLANG_WARN_UNREACHABLE_CODE = YES;
214
+ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
215
+ CODE_SIGN_IDENTITY = "iPhone Developer";
216
+ COPY_PHASE_STRIP = NO;
217
+ DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
218
+ ENABLE_NS_ASSERTIONS = NO;
219
+ ENABLE_STRICT_OBJC_MSGSEND = YES;
220
+ GCC_C_LANGUAGE_STANDARD = gnu11;
221
+ GCC_NO_COMMON_BLOCKS = YES;
222
+ GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
223
+ GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
224
+ GCC_WARN_UNDECLARED_SELECTOR = YES;
225
+ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
226
+ GCC_WARN_UNUSED_FUNCTION = YES;
227
+ GCC_WARN_UNUSED_VARIABLE = YES;
228
+ IPHONEOS_DEPLOYMENT_TARGET = 7.0;
229
+ MTL_ENABLE_DEBUG_INFO = NO;
230
+ SDKROOT = iphoneos;
231
+ VALIDATE_PRODUCT = YES;
232
+ };
233
+ name = Release;
234
+ };
235
+ 910362DC1FE9318600F4DA8E /* Debug */ = {
236
+ isa = XCBuildConfiguration;
237
+ buildSettings = {
238
+ CODE_SIGN_STYLE = Automatic;
239
+ DEVELOPMENT_TEAM = 9H9696K6NL;
240
+ OTHER_LDFLAGS = "-ObjC";
241
+ PRODUCT_NAME = "$(TARGET_NAME)";
242
+ SKIP_INSTALL = YES;
243
+ TARGETED_DEVICE_FAMILY = "1,2";
244
+ };
245
+ name = Debug;
246
+ };
247
+ 910362DD1FE9318600F4DA8E /* Release */ = {
248
+ isa = XCBuildConfiguration;
249
+ buildSettings = {
250
+ CODE_SIGN_STYLE = Automatic;
251
+ DEVELOPMENT_TEAM = 9H9696K6NL;
252
+ OTHER_LDFLAGS = "-ObjC";
253
+ PRODUCT_NAME = "$(TARGET_NAME)";
254
+ SKIP_INSTALL = YES;
255
+ TARGETED_DEVICE_FAMILY = "1,2";
256
+ };
257
+ name = Release;
258
+ };
259
+ /* End XCBuildConfiguration section */
260
+
261
+ /* Begin XCConfigurationList section */
262
+ 910362CD1FE9318600F4DA8E /* Build configuration list for PBXProject "BottomSheet" */ = {
263
+ isa = XCConfigurationList;
264
+ buildConfigurations = (
265
+ 910362D91FE9318600F4DA8E /* Debug */,
266
+ 910362DA1FE9318600F4DA8E /* Release */,
267
+ );
268
+ defaultConfigurationIsVisible = 0;
269
+ defaultConfigurationName = Release;
270
+ };
271
+ 910362DB1FE9318600F4DA8E /* Build configuration list for PBXNativeTarget "BottomSheet" */ = {
272
+ isa = XCConfigurationList;
273
+ buildConfigurations = (
274
+ 910362DC1FE9318600F4DA8E /* Debug */,
275
+ 910362DD1FE9318600F4DA8E /* Release */,
276
+ );
277
+ defaultConfigurationIsVisible = 0;
278
+ defaultConfigurationName = Release;
279
+ };
280
+ /* End XCConfigurationList section */
281
+ };
282
+ rootObject = 910362CA1FE9318600F4DA8E /* Project object */;
283
+ }
package/lib/index.d.ts ADDED
@@ -0,0 +1,21 @@
1
+ import React from 'react';
2
+ import { NativeSyntheticEvent, ViewProps } from 'react-native';
3
+ export interface OffsetChangedEventData {
4
+ offset: number;
5
+ expandedOffset: number;
6
+ collapsedOffset: number;
7
+ }
8
+ export type BottomSheetState = 'collapsed' | 'expanded' | 'hidden';
9
+ export interface StateChangedEventData {
10
+ state: BottomSheetState;
11
+ }
12
+ interface NativeBottomSheetProps extends ViewProps {
13
+ onSlide?: (event: NativeSyntheticEvent<OffsetChangedEventData>) => void;
14
+ onStateChanged?: (event: NativeSyntheticEvent<StateChangedEventData>) => void;
15
+ peekHeight?: number;
16
+ state?: BottomSheetState;
17
+ }
18
+ declare const BottomSheet: React.ForwardRefExoticComponent<NativeBottomSheetProps & {
19
+ fitToContents?: boolean | undefined;
20
+ } & React.RefAttributes<React.Component<NativeBottomSheetProps, {}, any> & Readonly<import("react-native").NativeMethods>>>;
21
+ export default BottomSheet;
package/lib/index.js ADDED
@@ -0,0 +1,31 @@
1
+ import React from 'react';
2
+ import { Platform, requireNativeComponent, StyleSheet, View } from 'react-native';
3
+ import splitLayoutProps from './splitLayoutProps';
4
+ const NativeBottomSheet = requireNativeComponent('BottomSheet');
5
+ const BottomSheet = React.forwardRef((props, ref) => {
6
+ const { style, children, peekHeight = 200, state = 'collapsed', fitToContents, ...rest } = props;
7
+ const { outer, inner } = splitLayoutProps(StyleSheet.flatten(style));
8
+ if (Platform.OS === 'android') {
9
+ return (<NativeBottomSheet style={[StyleSheet.absoluteFill, outer]} peekHeight={peekHeight} state={state} {...rest} ref={ref}>
10
+ <View style={[fitToContents ? styles.fitToContents : StyleSheet.absoluteFill, inner]} collapsable={false}>
11
+ {children}
12
+ </View>
13
+ </NativeBottomSheet>);
14
+ }
15
+ else {
16
+ return (<View style={[StyleSheet.absoluteFill, outer]} pointerEvents="box-none">
17
+ <NativeBottomSheet style={[fitToContents ? styles.fitToContents : StyleSheet.absoluteFill, inner]} peekHeight={peekHeight} state={state} {...rest} ref={ref}>
18
+ {children}
19
+ </NativeBottomSheet>
20
+ </View>);
21
+ }
22
+ });
23
+ const styles = StyleSheet.create({
24
+ fitToContents: {
25
+ position: 'absolute',
26
+ left: 0,
27
+ right: 0,
28
+ bottom: 0,
29
+ },
30
+ });
31
+ export default BottomSheet;
@@ -0,0 +1,15 @@
1
+ import { ViewStyle } from 'react-native';
2
+ export default function splitLayoutProps(props?: ViewStyle): {
3
+ outer: {
4
+ [key: string]: string | number | import("react-native").OpaqueColorValue | {
5
+ width: number;
6
+ height: number;
7
+ } | (import("react-native").PerpectiveTransform | import("react-native").RotateTransform | import("react-native").RotateXTransform | import("react-native").RotateYTransform | import("react-native").RotateZTransform | import("react-native").ScaleTransform | import("react-native").ScaleXTransform | import("react-native").ScaleYTransform | import("react-native").TranslateXTransform | import("react-native").TranslateYTransform | import("react-native").SkewXTransform | import("react-native").SkewYTransform | import("react-native").MatrixTransform)[] | number[] | undefined;
8
+ };
9
+ inner: {
10
+ [key: string]: string | number | import("react-native").OpaqueColorValue | {
11
+ width: number;
12
+ height: number;
13
+ } | (import("react-native").PerpectiveTransform | import("react-native").RotateTransform | import("react-native").RotateXTransform | import("react-native").RotateYTransform | import("react-native").RotateZTransform | import("react-native").ScaleTransform | import("react-native").ScaleXTransform | import("react-native").ScaleYTransform | import("react-native").TranslateXTransform | import("react-native").TranslateYTransform | import("react-native").SkewXTransform | import("react-native").SkewYTransform | import("react-native").MatrixTransform)[] | number[] | undefined;
14
+ };
15
+ };
@@ -0,0 +1,41 @@
1
+ export default function splitLayoutProps(props) {
2
+ let outer = {};
3
+ let inner = {};
4
+ if (props != null) {
5
+ for (const prop of Object.keys(props)) {
6
+ switch (prop) {
7
+ case 'margin':
8
+ case 'marginHorizontal':
9
+ case 'marginVertical':
10
+ case 'marginBottom':
11
+ case 'marginTop':
12
+ case 'marginLeft':
13
+ case 'marginRight':
14
+ case 'flex':
15
+ case 'flexGrow':
16
+ case 'flexShrink':
17
+ case 'flexBasis':
18
+ case 'alignSelf':
19
+ case 'height':
20
+ case 'minHeight':
21
+ case 'maxHeight':
22
+ case 'width':
23
+ case 'minWidth':
24
+ case 'maxWidth':
25
+ case 'position':
26
+ case 'left':
27
+ case 'right':
28
+ case 'bottom':
29
+ case 'top':
30
+ case 'transform':
31
+ case 'zIndex':
32
+ outer[prop] = props[prop];
33
+ break;
34
+ default:
35
+ inner[prop] = props[prop];
36
+ break;
37
+ }
38
+ }
39
+ }
40
+ return { outer, inner };
41
+ }
package/package.json ADDED
@@ -0,0 +1,65 @@
1
+ {
2
+ "name": "@sdcx/bottom-sheet",
3
+ "description": "A react-native bottom sheet component",
4
+ "version": "0.1.0",
5
+ "main": "./lib/index.js",
6
+ "typings": "./lib/index.d.ts",
7
+ "react-native": "src/index",
8
+ "nativePackage": true,
9
+ "files": [
10
+ "src",
11
+ "lib",
12
+ "android",
13
+ "ios",
14
+ "RNBottomSheet.podspec",
15
+ "!android/build",
16
+ "!ios/build",
17
+ "!**/__tests__"
18
+ ],
19
+ "repository": "https://github.com/sdcxtech/react-native-troika",
20
+ "homepage": "https://github.com/sdcxtech/react-native-troika#readme",
21
+ "license": "MIT",
22
+ "keywords": [
23
+ "react-native",
24
+ "bottom-sheet"
25
+ ],
26
+ "scripts": {
27
+ "build": "rm -rf ./lib && tsc -p tsconfig.build.json",
28
+ "prepare": "npm run build",
29
+ "tsc": "tsc",
30
+ "test": "jest",
31
+ "lint": "eslint . --fix --ext .js,.jsx,.ts,.tsx"
32
+ },
33
+ "peerDependencies": {
34
+ "react": ">=16.8",
35
+ "react-native": ">=0.60"
36
+ },
37
+ "devDependencies": {
38
+ "@babel/core": "^7.13.10",
39
+ "@babel/runtime": "^7.13.10",
40
+ "@react-native-community/eslint-config": "^3.0.0",
41
+ "@types/jest": "^26.0.21",
42
+ "@types/react": "^17.0.2",
43
+ "@types/react-native": "^0.67.0",
44
+ "@types/react-test-renderer": "17.0.2",
45
+ "babel-jest": "^26.6.3",
46
+ "jest": "^26.6.3",
47
+ "metro-react-native-babel-preset": "^0.66.2",
48
+ "react": "17.0.2",
49
+ "react-native": "^0.67.4",
50
+ "react-test-renderer": "17.0.2",
51
+ "eslint": "^7.32.0",
52
+ "typescript": "^4.6.4"
53
+ },
54
+ "jest": {
55
+ "preset": "react-native",
56
+ "moduleFileExtensions": [
57
+ "ts",
58
+ "tsx",
59
+ "js",
60
+ "jsx",
61
+ "json",
62
+ "node"
63
+ ]
64
+ }
65
+ }
package/src/index.tsx ADDED
@@ -0,0 +1,74 @@
1
+ import React from 'react'
2
+ import { NativeSyntheticEvent, Platform, requireNativeComponent, StyleSheet, View, ViewProps } from 'react-native'
3
+ import splitLayoutProps from './splitLayoutProps'
4
+
5
+ export interface OffsetChangedEventData {
6
+ offset: number
7
+ expandedOffset: number
8
+ collapsedOffset: number
9
+ }
10
+
11
+ export type BottomSheetState = 'collapsed' | 'expanded' | 'hidden'
12
+
13
+ export interface StateChangedEventData {
14
+ state: BottomSheetState
15
+ }
16
+
17
+ interface NativeBottomSheetProps extends ViewProps {
18
+ onSlide?: (event: NativeSyntheticEvent<OffsetChangedEventData>) => void
19
+ onStateChanged?: (event: NativeSyntheticEvent<StateChangedEventData>) => void
20
+ peekHeight?: number
21
+ state?: BottomSheetState
22
+ }
23
+
24
+ type BottomSheetProps = NativeBottomSheetProps & {
25
+ fitToContents?: boolean
26
+ }
27
+
28
+ const NativeBottomSheet = requireNativeComponent<NativeBottomSheetProps>('BottomSheet')
29
+
30
+ type NativeBottomSheetInstance = InstanceType<typeof NativeBottomSheet>
31
+
32
+ const BottomSheet = React.forwardRef<NativeBottomSheetInstance, BottomSheetProps>((props, ref) => {
33
+ const { style, children, peekHeight = 200, state = 'collapsed', fitToContents, ...rest } = props
34
+ const { outer, inner } = splitLayoutProps(StyleSheet.flatten(style))
35
+
36
+ if (Platform.OS === 'android') {
37
+ return (
38
+ <NativeBottomSheet
39
+ style={[StyleSheet.absoluteFill, outer]}
40
+ peekHeight={peekHeight}
41
+ state={state}
42
+ {...rest}
43
+ ref={ref}>
44
+ <View style={[fitToContents ? styles.fitToContents : StyleSheet.absoluteFill, inner]} collapsable={false}>
45
+ {children}
46
+ </View>
47
+ </NativeBottomSheet>
48
+ )
49
+ } else {
50
+ return (
51
+ <View style={[StyleSheet.absoluteFill, outer]} pointerEvents="box-none">
52
+ <NativeBottomSheet
53
+ style={[fitToContents ? styles.fitToContents : StyleSheet.absoluteFill, inner]}
54
+ peekHeight={peekHeight}
55
+ state={state}
56
+ {...rest}
57
+ ref={ref}>
58
+ {children}
59
+ </NativeBottomSheet>
60
+ </View>
61
+ )
62
+ }
63
+ })
64
+
65
+ const styles = StyleSheet.create({
66
+ fitToContents: {
67
+ position: 'absolute',
68
+ left: 0,
69
+ right: 0,
70
+ bottom: 0,
71
+ },
72
+ })
73
+
74
+ export default BottomSheet
@@ -0,0 +1,47 @@
1
+ import { ViewStyle } from 'react-native'
2
+
3
+ type StyleKey = keyof ViewStyle
4
+
5
+ export default function splitLayoutProps(props?: ViewStyle) {
6
+ let outer: { [key: string]: ViewStyle[StyleKey] } = {}
7
+ let inner: { [key: string]: ViewStyle[StyleKey] } = {}
8
+
9
+ if (props != null) {
10
+ for (const prop of Object.keys(props) as StyleKey[]) {
11
+ switch (prop) {
12
+ case 'margin':
13
+ case 'marginHorizontal':
14
+ case 'marginVertical':
15
+ case 'marginBottom':
16
+ case 'marginTop':
17
+ case 'marginLeft':
18
+ case 'marginRight':
19
+ case 'flex':
20
+ case 'flexGrow':
21
+ case 'flexShrink':
22
+ case 'flexBasis':
23
+ case 'alignSelf':
24
+ case 'height':
25
+ case 'minHeight':
26
+ case 'maxHeight':
27
+ case 'width':
28
+ case 'minWidth':
29
+ case 'maxWidth':
30
+ case 'position':
31
+ case 'left':
32
+ case 'right':
33
+ case 'bottom':
34
+ case 'top':
35
+ case 'transform':
36
+ case 'zIndex':
37
+ outer[prop] = props[prop]
38
+ break
39
+ default:
40
+ inner[prop] = props[prop]
41
+ break
42
+ }
43
+ }
44
+ }
45
+
46
+ return { outer, inner }
47
+ }