Skip to content

Commit 402aadb

Browse files
committed
Remove hooks
1 parent ad30413 commit 402aadb

File tree

2 files changed

+43
-48
lines changed

2 files changed

+43
-48
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-draggable-panel",
3-
"version": "1.2.0",
3+
"version": "1.2.1",
44
"description": "A react native draggable panel for Android and iOS",
55
"author": "Naoufal ELYOUSSOUFI <[email protected]> (https://github.com/nelyousfi)",
66
"main": "dist/index.js",

src/DraggablePanel.tsx

Lines changed: 42 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export const DraggablePanel = React.forwardRef<
7777
// eslint-disable-next-line react-hooks/exhaustive-deps
7878
}, [visible]);
7979

80-
const show = React.useCallback(() => {
80+
const show = () => {
8181
if (!animating) {
8282
animatedValue.setValue(0);
8383
setInnerContentHeight(Math.min(initialHeight, DEFAULT_PANEL_HEIGHT));
@@ -96,9 +96,9 @@ export const DraggablePanel = React.forwardRef<
9696
setAnimating(false);
9797
});
9898
}
99-
}, [animatedValue, animating, animationDuration, height, initialHeight]);
99+
};
100100

101-
const hide = React.useCallback(() => {
101+
const hide = () => {
102102
if (!animating) {
103103
setAnimating(true);
104104
Animated.timing(animatedValue, {
@@ -116,9 +116,9 @@ export const DraggablePanel = React.forwardRef<
116116
onDismiss && onDismiss();
117117
});
118118
}
119-
}, [animatedValue, animating, animationDuration, onDismiss]);
119+
};
120120

121-
const onBackButtonPress = React.useCallback(() => {
121+
const onBackButtonPress = () => {
122122
if (
123123
Platform.OS === 'android' &&
124124
hideOnBackButtonPressed &&
@@ -127,7 +127,7 @@ export const DraggablePanel = React.forwardRef<
127127
) {
128128
hide();
129129
}
130-
}, [hideOnBackButtonPressed, animating, popupVisible, hide]);
130+
};
131131

132132
React.useImperativeHandle<
133133
ReactNativeDraggablePanelRef,
@@ -137,51 +137,46 @@ export const DraggablePanel = React.forwardRef<
137137
hide,
138138
}));
139139

140-
const onScroll = React.useCallback(
141-
(event: NativeSyntheticEvent<NativeScrollEvent>) => {
142-
if (!animating) {
143-
const {y} = event.nativeEvent.contentOffset;
144-
if (
145-
!expandable &&
146-
y < SCREEN_HEIGHT - (SCREEN_HEIGHT * height) / DEFAULT_PANEL_HEIGHT
147-
) {
148-
return;
149-
}
150-
animatedValue.setValue(1 - Math.floor(y) / Math.floor(SCREEN_HEIGHT));
151-
// >= Fix the android issue, cause for some reason it goes for more than SCREEN_HEIGHT
152-
// if the use swipes faster
153-
if (Math.floor(y) >= Math.floor(SCREEN_HEIGHT)) {
154-
togglePopupVisibility(false);
155-
setAnimating(false);
156-
onDismiss && onDismiss();
157-
}
140+
const onScroll = (event: NativeSyntheticEvent<NativeScrollEvent>) => {
141+
if (!animating) {
142+
const {y} = event.nativeEvent.contentOffset;
143+
if (
144+
!expandable &&
145+
y < SCREEN_HEIGHT - (SCREEN_HEIGHT * height) / DEFAULT_PANEL_HEIGHT
146+
) {
147+
return;
158148
}
159-
},
160-
[animatedValue, animating, expandable, height, onDismiss],
161-
);
162-
163-
const onScrollBeginDrag = React.useCallback(
164-
(e: NativeSyntheticEvent<NativeScrollEvent>) => {
165-
if (e.nativeEvent.contentOffset.y !== 0 && expandable) {
166-
setInnerContentHeight(DEFAULT_PANEL_HEIGHT);
149+
animatedValue.setValue(1 - Math.floor(y) / Math.floor(SCREEN_HEIGHT));
150+
// >= Fix the android issue, cause for some reason it goes for more than SCREEN_HEIGHT
151+
// if the use swipes faster
152+
if (Math.floor(y) >= Math.floor(SCREEN_HEIGHT)) {
153+
togglePopupVisibility(false);
154+
setAnimating(false);
155+
onDismiss && onDismiss();
167156
}
168-
},
169-
[expandable],
170-
);
157+
}
158+
};
159+
160+
const onScrollBeginDrag = (
161+
event: NativeSyntheticEvent<NativeScrollEvent>,
162+
) => {
163+
if (event.nativeEvent.contentOffset.y !== 0 && expandable) {
164+
setInnerContentHeight(DEFAULT_PANEL_HEIGHT);
165+
}
166+
};
171167

172-
const onMomentumScrollEnd = React.useCallback(
173-
(e: NativeSyntheticEvent<NativeScrollEvent>) => {
174-
if (expandable) {
175-
const {y} = e.nativeEvent.contentOffset;
176-
if (y !== 0) {
177-
setInnerContentHeight(height);
178-
} else {
179-
setInnerContentHeight(DEFAULT_PANEL_HEIGHT);
180-
}
168+
const onMomentumScrollEnd = (
169+
event: NativeSyntheticEvent<NativeScrollEvent>,
170+
) => {
171+
if (expandable) {
172+
const {y} = event.nativeEvent.contentOffset;
173+
if (y !== 0) {
174+
setInnerContentHeight(height);
175+
} else {
176+
setInnerContentHeight(DEFAULT_PANEL_HEIGHT);
181177
}
182-
},
183-
[height, expandable],
184-
);
178+
}
179+
};
185180

186181
return (
187182
<Modal

0 commit comments

Comments
 (0)