Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ const YourComponent = () => {

More Examples: https://github.com/paufau/react-native-multiple-modals-examples

---

## Properties

### `contentContainerStyle?: ViewStyle`
Expand Down Expand Up @@ -90,9 +92,3 @@ Use to change the modals's rendering area. May be useful for foldable devices.
Default: Dimensions.get('screen')

---

## Integrations

### react-native-gesture-handler

Wrap your content with `<GestureHandlerRootView> ... </GestureHandlerRootView>` to make gestures work inside a modal
51 changes: 27 additions & 24 deletions src/ModalView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
} from 'react-native';

import { ScrollContextResetter } from './ScrollContextResetter';
import { GestureHandlerRootView } from './integrations/GestureHandlerRootView';
import RNTModalView from './newarch/RNTModalViewNativeComponent';
import { useScreenDimensions } from './useScreenDimensions';

Expand Down Expand Up @@ -58,31 +59,33 @@ export const ModalView: FC<ModalViewProps> = ({
}
>
<View collapsable={false}>
<View style={fullScreenStyle}>
{renderBackdrop ? (
renderBackdrop()
) : (
<Pressable
accessibilityLabel={backdropAccessibilityLabel}
accessibilityHint={backdropAccessibilityHint}
{...backdropProps}
onPress={() => onRequestDismiss?.(DismissalSource.Backdrop)}
style={[styles.defaultBackdrop, backdropProps?.style]}
/>
)}
</View>
<ScrollContextResetter>
<View
pointerEvents='box-none'
style={[
preferredContainerSize,
styles.content,
contentContainerStyle,
]}
>
{children}
<GestureHandlerRootView>
<View style={fullScreenStyle}>
{renderBackdrop ? (
renderBackdrop()
) : (
<Pressable
accessibilityLabel={backdropAccessibilityLabel}
accessibilityHint={backdropAccessibilityHint}
{...backdropProps}
onPress={() => onRequestDismiss?.(DismissalSource.Backdrop)}
style={[styles.defaultBackdrop, backdropProps?.style]}
/>
)}
</View>
</ScrollContextResetter>
<ScrollContextResetter>
<View
pointerEvents='box-none'
style={[
preferredContainerSize,
styles.content,
contentContainerStyle,
]}
>
{children}
</View>
</ScrollContextResetter>
</GestureHandlerRootView>
</View>
</RNTModalView>
</View>
Expand Down
37 changes: 37 additions & 0 deletions src/integrations/GestureHandlerRootView.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/* eslint-disable no-console */
/* eslint-disable @typescript-eslint/no-require-imports */
/* eslint-disable @typescript-eslint/no-var-requires */
/* eslint-disable import/no-unused-modules */
/* eslint-disable global-require */

import { ReactNode } from 'react';

// The library is connected if it is detected at runtime.
// By default, gestures do not work inside a modal window.
const importGestureHandlerRootView = () => {
const Errors = {
GestureHandlerRootViewNotFound: new Error(
'GestureHandlerRootView not found. Please report the issue: https://github.com/paufau/react-native-multiple-modals/issues',
),
};

try {
const GestureHandlerRootViewComponent =
require('react-native-gesture-handler').GestureHandlerRootView;

if (!GestureHandlerRootViewComponent) {
throw Errors.GestureHandlerRootViewNotFound;
}

return GestureHandlerRootViewComponent;
} catch (e) {
if (e === Errors.GestureHandlerRootViewNotFound) {
console.error(e);
}

// Fallback component used if the library is not found
return ({ children }: { children: ReactNode }) => children;
}
};

export const GestureHandlerRootView = importGestureHandlerRootView();