Skip to content

Commit 416f9e9

Browse files
committed
fix types
1 parent cc7b8f3 commit 416f9e9

File tree

2 files changed

+30
-68
lines changed

2 files changed

+30
-68
lines changed

src/index.tsx

Lines changed: 29 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -273,36 +273,6 @@ export default forwardRef<ActionSheetRef, ActionSheetProps>(
273273
[animated, props.openAnimationConfig],
274274
);
275275

276-
// const keyboardAnimation = React.useCallback(
277-
// (shown = true) => {
278-
// const position = initialValue.current + actionSheetHeight.current;
279-
// const value =
280-
// position -
281-
// ((dimensionsRef.current?.height || 0) - keyboard.keyboardHeight);
282-
// if (!shown) {
283-
// animations.translateY.setValue(initialValue.current);
284-
// Animated.spring(animations.keyboardTranslate, {
285-
// toValue: 0,
286-
// friction: 10,
287-
// useNativeDriver: true,
288-
// }).start();
289-
// } else {
290-
// // animations.translateY.setValue(initialValue.current - value);
291-
// Animated.spring(animations.keyboardTranslate, {
292-
// toValue: -keyboard.keyboardHeight,
293-
// friction: 10,
294-
// useNativeDriver: true,
295-
// }).start(() => {
296-
// setTimeout(() => {
297-
// animations.translateY.setValue(initialValue.current);
298-
// }, 1);
299-
// });
300-
// }
301-
// },
302-
// // eslint-disable-next-line react-hooks/exhaustive-deps
303-
// [animated, props.openAnimationConfig, keyboard],
304-
// );
305-
306276
const opacityAnimation = React.useCallback(
307277
(opacity: number) => {
308278
Animated.timing(animations.opacity, {
@@ -365,43 +335,41 @@ export default forwardRef<ActionSheetRef, ActionSheetProps>(
365335
isModal && !props?.backgroundInteractionEnabled ? Modal : Animated.View;
366336

367337
useEffect(() => {
338+
let animationListener;
368339
if (drawUnderStatusBar || props.onChange) {
369-
animationListeners.current.translateY =
370-
animations.translateY.addListener(value => {
371-
const correctedValue =
372-
value.value > minTranslateValue.current ? value.value : 0;
373-
props?.onChange?.(correctedValue, actionSheetHeight.current);
374-
if (drawUnderStatusBar) {
375-
if (lock.current) return;
376-
const correctedHeight = keyboard.keyboardShown
377-
? dimensionsRef.current.height -
378-
(keyboard.keyboardHeight + safeAreaPaddings.current.bottom)
379-
: dimensionsRef.current.height -
380-
safeAreaPaddings.current.bottom;
381-
const correctedOffset = keyboard.keyboardShown
382-
? value.value - keyboard.keyboardHeight
383-
: value.value;
384-
385-
if (actionSheetHeight.current > correctedHeight - 1) {
386-
if (correctedOffset < 100) {
387-
animations.underlayTranslateY.setValue(
388-
Math.max(correctedOffset - 20, -20),
389-
);
390-
} else {
391-
//@ts-ignore
392-
if (animations.underlayTranslateY._value < 100) {
393-
animations.underlayTranslateY.setValue(100);
394-
}
340+
animationListener = animations.translateY.addListener(value => {
341+
const correctedValue =
342+
value.value > minTranslateValue.current ? value.value : 0;
343+
props?.onChange?.(correctedValue, actionSheetHeight.current);
344+
if (drawUnderStatusBar) {
345+
if (lock.current) return;
346+
const correctedHeight = keyboard.keyboardShown
347+
? dimensionsRef.current.height -
348+
(keyboard.keyboardHeight + safeAreaPaddings.current.bottom)
349+
: dimensionsRef.current.height - safeAreaPaddings.current.bottom;
350+
const correctedOffset = keyboard.keyboardShown
351+
? value.value - keyboard.keyboardHeight
352+
: value.value;
353+
354+
if (actionSheetHeight.current > correctedHeight - 1) {
355+
if (correctedOffset < 100) {
356+
animations.underlayTranslateY.setValue(
357+
Math.max(correctedOffset - 20, -20),
358+
);
359+
} else {
360+
//@ts-ignore
361+
if (animations.underlayTranslateY._value < 100) {
362+
animations.underlayTranslateY.setValue(100);
395363
}
396364
}
397365
}
398-
});
366+
}
367+
});
399368
}
369+
animationListeners.current.translateY = animationListener;
400370
return () => {
401-
animationListeners.current.translateY &&
402-
animations.translateY.removeListener(
403-
animationListeners.current.translateY,
404-
);
371+
animationListener &&
372+
animations.translateY.removeListener(animationListener);
405373
};
406374
// eslint-disable-next-line react-hooks/exhaustive-deps
407375
}, [props?.id, keyboard.keyboardShown, keyboard.keyboardHeight]);
@@ -1125,7 +1093,6 @@ export default forwardRef<ActionSheetRef, ActionSheetProps>(
11251093
]);
11261094

11271095
const onTouch = (event: GestureResponderEvent) => {
1128-
props.onTouchBackdrop?.(event);
11291096
onTouchBackdrop?.(event);
11301097
if (enableRouterBackNavigation && router.canGoBack()) {
11311098
router.goBack();
@@ -1148,7 +1115,6 @@ export default forwardRef<ActionSheetRef, ActionSheetProps>(
11481115

11491116
if (orientationChanged) isOrientationChanging.current = true;
11501117

1151-
11521118
actionSheetHeight.current =
11531119
event.nativeEvent.layout.height > dimensionsRef.current.height
11541120
? dimensionsRef.current.height

src/types.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import React from 'react';
22
import {
33
Animated,
44
GestureResponderEvent,
5-
65
LayoutRectangle,
76
TouchableOpacityProps,
87
ViewStyle,
@@ -57,7 +56,6 @@ export type ActionSheetRef<SheetId extends keyof Sheets = never> = {
5756
*/
5857
currentSnapIndex: () => number;
5958

60-
6159
/**
6260
* Used internally for scrollable views.
6361
*/
@@ -73,7 +71,7 @@ export type ActionSheetRef<SheetId extends keyof Sheets = never> = {
7371
/**
7472
* Disable or enable sheet keyboard handler.
7573
*/
76-
keyboardHandler: (enabled?: boolean) => void
74+
keyboardHandler: (enabled?: boolean) => void;
7775
};
7876

7977
export type ActionSheetProps<SheetId extends keyof Sheets = never> = {
@@ -387,8 +385,6 @@ export type ActionSheetProps<SheetId extends keyof Sheets = never> = {
387385

388386
onSnapIndexChange?: (index: number) => void;
389387

390-
onTouchBackdrop?: (event: GestureResponderEvent) => void;
391-
392388
/**
393389
* When `closable=false`, set this to true to not allow
394390
* sheet to go beyond minimum snap point position with drag.

0 commit comments

Comments
 (0)