Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v5] OnPress backdrop is not working on web #1446

Closed
devoren opened this issue Jul 16, 2023 · 13 comments
Closed

[v5] OnPress backdrop is not working on web #1446

devoren opened this issue Jul 16, 2023 · 13 comments
Labels
bug Something isn't working

Comments

@devoren
Copy link

devoren commented Jul 16, 2023

Bug

Im using BottomSheetModal on web and it works fine! But when press backdrop is not working on web

Environment info

Library Version
@gorhom/bottom-sheet ^5.0.0-alpha.2
react-native 0.72.3
react-native-reanimated ~3.3.0
react-native-gesture-handler ~2.12.0

Steps To Reproduce

  1. Create bottomsheet component using modal
  2. Add backdropComponent
  3. Run it on web

Describe what you expected to happen:

  1. When i press backdrop closes modal

Reproducible sample code

const bottomSheetModalRef = useRef<BottomSheetModal>(null);
const snapPoints = useMemo(() => ['50%'], []);

const renderBackdrop = useCallback(
(props: BottomSheetBackdropProps) => (
	<BottomSheetBackdrop
		{...props}
		disappearsOnIndex={-1}
		appearsOnIndex={0}
		pressBehavior={'close'}
		onPress={dismissModal}
	/>
),
[],
);
	
<BottomSheetModal
		ref={bottomSheetModalRef}
		index={0}
		snapPoints={snapPoints}
		backdropComponent={renderBackdrop}
		handleComponent={null}
		enableOverDrag={false}
		enablePanDownToClose={false}
		backgroundStyle={{
			borderRadius: isAndroid ? 0 : 15,
		}}
		containerStyle={{
			maxWidth: window.width,
			marginHorizontal: isDesktop ? 'auto' : 0,
		}}>
		<BottomSheetView style={{ flex: 1 }}>
		</BottomSheetView>
	</BottomSheetModal>
@devoren devoren added the bug Something isn't working label Jul 16, 2023
@oliviercperrier
Copy link

oliviercperrier commented Jul 25, 2023

My backdrop isnt even rendering on web

@devoren
Copy link
Author

devoren commented Jul 25, 2023

@oliviercperrier are you using alpha or v4?

@devoren
Copy link
Author

devoren commented Jul 31, 2023

@gorhom Hi, can we change TapGestureHandler to GestureDetector from 'react-native-gesture-handler >= v2.0.0'? So instead useAnimatedGestureHandler we use Gesture.Tap(). If we use new GestureDetector API, backdrop press works on native and web in v5

diff --git a/node_modules/@gorhom/bottom-sheet/lib/module/components/bottomSheetBackdrop/BottomSheetBackdrop.js b/node_modules/@gorhom/bottom-sheet/lib/module/components/bottomSheetBackdrop/BottomSheetBackdrop.js
index d8a0d1c..b5ae4df 100644
--- a/node_modules/@gorhom/bottom-sheet/lib/module/components/bottomSheetBackdrop/BottomSheetBackdrop.js
+++ b/node_modules/@gorhom/bottom-sheet/lib/module/components/bottomSheetBackdrop/BottomSheetBackdrop.js
@@ -1,6 +1,6 @@
 import React, { memo, useCallback, useMemo, useState } from 'react';
 import Animated, { interpolate, Extrapolate, useAnimatedStyle, useAnimatedReaction, useAnimatedGestureHandler, runOnJS } from 'react-native-reanimated';
-import { TapGestureHandler } from 'react-native-gesture-handler';
+import { Gesture, TapGestureHandler, GestureDetector } from 'react-native-gesture-handler';
 import { useBottomSheet } from '../../hooks';
 import { DEFAULT_OPACITY, DEFAULT_APPEARS_ON_INDEX, DEFAULT_DISAPPEARS_ON_INDEX, DEFAULT_ENABLE_TOUCH_THROUGH, DEFAULT_PRESS_BEHAVIOR } from './constants';
 import { styles } from './styles';
@@ -58,6 +58,16 @@ const BottomSheetBackdropComponent = _ref => {
   }, [handleOnPress]);
   //#endregion
 
