Skip to content

Commit 822c19f

Browse files
authored
Merge pull request #13 from nelyousfi/1.2.1
1.2.1
2 parents ad30413 + d61b656 commit 822c19f

File tree

3 files changed

+55
-51
lines changed

3 files changed

+55
-51
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,11 @@ render () {
6363
| visible | boolean | false | Controls the panel's visibility |
6464
| animationDuration | number | 500 | Controls the duration in ms to show or hide the panel |
6565
| expandable | boolean | false | Controls if the panel can be expanded or not |
66+
| hideable | boolean | true | Controls if the panel can be hidden when press outside or on the android physical back button |
6667
| hideOnPressOutside | boolean | true | Controls neither to hide the panel when user presses on the overlay or not |
6768
| overlayBackgroundColor | Color | black | Controls the backgroundColor of the overlay |
6869
| overlayOpacity | number | 0.8 | Is a value between 0 and 1 that controls the overlay opacity |
6970
| borderRadius | number | 0 | Controls the panel top border radius |
70-
| initialHeight | number | SCREEN_HEIGHT / 2 | Controls the panel initial height |
71+
| initialHeight | number | SCREEN_HEIGHT / 2 | Controls the panel initial height |
7172
| hideOnBackButtonPressed | boolean | true | Controls either the panel get dismissed on android physical button pressed or not [Android ONLY] |
7273
| onDismiss | callback | | A callback function when the panel is dismissed |

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: 52 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ type Props = {
2626
visible?: boolean;
2727
animationDuration?: number;
2828
expandable?: boolean;
29+
hideable?: boolean;
2930
hideOnPressOutside?: boolean;
3031
overlayBackgroundColor?: string;
3132
overlayOpacity?: number;
@@ -50,20 +51,26 @@ export const DraggablePanel = React.forwardRef<
5051
borderRadius = 0,
5152
initialHeight = DEFAULT_PANEL_HEIGHT / 2,
5253
hideOnBackButtonPressed = true,
54+
hideable = true,
5355
onDismiss,
5456
children,
5557
}: Props,
5658
ref: React.Ref<ReactNativeDraggablePanelRef>,
5759
) => {
5860
const [animatedValue] = React.useState(new Animated.Value(0));
61+
5962
const [popupVisible, togglePopupVisibility] = React.useState(false);
63+
6064
const [animating, setAnimating] = React.useState(false);
65+
6166
const [height] = React.useState(
6267
Math.min(initialHeight, DEFAULT_PANEL_HEIGHT),
6368
);
69+
6470
const [innerContentHeight, setInnerContentHeight] = React.useState(
6571
Math.min(initialHeight, DEFAULT_PANEL_HEIGHT),
6672
);
73+
6774
const scrollViewRef: RefObject<ScrollView> = React.useRef(null);
6875

6976
React.useEffect(() => {
@@ -77,7 +84,7 @@ export const DraggablePanel = React.forwardRef<
7784
// eslint-disable-next-line react-hooks/exhaustive-deps
7885
}, [visible]);
7986

80-
const show = React.useCallback(() => {
87+
const show = () => {
8188
if (!animating) {
8289
animatedValue.setValue(0);
8390
setInnerContentHeight(Math.min(initialHeight, DEFAULT_PANEL_HEIGHT));
@@ -96,9 +103,9 @@ export const DraggablePanel = React.forwardRef<
96103
setAnimating(false);
97104
});
98105
}
99-
}, [animatedValue, animating, animationDuration, height, initialHeight]);
106+
};
100107

101-
const hide = React.useCallback(() => {
108+
const hide = () => {
102109
if (!animating) {
103110
setAnimating(true);
104111
Animated.timing(animatedValue, {
@@ -116,18 +123,19 @@ export const DraggablePanel = React.forwardRef<
116123
onDismiss && onDismiss();
117124
});
118125
}
119-
}, [animatedValue, animating, animationDuration, onDismiss]);
126+
};
120127

121-
const onBackButtonPress = React.useCallback(() => {
128+
const onBackButtonPress = () => {
122129
if (
123130
Platform.OS === 'android' &&
124131
hideOnBackButtonPressed &&
125132
!animating &&
126-
popupVisible
133+
popupVisible &&
134+
hideable
127135
) {
128136
hide();
129137
}
130-
}, [hideOnBackButtonPressed, animating, popupVisible, hide]);
138+
};
131139

132140
React.useImperativeHandle<
133141
ReactNativeDraggablePanelRef,
@@ -137,51 +145,46 @@ export const DraggablePanel = React.forwardRef<
137145
hide,
138146
}));
139147

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-
}
148+
const onScroll = (event: NativeSyntheticEvent<NativeScrollEvent>) => {
149+
if (!animating) {
150+
const {y} = event.nativeEvent.contentOffset;
151+
if (
152+
!expandable &&
153+
y < SCREEN_HEIGHT - (SCREEN_HEIGHT * height) / DEFAULT_PANEL_HEIGHT
154+
) {
155+
return;
158156
}
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);
157+
animatedValue.setValue(1 - Math.floor(y) / Math.floor(SCREEN_HEIGHT));
158+
// >= Fix the android issue, cause for some reason it goes for more than SCREEN_HEIGHT
159+
// if the use swipes faster
160+
if (Math.floor(y) >= Math.floor(SCREEN_HEIGHT)) {
161+
togglePopupVisibility(false);
162+
setAnimating(false);
163+
onDismiss && onDismiss();
167164
}
168-
},
169-
[expandable],
170-
);
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 onScrollBeginDrag = (
169+
event: NativeSyntheticEvent<NativeScrollEvent>,
170+
) => {
171+
if (event.nativeEvent.contentOffset.y !== 0 && expandable) {
172+
setInnerContentHeight(DEFAULT_PANEL_HEIGHT);
173+
}
174+
};
175+
176+
const onMomentumScrollEnd = (
177+
event: NativeSyntheticEvent<NativeScrollEvent>,
178+
) => {
179+
if (expandable) {
180+
const {y} = event.nativeEvent.contentOffset;
181+
if (y !== 0) {
182+
setInnerContentHeight(height);
183+
} else {
184+
setInnerContentHeight(DEFAULT_PANEL_HEIGHT);
181185
}
182-
},
183-
[height, expandable],
184-
);
186+
}
187+
};
185188

186189
return (
187190
<Modal
@@ -218,7 +221,7 @@ export const DraggablePanel = React.forwardRef<
218221
SCREEN_HEIGHT,
219222
]}>
220223
<TouchableWithoutFeedback
221-
disabled={!hideOnPressOutside || animating}
224+
disabled={!hideOnPressOutside || animating || !hideable}
222225
onPress={hide}>
223226
<View style={styles.hideContainer} />
224227
</TouchableWithoutFeedback>

0 commit comments

Comments
 (0)