@swmansion/react-native-bottom-sheet 0.6.3 → 0.7.0-next.2

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 @@
1
+ {"version":3,"file":"BottomSheetNativeComponent.d.ts","sourceRoot":"","sources":["../../../src/BottomSheetNativeComponent.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,YAAY,EACjB,KAAK,SAAS,EACf,MAAM,cAAc,CAAC;AAEtB,KAAK,YAAY,GAAG,QAAQ,CAAC;IAC3B,MAAM,EAAE,YAAY,CAAC,MAAM,CAAC;IAC5B,YAAY,EAAE,OAAO,CAAC;CACvB,CAAC,CAAC;AAEH,MAAM,WAAW,WAAY,SAAQ,SAAS;IAC5C,OAAO,EAAE,aAAa,CAAC,YAAY,CAAC,CAAC;IACrC,KAAK,EAAE,YAAY,CAAC,KAAK,CAAC;IAC1B,SAAS,EAAE,OAAO,CAAC;IACnB,aAAa,CAAC,EAAE,YAAY,CAAC,kBAAkB,CAC7C,QAAQ,CAAC;QAAE,KAAK,EAAE,YAAY,CAAC,KAAK,CAAA;KAAE,CAAC,CACxC,CAAC;IACF,gBAAgB,CAAC,EAAE,YAAY,CAAC,kBAAkB,CAChD,QAAQ,CAAC;QAAE,QAAQ,EAAE,YAAY,CAAC,MAAM,CAAA;KAAE,CAAC,CAC5C,CAAC;CACH;;AAED,wBAAsE"}
@@ -7,7 +7,7 @@ export { BottomSheetFlatList } from './BottomSheetFlatList';
7
7
  export type { BottomSheetFlatListProps } from './BottomSheetFlatList';
8
8
  export { BottomSheetScrollView } from './BottomSheetScrollView';
9
9
  export type { BottomSheetScrollViewProps } from './BottomSheetScrollView';
10
- export type { Detent, DetentValue } from './BottomSheetBase';
11
- export { programmatic } from './BottomSheetBase';
10
+ export type { Detent, DetentValue } from './bottomSheetUtils';
11
+ export { programmatic } from './bottomSheetUtils';
12
12
  export { bottomSheetScrollable } from './bottomSheetScrollable';
13
13
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,YAAY,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,YAAY,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAChE,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,YAAY,EAAE,wBAAwB,EAAE,MAAM,uBAAuB,CAAC;AACtE,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAChE,YAAY,EAAE,0BAA0B,EAAE,MAAM,yBAAyB,CAAC;AAC1E,YAAY,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,YAAY,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,YAAY,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAChE,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,YAAY,EAAE,wBAAwB,EAAE,MAAM,uBAAuB,CAAC;AACtE,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAChE,YAAY,EAAE,0BAA0B,EAAE,MAAM,yBAAyB,CAAC;AAC1E,YAAY,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@swmansion/react-native-bottom-sheet",
3
- "version": "0.6.3",
3
+ "version": "0.7.0-next.2",
4
4
  "description": "Provides bottom-sheet components for React Native.",
5
5
  "main": "./lib/module/index.js",
6
6
  "types": "./lib/typescript/src/index.d.ts",
@@ -108,6 +108,19 @@
108
108
  ]
109
109
  ]
110
110
  },
