Skip to content

Commit d3275b1

Browse files
committed
fix(#2364): fixed layouting issue when dynamic sizing enabled and handle is not provided
1 parent 513655c commit d3275b1

File tree

6 files changed

+29
-17
lines changed

6 files changed

+29
-17
lines changed

example/src/screens/advanced/BackdropExample.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import React, { useCallback, useMemo, useRef, useState } from 'react';
2-
import { View, StyleSheet } from 'react-native';
31
import BottomSheet, { BottomSheetBackdrop } from '@gorhom/bottom-sheet';
2+
import React, { useCallback, useMemo, useRef, useState } from 'react';
3+
import { StyleSheet, View } from 'react-native';
44
import { Button } from '../../components/button';
55
import { ContactList } from '../../components/contactList';
66
import { HeaderHandle } from '../../components/headerHandle';
@@ -65,6 +65,7 @@ const BackdropExample = () => {
6565
snapPoints={snapPoints}
6666
backdropComponent={renderBackdrop}
6767
handleComponent={renderHeaderHandle}
68+
enableDynamicSizing={false}
6869
>
6970
<ContactList type="FlatList" count={10} />
7071
</BottomSheet>

src/components/bottomSheet/BottomSheet.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,10 @@ import { BottomSheetBackgroundContainer } from '../bottomSheetBackground';
5858
// import BottomSheetDebugView from '../bottomSheetDebugView';
5959
import { BottomSheetFooterContainer } from '../bottomSheetFooter';
6060
import BottomSheetGestureHandlersProvider from '../bottomSheetGestureHandlersProvider';
61-
import { BottomSheetHandleContainer } from '../bottomSheetHandle';
61+
import {
62+
BottomSheetHandle,
63+
BottomSheetHandleContainer,
64+
} from '../bottomSheetHandle';
6265
import { BottomSheetHostingContainer } from '../bottomSheetHostingContainer';
6366
import { BottomSheetBody } from './BottomSheetBody';
6467
import { BottomSheetContent } from './BottomSheetContent';
@@ -152,7 +155,7 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
152155
detached = false,
153156

154157
// components
155-
handleComponent,
158+
handleComponent = BottomSheetHandle,
156159
backdropComponent: BackdropComponent,
157160
backgroundComponent,
158161
footerComponent,
@@ -187,7 +190,8 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
187190
containerLayoutState,
188191
topInset,
189192
bottomInset,
190-
$modal
193+
$modal,
194+
handleComponent === null
191195
);
192196
const animatedDetentsState = useAnimatedDetents(
193197
_providedSnapPoints,
@@ -1797,6 +1801,8 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
17971801
</BottomSheetBody>
17981802
{/* <BottomSheetDebugView
17991803
values={{
1804+
index: animatedIndex,
1805+
position: animatedPosition,
18001806
sheetStatus: animatedSheetState,
18011807
scrollableStatus: animatedScrollableStatus,
18021808
layoutState: animatedLayoutState,

src/components/bottomSheetHandle/BottomSheetHandleContainer.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,14 @@ import {
1010
} from '../../hooks';
1111
import { print } from '../../utilities';
1212
import { DEFAULT_ENABLE_HANDLE_PANNING_GESTURE } from '../bottomSheet/constants';
13-
import BottomSheetHandle from './BottomSheetHandle';
1413
import type { BottomSheetHandleContainerProps } from './types';
1514

1615
function BottomSheetHandleContainerComponent({
1716
animatedIndex,
1817
animatedPosition,
1918
simultaneousHandlers: _internalSimultaneousHandlers,
2019
enableHandlePanningGesture = DEFAULT_ENABLE_HANDLE_PANNING_GESTURE,
21-
handleComponent,
20+
handleComponent: HandleComponent,
2221
handleStyle: _providedHandleStyle,
2322
handleIndicatorStyle: _providedIndicatorStyle,
2423
}: BottomSheetHandleContainerProps) {
@@ -163,7 +162,6 @@ function BottomSheetHandleContainerComponent({
163162
//#endregion
164163

165164
//#region renders
166-
const HandleComponent = handleComponent ?? BottomSheetHandle;
167165
return (
168166
<GestureDetector gesture={panGesture}>
169167
<Animated.View

src/components/bottomSheetHandle/types.d.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,11 @@ export interface BottomSheetDefaultHandleProps
3636
export type BottomSheetHandleContainerProps = Pick<
3737
PanGestureHandlerProperties,
3838
'simultaneousHandlers'
39-
> &
40-
Pick<
39+
> & {
40+
handleComponent: React.FC<BottomSheetDefaultHandleProps>;
41+
} & Pick<
4142
BottomSheetProps,
42-
| 'enableHandlePanningGesture'
43-
| 'handleIndicatorStyle'
44-
| 'handleStyle'
45-
| 'handleComponent'
43+
'enableHandlePanningGesture' | 'handleIndicatorStyle' | 'handleStyle'
4644
> &
4745
Pick<
4846
useInteractivePanGestureHandlerConfigs,

src/hooks/useAnimatedDetents.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ export const useAnimatedDetents = (
9494
// sort all detents.
9595
_normalizedDetents = _normalizedDetents.sort((a, b) => b - a);
9696

97-
highestDetentPosition = _normalizedDetents[0];
97+
// update the highest detent position.
98+
highestDetentPosition = _normalizedDetents[_normalizedDetents.length - 1];
9899

99100
// locate the dynamic detent index.
100101
const dynamicDetentIndex = _normalizedDetents.indexOf(dynamicSnapPoint);

src/hooks/useAnimatedLayout.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,15 @@ const INITIAL_STATE: LayoutState = {
2828
* @param topInset - The top inset value to be subtracted from the container height.
2929
* @param bottomInset - The bottom inset value to be subtracted from the container height.
3030
* @param modal - Optional flag indicating if the layout is in modal mode.
31+
* @param shouldOverrideHandleHeight - Optional flag to override the handle height in the layout state, only when handle is set to null.
3132
* @returns An object containing the animated layout state.
3233
*/
3334
export function useAnimatedLayout(
3435
containerLayoutState: SharedValue<ContainerLayoutState> | undefined,
3536
topInset: number,
3637
bottomInset: number,
37-
modal?: boolean
38+
modal?: boolean,
39+
shouldOverrideHandleHeight?: boolean
3840
) {
3941
//#region variables
4042
const verticalInset = useMemo(
@@ -43,15 +45,21 @@ export function useAnimatedLayout(
4345
);
4446
const initialState = useMemo(() => {
4547
const _state = { ...INITIAL_STATE };
48+
4649
if (containerLayoutState) {
4750
const containerLayout = containerLayoutState.get();
4851
_state.containerHeight = modal
4952
? containerLayout.height - verticalInset
5053
: containerLayout.height;
5154
_state.containerOffset = containerLayout.offset;
5255
}
56+
57+
if (shouldOverrideHandleHeight) {
58+
_state.handleHeight = 0;
59+
}
60+
5361
return _state;
54-
}, [containerLayoutState, modal, verticalInset]);
62+
}, [containerLayoutState, modal, shouldOverrideHandleHeight, verticalInset]);
5563
//#endregion
5664

5765
//#region state

0 commit comments

Comments
 (0)