Skip to content

Commit

Permalink
feat: wrapInGestureHandlerRootView prop
Browse files Browse the repository at this point in the history
  • Loading branch information
LukasFridmansky authored and Lipo11 committed Dec 27, 2023
1 parent 8d6b2d8 commit 046ce4b
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 7 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export default YourComponent;
`topOffset` | number | 0 | Determines the amount of space that the swipeable content will be offset from the top edge of window.
`containerProps` | ViewProps | | Additional props to be applied to the container.
`hideKeyboardOnShow` | boolean | true | Set to `true` if you want to hide keyboard on show modal if was opened.
`wrapInGestureHandlerRootView`| boolean | false | Set to `true` if you want to wrap content in to GestureHandlerRootView (required if you want to use modal inside react-native Modal component).
## Public Methods
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions src/components/SwipeModal/SwipeModal.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,8 @@ export default StyleSheet.create( {
flex: {
flex: 1,
},
rootView: {
flex: 1,
justifyContent: 'flex-end',
},
} );
17 changes: 13 additions & 4 deletions src/components/SwipeModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { View, Dimensions, LayoutChangeEvent } from 'react-native';
import Animated, {
useSharedValue, useAnimatedStyle, useAnimatedReaction, runOnJS, withTiming,
} from 'react-native-reanimated';
import { GestureDetector, ScrollView } from 'react-native-gesture-handler';
import { GestureDetector, GestureHandlerRootView, ScrollView } from 'react-native-gesture-handler';
import AnimatedModal from '../AnimatedModal';
import ModalScrollView from './scroll';
import { SwipeModalProps, SwipeModalPublicMethods } from '../../core/dto/swipeModalDTO';
Expand Down Expand Up @@ -55,6 +55,7 @@ const SwipeModal = forwardRef<SwipeModalPublicMethods, SwipeModalProps>( ( {
disableSwipe = false,
topOffset = 0,
containerProps,
wrapInGestureHandlerRootView,
...props
}, ref ) => {

Expand Down Expand Up @@ -232,11 +233,19 @@ const SwipeModal = forwardRef<SwipeModalPublicMethods, SwipeModalProps>( ( {

}

const content = (
<Animated.View style={!disableSwipe && animatedStyle} testID="swipeModal">
<GestureDetector gesture={gesture}>{modalChildren}</GestureDetector>
</Animated.View>
);

return (
<AnimatedModal ref={modalRef} {...props}>
<Animated.View style={!disableSwipe && animatedStyle} testID="swipeModal">
<GestureDetector gesture={gesture}>{modalChildren}</GestureDetector>
</Animated.View>
{wrapInGestureHandlerRootView ? (
<GestureHandlerRootView style={SwipeModalStyles.rootView}>
{content}
</GestureHandlerRootView>
) : content}
</AnimatedModal>
);

Expand Down
1 change: 1 addition & 0 deletions src/core/dto/swipeModalDTO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export interface SwipeModalProps extends AnimatedModalProps {
disableSwipe?: boolean;
topOffset?: number;
containerProps?: ViewProps;
wrapInGestureHandlerRootView?: boolean;
}

export type SwipeModalPublicMethods = {
Expand Down

0 comments on commit 046ce4b

Please sign in to comment.