111
+ "codegenConfig": {
112
+ "name": "ReactNativeBottomSheetSpec",
113
+ "type": "all",
114
+ "jsSrcsDir": "src",
115
+ "ios": {
116
+ "componentProvider": {
117
+ "BottomSheetView": "BottomSheetComponentView"
118
+ }
119
+ },
120
+ "android": {
121
+ "javaPackageName": "com.swmansion.reactnativebottomsheet"
122
+ }
123
+ },
111
124
  "prettier": {
112
125
  "quoteProps": "consistent",
113
126
  "singleQuote": true,
@@ -0,0 +1 @@
1
+ module.exports = {};
@@ -1,8 +1,102 @@
1
- import type { BottomSheetCommonProps } from './BottomSheetBase';
2
- import { BottomSheetBase } from './BottomSheetBase';
1
+ import { useState, type ReactNode } from 'react';
2
+ import type { LayoutChangeEvent, StyleProp, ViewStyle } from 'react-native';
3
+ import { StyleSheet, View, useWindowDimensions } from 'react-native';
4
+ import { runOnUI, type SharedValue } from 'react-native-reanimated';
5
+ import { useSafeAreaInsets } from 'react-native-safe-area-context';
3
6
 
4
- export type BottomSheetProps = BottomSheetCommonProps;
7
+ import BottomSheetNativeComponent from './BottomSheetNativeComponent';
8
+ import { type Detent, resolveDetent } from './bottomSheetUtils';
9
+ export type { Detent, DetentValue } from './bottomSheetUtils';
10
+ export { programmatic } from './bottomSheetUtils';
5
11
 
6
- export const BottomSheet = (props: BottomSheetProps) => (
7
- <BottomSheetBase {...props} />
8
- );
12
+ export interface BottomSheetProps {
13
+ children: ReactNode;
14
+ style?: StyleProp<ViewStyle>;
15
+ detents?: Detent[];
16
+ index: number;
17
+ animateIn?: boolean;
18
+ onIndexChange?: (index: number) => void;
19
+ position?: SharedValue<number>;
20
+ }
21
+
22
+ export const BottomSheet = ({
23
+ children,
24
+ style,
25
+ detents = [0, 'max'],
26
+ index,
27
+ animateIn = true,
28
+ onIndexChange,
29
+ position,
30
+ }: BottomSheetProps) => {
31
+ const { height: screenHeight } = useWindowDimensions();
32
+ const insets = useSafeAreaInsets();
33
+ const maxHeight = screenHeight - insets.top;
34
+ const [contentHeight, setContentHeight] = useState(0);
35
+
36
+ const resolvedDetents = detents.map((detent) => {
37
+ const value = resolveDetent(detent, contentHeight, maxHeight);
38
+ return {
39
+ height: Math.max(0, Math.min(value, maxHeight)),
40
+ programmatic: isDetentProgrammatic(detent),
41
+ };
42
+ });
43
+
44
+ const handleSentinelLayout = (event: LayoutChangeEvent) => {
45
+ setContentHeight(event.nativeEvent.layout.y);
46
+ };
47
+
48
+ const clampedIndex = Math.max(0, Math.min(index, resolvedDetents.length - 1));
49
+ const isCollapsed = (resolvedDetents[clampedIndex]?.height ?? 0) === 0;
50
+ const sheetPointerEvents = isCollapsed ? 'none' : 'box-none';
51
+
52
+ const handleIndexChange = (event: { nativeEvent: { index: number } }) => {
53
+ onIndexChange?.(event.nativeEvent.index);
54
+ };
55
+
56
+ const handlePositionChange = (event: {
57
+ nativeEvent: { position: number };
58
+ }) => {
59
+ if (position !== undefined) {
60
+ const height = event.nativeEvent.position;
61
+ runOnUI(() => {
62
+ 'worklet';
63
+ position.set(height);
64
+ })();
65
+ }
66
+ };
67
+
68
+ return (
69
+ <View pointerEvents="box-none" style={StyleSheet.absoluteFill}>
70
+ <BottomSheetNativeComponent
71
+ pointerEvents={sheetPointerEvents}
72
+ style={[
73
+ {
74
+ position: 'absolute',
75
+ left: 0,
76
+ right: 0,
77
+ bottom: 0,
78
+ height: maxHeight,
79
+ },
80
+ style,
81
+ ]}
82
+ detents={resolvedDetents}
83
+ index={index}
84
+ animateIn={animateIn}
85
+ onIndexChange={handleIndexChange}
86
+ onPositionChange={handlePositionChange}
87
+ >
88
+ <View collapsable={false} style={{ flex: 1 }} pointerEvents="box-none">
89
+ {children}
90
+ <View onLayout={handleSentinelLayout} pointerEvents="none" />
91
+ </View>
92
+ </BottomSheetNativeComponent>
93
+ </View>
94
+ );
95
+ };
96
+
97
+ function isDetentProgrammatic(detent: Detent): boolean {
98
+ if (typeof detent === 'object' && detent !== null) {
99
+ return detent.programmatic === true;
100
+ }
101
+ return false;
102
+ }
@@ -0,0 +1,24 @@
1
+ import {
2
+ codegenNativeComponent,
3
+ type CodegenTypes,
4
+ type ViewProps,
5
+ } from 'react-native';
6
+
7
+ type NativeDetent = Readonly<{
8
+ height: CodegenTypes.Double;
9
+ programmatic: boolean;
10
+ }>;
11
+
12
+ export interface NativeProps extends ViewProps {
13
+ detents: ReadonlyArray<NativeDetent>;
14
+ index: CodegenTypes.Int32;
15
+ animateIn: boolean;
16
+ onIndexChange?: CodegenTypes.DirectEventHandler<
17
+ Readonly<{ index: CodegenTypes.Int32 }>
18
+ >;
19
+ onPositionChange?: CodegenTypes.DirectEventHandler<
20
+ Readonly<{ position: CodegenTypes.Double }>
21
+ >;
22
+ }
23
+
24
+ export default codegenNativeComponent<NativeProps>('BottomSheetView');
package/src/index.tsx CHANGED
@@ -7,6 +7,6 @@ export { BottomSheetFlatList } from './BottomSheetFlatList';
7
7
  export type { BottomSheetFlatListProps } from './BottomSheetFlatList';
8
8
  export { BottomSheetScrollView } from './BottomSheetScrollView';
9
9
  export type { BottomSheetScrollViewProps } from './BottomSheetScrollView';
10
- export type { Detent, DetentValue } from './BottomSheetBase';
11
- export { programmatic } from './BottomSheetBase';
10
+ export type { Detent, DetentValue } from './bottomSheetUtils';
11
+ export { programmatic } from './bottomSheetUtils';
12
12
  export { bottomSheetScrollable } from './bottomSheetScrollable';