Skip to content

Commit 9615b6a

Browse files
jr-km-bert
andauthored
Add rootContainerStyle prop to ReanimatedDrawerLayout (#3846)
**What this PR does** This PR adds a new `mainContainerStyle` prop to the main component. Until now, it was not possible to apply custom styles to the wrapper since it was fully controlled internally. By exposing this prop, consumers can now override or extend the wrapper's styles and apply absolute positioning or any other layout adjustment when needed. **Why** I needed to apply absolute positioning to the top-level wrapper but there was no way to customize it. Adding this prop keeps the existing default behavior while allowing more flexibility for advanced layout cases. **How** - Added the `mainContainerStyle` prop - Passed it directly to the `ReanimatedDrawerLayout` element - Ensured it merges cleanly with the component's default styling --------- Co-authored-by: Michał <michal.bert@swmansion.com>
1 parent 6ba9d63 commit 9615b6a

8 files changed

Lines changed: 45 additions & 20 deletions

File tree

packages/docs-gesture-handler/docs/components/reanimated-drawer-layout.mdx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,21 +108,29 @@ minSwipeDistance?: number;
108108

109109
Minimal distance to swipe before the drawer starts moving.
110110

111+
### rootContainerStyle
112+
113+
```ts
114+
rootContainerStyle?: StyleProp<ViewStyle>;
115+
```
116+
117+
Style applied to the outermost container that wraps both the content view and the drawer. Note that this container has `flex: 1` and `overflow: 'hidden'` applied by default.
118+
111119
### contentContainerStyle
112120

113121
```ts
114122
contentContainerStyle?: StyleProp<ViewStyle>;
115123
```
116124

117-
Style of the content view container.
125+
Style applied to the container wrapping the content view (the [`children`](#children)) and the background overlay.
118126

119127
### drawerContainerStyle
120128

121129
```ts
122130
drawerContainerStyle?: StyleProp<ViewStyle>;
123131
```
124132

125-
Style wrapping the drawer.
133+
Style applied to the container wrapping the drawer (the view returned by [`renderNavigationView`](#rendernavigationview)).
126134

127135
### edgeWidth
128136

packages/docs-gesture-handler/docs/fundamentals/_examples/hooks/Simultaneous.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import {
88
useSimultaneousGestures,
99
} from 'react-native-gesture-handler';
1010
import Animated, {
11-
useSharedValue,
1211
useAnimatedStyle,
12+
useSharedValue,
1313
} from 'react-native-reanimated';
1414

1515
export default function App() {

packages/docs-gesture-handler/src/components/CodeComparison/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import React from 'react';
2-
import CodeBlock from '@theme/CodeBlock';
31
import useFormattedCode from '@site/src/hooks/useFormattedCode';
2+
import CodeBlock from '@theme/CodeBlock';
3+
import React from 'react';
44

55
export default function CodeComparison({
66
label1,

packages/docs-gesture-handler/src/components/CollapseButton/index.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
/* eslint-disable import-x/extensions */
2-
import React from 'react';
3-
import styles from './styles.module.css';
2+
import { useColorMode } from '@docusaurus/theme-common';
43
import Arrow from '@site/static/img/Arrow.svg';
54
import ArrowDark from '@site/static/img/Arrow-dark.svg';
6-
import { useColorMode } from '@docusaurus/theme-common';
75
import clsx from 'clsx';
6+
import React from 'react';
7+
8+
import styles from './styles.module.css';
89

910
const CollapseButton: React.FC<{
1011
label: string;

packages/docs-gesture-handler/src/components/CollapsibleCode/index.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import React, { useState } from 'react';
2-
import CodeBlock from '@theme/CodeBlock';
3-
import styles from './styles.module.css';
4-
51
import CollapseButton from '@site/src/components/CollapseButton';
6-
72
import useFormattedCode from '@site/src/hooks/useFormattedCode';
3+
import CodeBlock from '@theme/CodeBlock';
4+
import React, { useState } from 'react';
5+
6+
import styles from './styles.module.css';
87
interface Props {
98
src: string;
109
label: string;

packages/docs-gesture-handler/src/components/Hero/StartScreen/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
import HomepageButton from '@site/src/components/HomepageButton';
12
import React from 'react';
3+
24
import styles from './styles.module.css';
3-
import HomepageButton from '@site/src/components/HomepageButton';
45

56
const StartScreen = () => {
67
return (

packages/docs-gesture-handler/src/hooks/useFormattedCode.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { useEffect, useState } from 'react';
2-
import * as prettier from 'prettier/standalone';
3-
import tsParser from 'prettier/plugins/typescript';
41
import estreeParser from 'prettier/plugins/estree';
2+
import tsParser from 'prettier/plugins/typescript';
3+
import * as prettier from 'prettier/standalone';
4+
import { useEffect, useState } from 'react';
55

66
const prettierOptions = {
77
parser: 'typescript',

packages/react-native-gesture-handler/src/components/ReanimatedDrawerLayout.tsx

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,15 +188,28 @@ export type DrawerLayoutProps = {
188188
overlayColor?: string;
189189

190190
/**
191-
* Style wrapping the content.
191+
* Style applied to the container wrapping the content view (the `children`)
192+
* and the background overlay.
192193
*/
193194
contentContainerStyle?: StyleProp<ViewStyle>;
194195

195196
/**
196-
* Style wrapping the drawer.
197+
* Style applied to the container wrapping the drawer (the view returned by
198+
* `renderNavigationView`).
197199
*/
198200
drawerContainerStyle?: StyleProp<ViewStyle>;
199201

202+
/**
203+
* Style applied to the outermost container that wraps both the content view
204+
* and the drawer.
205+
*/
206+
rootContainerStyle?: StyleProp<ViewStyle>;
207+
208+
/**
209+
* Called while the drawer is moving or animating, with a `position`
210+
* parameter indicating the progress of the opening/closing animation.
211+
* It equals `0` when the drawer is closed and `1` when it is fully opened.
212+
*/
200213
onDrawerSlide?: (position: number) => void;
201214

202215
// Implicit `children` prop has been removed in @types/react^18.0.
@@ -286,6 +299,7 @@ const DrawerLayout = function DrawerLayout(
286299
drawerType = defaultProps.drawerType,
287300
drawerBackgroundColor,
288301
drawerContainerStyle,
302+
rootContainerStyle,
289303
contentContainerStyle,
290304
minSwipeDistance = defaultProps.minSwipeDistance,
291305
edgeWidth = defaultProps.edgeWidth,
@@ -664,7 +678,9 @@ const DrawerLayout = function DrawerLayout(
664678
gesture={panGesture}
665679
userSelect={userSelect}
666680
enableContextMenu={enableContextMenu}>
667-
<Animated.View style={styles.main} onLayout={handleContainerLayout}>
681+
<Animated.View
682+
style={[styles.main, rootContainerStyle]}
683+
onLayout={handleContainerLayout}>
668684
<VirtualGestureDetector
669685
gesture={overlayDismissGesture}
670686
userSelect={userSelect}>

0 commit comments

Comments
 (0)