+  //#region tap gesture
+  const gesture = useMemo(
+    () =>
+      Gesture.Tap().onEnd(() => {
+        runOnJS(handleOnPress)();
+      }),
+    [handleOnPress]
+  );
+  //#endregion
+
   //#region styles
   const containerAnimatedStyle = useAnimatedStyle(() => ({
     opacity: interpolate(animatedIndex.value, [-1, disappearsOnIndex, appearsOnIndex], [0, 0, opacity], Extrapolate.CLAMP),
@@ -75,8 +85,8 @@ const BottomSheetBackdropComponent = _ref => {
   }, [disappearsOnIndex]);
   //#endregion
 
-  return pressBehavior !== 'none' ? /*#__PURE__*/React.createElement(TapGestureHandler, {
-    onGestureEvent: gestureHandler
+  return pressBehavior !== 'none' ? /*#__PURE__*/React.createElement(GestureDetector, {
+    gesture: gesture
   }, /*#__PURE__*/React.createElement(Animated.View, {
     style: containerStyle,
     pointerEvents: pointerEvents,
diff --git a/node_modules/@gorhom/bottom-sheet/src/components/bottomSheetBackdrop/BottomSheetBackdrop.tsx b/node_modules/@gorhom/bottom-sheet/src/components/bottomSheetBackdrop/BottomSheetBackdrop.tsx
index 35597ce..de2aad1 100644
--- a/node_modules/@gorhom/bottom-sheet/src/components/bottomSheetBackdrop/BottomSheetBackdrop.tsx
+++ b/node_modules/@gorhom/bottom-sheet/src/components/bottomSheetBackdrop/BottomSheetBackdrop.tsx
@@ -9,8 +9,8 @@ import Animated, {
   runOnJS,
 } from 'react-native-reanimated';
 import {
-  TapGestureHandler,
-  TapGestureHandlerGestureEvent,
+  Gesture,
+  GestureDetector,
 } from 'react-native-gesture-handler';
 import { useBottomSheet } from '../../hooks';
 import {
@@ -74,17 +74,16 @@ const BottomSheetBackdropComponent = ({
   //#endregion
 
   //#region tap gesture
-  const gestureHandler =
-    useAnimatedGestureHandler<TapGestureHandlerGestureEvent>(
-      {
-        onFinish: () => {
-          runOnJS(handleOnPress)();
-        },
-      },
-      [handleOnPress]
-    );
+  const gesture = useMemo(
+    () =>
+      Gesture.Tap().onEnd(() => {
+        runOnJS(handleOnPress)();
+      }),
+    [handleOnPress]
+  );
   //#endregion
 
+
   //#region styles
   const containerAnimatedStyle = useAnimatedStyle(() => ({
     opacity: interpolate(
@@ -114,22 +113,20 @@ const BottomSheetBackdropComponent = ({
   );
   //#endregion
 
-  return pressBehavior !== 'none' ? (
-    <TapGestureHandler onGestureEvent={gestureHandler}>
-      <Animated.View
-        style={containerStyle}
-        pointerEvents={pointerEvents}
-        accessible={true}
-        accessibilityRole="button"
-        accessibilityLabel="Bottom Sheet backdrop"
-        accessibilityHint={`Tap to ${
-          typeof pressBehavior === 'string' ? pressBehavior : 'move'
-        } the Bottom Sheet`}
-      >
-        {children}
-      </Animated.View>
-    </TapGestureHandler>
-  ) : (
+  return pressBehavior !== 'none' ? <GestureDetector gesture={gesture}>
+  <Animated.View
+    style={containerStyle}
+    pointerEvents={pointerEvents}
+    accessible={true}
+    accessibilityRole="button"
+    accessibilityLabel="Bottom Sheet backdrop web"
+    accessibilityHint={`Tap to ${
+      typeof pressBehavior === 'string' ? pressBehavior : 'move'
+    } the Bottom Sheet`}
+  >
+    {children}
+  </Animated.View>
+</GestureDetector> : (
     <Animated.View pointerEvents={pointerEvents} style={containerStyle}>
       {children}
     </Animated.View>

@github-actions
Copy link

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

@devoren
Copy link
Author

devoren commented Aug 31, 2023

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

Still waiting for updates

@github-actions
Copy link

github-actions bot commented Oct 2, 2023

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

@devoren
Copy link
Author

devoren commented Oct 2, 2023

I'm waiting for PR #1467

Copy link

github-actions bot commented Nov 3, 2023

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

@devoren
Copy link
Author

devoren commented Nov 3, 2023

waiting for PR #1467

Copy link

github-actions bot commented Dec 5, 2023

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

@devoren
Copy link
Author

devoren commented Dec 5, 2023

Still waiting for updates

@gorhom
Copy link
Owner

gorhom commented Jan 3, 2024

this should be fixed with alpha.6, thanks for reporting it

@gorhom gorhom closed this as completed Jan 3, 2024
@jerone
Copy link

jerone commented Apr 8, 2024

@gorhom commented on Jan 3, 2024, 9:37 PM GMT+1:

this should be fixed with alpha.6, thanks for reporting it

I'm having the same issue. When will there be an official release?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants