Skip to content

Commit d41eda2

Browse files
authored
chore: fixed types (#1123)(by @stropho)
* fix: react 18 types * fix: allow providing whatever version of react types the library consumer needs as optional peer dependecies
1 parent 54abf0c commit d41eda2

File tree

7 files changed

+44
-23
lines changed

7 files changed

+44
-23
lines changed

package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,21 @@
6767
"typescript": "^4.2.4"
6868
},
6969
"peerDependencies": {
70+
"@types/react": "*",
71+
"@types/react-native": "*",
7072
"react": "*",
7173
"react-native": "*",
7274
"react-native-gesture-handler": ">=1.10.1",
7375
"react-native-reanimated": ">=2.2.0"
7476
},
77+
"peerDependenciesMeta": {
78+
"@types/react-native": {
79+
"optional": true
80+
},
81+
"@types/react": {
82+
"optional": true
83+
}
84+
},
7585
"react-native-builder-bob": {
7686
"source": "src",
7787
"output": "lib",

src/components/bottomSheet/types.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,9 +283,9 @@ export interface BottomSheetProps
283283
footerComponent?: React.FC<BottomSheetFooterProps>;
284284
/**
285285
* A scrollable node or normal view.
286-
* @type React.ReactNode[] | React.ReactNode
286+
* @type (() => React.ReactElement) | React.ReactNode[] | React.ReactNode
287287
*/
288-
children: (() => React.ReactNode) | React.ReactNode[] | React.ReactNode;
288+
children: (() => React.ReactElement) | React.ReactNode[] | React.ReactNode;
289289
//#endregion
290290

291291
//#region private

src/components/bottomSheetFooter/types.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { ReactNode } from 'react';
1+
import type { ReactElement, ReactNode } from 'react';
22
import { ViewStyle } from 'react-native';
33
import type Animated from 'react-native-reanimated';
44

@@ -31,7 +31,7 @@ export interface BottomSheetDefaultFooterProps extends BottomSheetFooterProps {
3131
/**
3232
* Component to be placed in the footer.
3333
*
34-
* @type {ReactNode | ReactNode[]}
34+
* @type {ReactNode | ReactNode[] | (() => ReactElement)}
3535
*/
36-
children?: ReactNode | ReactNode[];
36+
children?: ReactNode | ReactNode[] | (() => ReactElement);
3737
}

src/components/bottomSheetModal/BottomSheetModal.tsx

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -142,30 +142,36 @@ const BottomSheetModalComponent = forwardRef<
142142
}
143143
bottomSheetRef.current?.snapToPosition(...args);
144144
}, []);
145-
const handleExpand = useCallback((...args) => {
145+
const handleExpand = useCallback<BottomSheetMethods['expand']>((...args) => {
146146
if (minimized.current) {
147147
return;
148148
}
149149
bottomSheetRef.current?.expand(...args);
150150
}, []);
151-
const handleCollapse = useCallback((...args) => {
152-
if (minimized.current) {
153-
return;
154-
}
155-
bottomSheetRef.current?.collapse(...args);
156-
}, []);
157-
const handleClose = useCallback((...args) => {
151+
const handleCollapse = useCallback<BottomSheetMethods['collapse']>(
152+
(...args) => {
153+
if (minimized.current) {
154+
return;
155+
}
156+
bottomSheetRef.current?.collapse(...args);
157+
},
158+
[]
159+
);
160+
const handleClose = useCallback<BottomSheetMethods['close']>((...args) => {
158161
if (minimized.current) {
159162
return;
160163
}
161164
bottomSheetRef.current?.close(...args);
162165
}, []);
163-
const handleForceClose = useCallback((...args) => {
164-
if (minimized.current) {
165-
return;
166-
}
167-
bottomSheetRef.current?.forceClose(...args);
168-
}, []);
166+
const handleForceClose = useCallback<BottomSheetMethods['forceClose']>(
167+
(...args) => {
168+
if (minimized.current) {
169+
return;
170+
}
171+
bottomSheetRef.current?.forceClose(...args);
172+
},
173+
[]
174+
);
169175
//#endregion
170176

171177
//#region bottom sheet modal methods

src/components/bottomSheetModal/types.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ export interface BottomSheetModalProps
4444

4545
/**
4646
* A scrollable node or normal view.
47-
* @type React.ReactNode[] | React.ReactNode
47+
* @type React.ReactNode[] | React.ReactNode | (({ data: any }?) => React.ReactElement)
4848
*/
4949
children:
50-
| (({ data: any }?) => React.ReactNode)
50+
| (({ data: any }?) => React.ReactElement)
5151
| React.ReactNode[]
5252
| React.ReactNode;
5353
}

src/hooks/useBottomSheetDynamicSnapPoints.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,18 @@ export const useBottomSheetDynamicSnapPoints = (
3939
);
4040
}, []);
4141

42+
type HandleContentLayoutProps = {
43+
nativeEvent: {
44+
layout: { height: number };
45+
};
46+
};
4247
// callbacks
4348
const handleContentLayout = useCallback(
4449
({
4550
nativeEvent: {
4651
layout: { height },
4752
},
48-
}) => {
53+
}: HandleContentLayoutProps) => {
4954
animatedContentHeight.value = height;
5055
},
5156
[animatedContentHeight]

src/hooks/useStableCallback.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ type Callback = (...args: any[]) => any;
88
export const useStableCallback = (callback: Callback) => {
99
const callbackRef = useRef<Callback>();
1010
const memoCallback = useCallback(
11-
(...args) => callbackRef.current && callbackRef.current(...args),
11+
(...args: any) => callbackRef.current && callbackRef.current(...args),
1212
[]
1313
);
1414
useEffect(() => {

0 commit comments

Comments
 (0)