Skip to content

Commit c19c93d

Browse files
authored
Merge pull request #4 from guideline-tech/upstream-sync-5.1.2
Upstream sync 5.1.2
2 parents 48f8ee9 + c8822c9 commit c19c93d

File tree

19 files changed

+190
-105
lines changed

19 files changed

+190
-105
lines changed

CHANGELOG.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,32 @@
11

22

3+
## [5.1.2](https://github.com/gorhom/react-native-bottom-sheet/compare/v5.1.1...v5.1.2) (2025-03-09)
4+
5+
6+
### Bug Fixes
7+
8+
* **#2163:** restart closing animation when container height get updated ([4ed9f3c](https://github.com/gorhom/react-native-bottom-sheet/commit/4ed9f3cb542316a984893efa2025ca5384ffe89a)), closes [#2163](https://github.com/gorhom/react-native-bottom-sheet/issues/2163)
9+
* **#2177:** set absolute fill to backdrop default style ([979ba7c](https://github.com/gorhom/react-native-bottom-sheet/commit/979ba7ce0b9d69abfaefd169ee692bf818fa4d0d)), closes [#2177](https://github.com/gorhom/react-native-bottom-sheet/issues/2177)
10+
11+
## [5.1.1](https://github.com/gorhom/react-native-bottom-sheet/compare/v5.1.0...v5.1.1) (2025-02-09)
12+
13+
14+
### Bug Fixes
15+
16+
* **#2043:** handle unnecessary invocation of index side effect ([#2073](https://github.com/gorhom/react-native-bottom-sheet/issues/2073))(inspired by @IslamRustamov) ([2164c02](https://github.com/gorhom/react-native-bottom-sheet/commit/2164c02e63177f9ac69acc05722c85e8d55cd931)), closes [#2043](https://github.com/gorhom/react-native-bottom-sheet/issues/2043)
17+
18+
# [5.1.0](https://github.com/gorhom/react-native-bottom-sheet/compare/v5.0.6...v5.1.0) (2025-02-06)
19+
20+
21+
### Bug Fixes
22+
23+
* **#2129:** fixed initial isAnimatedOnMount value ([0850cb8](https://github.com/gorhom/react-native-bottom-sheet/commit/0850cb864819f79189592cb66c2b6d179957ba61))
24+
25+
26+
### Features
27+
28+
* added enableBlurKeyboardOnGesture prop to handle blurring keyboard on gesture ([1c31aca](https://github.com/gorhom/react-native-bottom-sheet/commit/1c31acad50a7c171548ea7f4594a4d1d563cf40f))
29+
330
## [5.0.6](https://github.com/gorhom/react-native-bottom-sheet/compare/v5.0.5...v5.0.6) (2024-11-17)
431

532

example/app.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"splash": {
1313
"image": "./assets/splash.png",
1414
"resizeMode": "contain",
15-
"backgroundColor": "#000"
15+
"backgroundColor": "#000000"
1616
},
1717
"assetBundlePatterns": ["**/*"],
1818
"ios": {
@@ -22,7 +22,7 @@
2222
"android": {
2323
"adaptiveIcon": {
2424
"foregroundImage": "./assets/adaptive-icon.png",
25-
"backgroundColor": "#000"
25+
"backgroundColor": "#000000"
2626
},
2727
"package": "dev.gorhom.bottomsheet",
2828
"softwareKeyboardLayoutMode": "pan"

example/package.json

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,22 @@
1616
"@react-navigation/native": "^6.1.9",
1717
"@react-navigation/native-stack": "^6.9.17",
1818
"@react-navigation/stack": "^6.3.20",
19-
"@shopify/flash-list": "1.7.1",
20-
"expo": "^52.0.7",
21-
"expo-asset": "~11.0.1",
22-
"expo-blur": "~14.0.1",
23-
"expo-image": "~2.0.0",
24-
"expo-status-bar": "~2.0.0",
19+
"@shopify/flash-list": "1.7.3",
20+
"expo": "~52.0.36",
21+
"expo-asset": "~11.0.4",
22+
"expo-blur": "~14.0.3",
23+
"expo-image": "~2.0.6",
24+
"expo-status-bar": "~2.0.1",
2525
"react": "18.3.1",
2626
"react-dom": "18.3.1",
27-
"react-native": "0.76.2",
27+
"react-native": "0.76.7",
2828
"react-native-gesture-handler": "~2.20.2",
2929
"react-native-maps": "1.18.0",
30-
"react-native-pager-view": "6.4.1",
30+
"react-native-pager-view": "6.5.1",
3131
"react-native-reanimated": "~3.16.1",
3232
"react-native-redash": "^18.1.0",
3333
"react-native-safe-area-context": "4.12.0",
34-
"react-native-screens": "~4.1.0",
34+
"react-native-screens": "~4.4.0",
3535
"react-native-tab-view": "^3.5.2",
3636
"react-native-web": "~0.19.13"
3737
},
@@ -41,6 +41,7 @@
4141
"@types/faker": "^4.1.12",
4242
"@types/react": "~18.3.12",
4343
"@types/react-native": "^0.73.0",
44+
"babel-loader": "^10.0.0",
4445
"babel-plugin-module-resolver": "^5.0.0",
4546
"faker": "^4.1.0",
4647
"typescript": "^5.3.3"

example/src/screens/advanced/KeyboardHandlingExample.tsx

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import React, { useCallback, useMemo, useRef, useState } from 'react';
2-
import { View, StyleSheet } from 'react-native';
31
import BottomSheet from '@gorhom/bottom-sheet';
2+
import React, { useCallback, useMemo, useRef, useState } from 'react';
3+
import { StyleSheet, View } from 'react-native';
4+
import { Button } from '../../components/button';
5+
import { ContactList } from '../../components/contactList';
46
import {
5-
SearchHandle,
67
SEARCH_HANDLE_HEIGHT,
8+
SearchHandle,
79
} from '../../components/searchHandle';
8-
import { Button } from '../../components/button';
9-
import { ContactList } from '../../components/contactList';
1010

1111
const KeyboardHandlingExample = () => {
1212
// state
@@ -16,6 +16,7 @@ const KeyboardHandlingExample = () => {
1616
const [keyboardBlurBehavior, setKeyboardBlurBehavior] = useState<
1717
'none' | 'restore'
1818
>('none');
19+
const [blurKeyboardOnGesture, setBlurKeyboardOnGesture] = useState(false);
1920

2021
// hooks
2122
const bottomSheetRef = useRef<BottomSheet>(null);
@@ -46,6 +47,9 @@ const KeyboardHandlingExample = () => {
4647
}
4748
});
4849
}, []);
50+
const handleToggleBlurKeyboardOnGesture = useCallback(() => {
51+
setBlurKeyboardOnGesture(state => !state);
52+
}, []);
4953
const handleExpandPress = useCallback(() => {
5054
bottomSheetRef.current?.expand();
5155
}, []);
@@ -67,6 +71,10 @@ const KeyboardHandlingExample = () => {
6771
label={`Toggle Keyboard Blur Behavior: ${keyboardBlurBehavior}`}
6872
onPress={handleToggleKeyboardBlurBehavior}
6973
/>
74+
<Button
75+
label={`Toggle Blur Keyboard On Gesture: ${blurKeyboardOnGesture}`}
76+
onPress={handleToggleBlurKeyboardOnGesture}
77+
/>
7078
<Button label="Expand" onPress={handleExpandPress} />
7179
<Button label="Collapse" onPress={handleCollapsePress} />
7280
<Button label="Close" onPress={handleClosePress} />
@@ -76,6 +84,7 @@ const KeyboardHandlingExample = () => {
7684
enableDynamicSizing={false}
7785
keyboardBehavior={keyboardBehavior}
7886
keyboardBlurBehavior={keyboardBlurBehavior}
87+
enableBlurKeyboardOnGesture={blurKeyboardOnGesture}
7988
handleComponent={SearchHandle}
8089
>
8190
<ContactList count={12} type="FlatList" />

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@gorhom/bottom-sheet",
3-
"version": "5.0.6",
3+
"version": "5.1.2",
44
"description": "A performant interactive bottom sheet with fully configurable options 🚀",
55
"main": "lib/commonjs/index",
66
"module": "lib/module/index",

src/components/bottomSheet/BottomSheet.tsx

Lines changed: 80 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import {
4747
usePropsValidator,
4848
useReactiveSharedValue,
4949
useScrollable,
50+
useStableCallback,
5051
} from '../../hooks';
5152
import type { BottomSheetMethods } from '../../types';
5253
import {
@@ -69,6 +70,7 @@ import {
6970
DEFAULT_ACCESSIBLE,
7071
DEFAULT_ANIMATE_ON_MOUNT,
7172
DEFAULT_DYNAMIC_SIZING,
73+
DEFAULT_ENABLE_BLUR_KEYBOARD_ON_GESTURE,
7274
DEFAULT_ENABLE_CONTENT_PANNING_GESTURE,
7375
DEFAULT_ENABLE_OVER_DRAG,
7476
DEFAULT_ENABLE_PAN_DOWN_TO_CLOSE,
@@ -125,6 +127,7 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
125127
keyboardBehavior = DEFAULT_KEYBOARD_BEHAVIOR,
126128
keyboardBlurBehavior = DEFAULT_KEYBOARD_BLUR_BEHAVIOR,
127129
android_keyboardInputMode = DEFAULT_KEYBOARD_INPUT_MODE,
130+
enableBlurKeyboardOnGesture = DEFAULT_ENABLE_BLUR_KEYBOARD_ON_GESTURE,
128131

129132
// layout
130133
containerHeight: _providedContainerHeight,
@@ -245,7 +248,9 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
245248
const animatedNextPositionIndex = useSharedValue(INITIAL_VALUE);
246249

247250
// conditional
248-
const isAnimatedOnMount = useSharedValue(false);
251+
const isAnimatedOnMount = useSharedValue(
252+
!animateOnMount || _providedIndex === -1
253+
);
249254
const isContentHeightFixed = useSharedValue(false);
250255
const isLayoutCalculated = useDerivedValue(() => {
251256
let isContainerHeightCalculated = false;
@@ -674,6 +679,7 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
674679
params: {
675680
currentPosition: animatedPosition.value,
676681
nextPosition: position,
682+
source,
677683
},
678684
});
679685
}
@@ -1017,68 +1023,56 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
10171023
//#endregion
10181024

10191025
//#region public methods
1020-
// biome-ignore lint/correctness/useExhaustiveDependencies(BottomSheet.name): used for debug only
1021-
const handleSnapToIndex = useCallback(
1022-
function handleSnapToIndex(
1023-
index: number,
1024-
animationConfigs?: WithSpringConfig | WithTimingConfig
1025-
) {
1026-
const snapPoints = animatedSnapPoints.value;
1027-
invariant(
1028-
index >= -1 && index <= snapPoints.length - 1,
1029-
`'index' was provided but out of the provided snap points range! expected value to be between -1, ${
1030-
snapPoints.length - 1
1031-
}`
1032-
);
1033-
if (__DEV__) {
1034-
print({
1035-
component: BottomSheet.name,
1036-
method: handleSnapToIndex.name,
1037-
params: {
1038-
index,
1039-
},
1040-
});
1041-
}
1026+
const handleSnapToIndex = useStableCallback(function handleSnapToIndex(
1027+
index: number,
1028+
animationConfigs?: WithSpringConfig | WithTimingConfig
1029+
) {
1030+
const snapPoints = animatedSnapPoints.value;
1031+
invariant(
1032+
index >= -1 && index <= snapPoints.length - 1,
1033+
`'index' was provided but out of the provided snap points range! expected value to be between -1, ${
1034+
snapPoints.length - 1
1035+
}`
1036+
);
1037+
if (__DEV__) {
1038+
print({
1039+
component: BottomSheet.name,
1040+
method: handleSnapToIndex.name,
1041+
params: {
1042+
index,
1043+
},
1044+
});
1045+
}
10421046

1043-
const nextPosition = snapPoints[index];
1047+
const nextPosition = snapPoints[index];
10441048

1045-
/**
1046-
* exit method if :
1047-
* - layout is not calculated.
1048-
* - already animating to next position.
1049-
* - sheet is forced closing.
1050-
*/
1051-
if (
1052-
!isLayoutCalculated.value ||
1053-
index === animatedNextPositionIndex.value ||
1054-
nextPosition === animatedNextPosition.value ||
1055-
isForcedClosing.value
1056-
) {
1057-
return;
1058-
}
1049+
/**
1050+
* exit method if :
1051+
* - layout is not calculated.
1052+
* - already animating to next position.
1053+
* - sheet is forced closing.
1054+
*/
1055+
if (
1056+
!isLayoutCalculated.value ||
1057+
index === animatedNextPositionIndex.value ||
1058+
nextPosition === animatedNextPosition.value ||
1059+
isForcedClosing.value
1060+
) {
1061+
return;
1062+
}
10591063

1060-
/**
1061-
* reset temporary position boolean.
1062-
*/
1063-
isInTemporaryPosition.value = false;
1064+
/**
1065+
* reset temporary position boolean.
1066+
*/
1067+
isInTemporaryPosition.value = false;
10641068

1065-
runOnUI(animateToPosition)(
1066-
nextPosition,
1067-
ANIMATION_SOURCE.USER,
1068-
0,
1069-
animationConfigs
1070-
);
1071-
},
1072-
[
1073-
animateToPosition,
1074-
isLayoutCalculated,
1075-
isInTemporaryPosition,
1076-
isForcedClosing,
1077-
animatedSnapPoints,
1078-
animatedNextPosition,
1079-
animatedNextPositionIndex,
1080-
]
1081-
);
1069+
runOnUI(animateToPosition)(
1070+
nextPosition,
1071+
ANIMATION_SOURCE.USER,
1072+
0,
1073+
animationConfigs
1074+
);
1075+
});
10821076
const handleSnapToPosition = useWorkletCallback(
10831077
function handleSnapToPosition(
10841078
position: number | string,
@@ -1390,6 +1384,7 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
13901384
activeOffsetY: _providedActiveOffsetY,
13911385
failOffsetX: _providedFailOffsetX,
13921386
failOffsetY: _providedFailOffsetY,
1387+
enableBlurKeyboardOnGesture,
13931388
animateToPosition,
13941389
stopAnimation,
13951390
setScrollableRef,
@@ -1425,6 +1420,7 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
14251420
enableOverDrag,
14261421
enablePanDownToClose,
14271422
enableDynamicSizing,
1423+
enableBlurKeyboardOnGesture,
14281424
_providedSimultaneousHandlers,
14291425
_providedWaitFor,
14301426
_providedActiveOffsetX,
@@ -1538,6 +1534,25 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
15381534
}
15391535

15401536
animatedContainerHeightDidChange.value = result !== previous;
1537+
1538+
/**
1539+
* When user close the bottom sheet while the keyboard open on Android with
1540+
* software keyboard layout mode set to resize, the close position would be
1541+
* set to the container height - the keyboard height, and when the keyboard
1542+
* closes, the container height and here we restart the animation again.
1543+
*
1544+
* [read more](https://github.com/gorhom/react-native-bottom-sheet/issues/2163)
1545+
*/
1546+
if (
1547+
animatedAnimationState.value === ANIMATION_STATE.RUNNING &&
1548+
animatedAnimationSource.value === ANIMATION_SOURCE.GESTURE &&
1549+
animatedNextPositionIndex.value === -1
1550+
) {
1551+
animateToPosition(
1552+
animatedClosedPosition.value,
1553+
ANIMATION_SOURCE.GESTURE
1554+
);
1555+
}
15411556
}
15421557
);
15431558

@@ -1860,10 +1875,13 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
18601875
* @alias onIndexChange
18611876
*/
18621877
useEffect(() => {
1863-
if (isAnimatedOnMount.value) {
1864-
handleSnapToIndex(_providedIndex);
1878+
// early exit, if animate on mount is set and it did not animate yet.
1879+
if (animateOnMount && !isAnimatedOnMount.value) {
1880+
return;
18651881
}
1866-
}, [_providedIndex, isAnimatedOnMount, handleSnapToIndex]);
1882+
1883+
handleSnapToIndex(_providedIndex);
1884+
}, [animateOnMount, _providedIndex, isAnimatedOnMount, handleSnapToIndex]);
18671885
//#endregion
18681886

18691887
// render

src/components/bottomSheet/constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const DEFAULT_DYNAMIC_SIZING = true;
1919
const DEFAULT_KEYBOARD_BEHAVIOR = KEYBOARD_BEHAVIOR.interactive;
2020
const DEFAULT_KEYBOARD_BLUR_BEHAVIOR = KEYBOARD_BLUR_BEHAVIOR.none;
2121
const DEFAULT_KEYBOARD_INPUT_MODE = KEYBOARD_INPUT_MODE.adjustPan;
22+
const DEFAULT_ENABLE_BLUR_KEYBOARD_ON_GESTURE = false;
2223

2324
// initial values
2425
const INITIAL_VALUE = Number.NEGATIVE_INFINITY;
@@ -51,6 +52,7 @@ export {
5152
DEFAULT_KEYBOARD_BEHAVIOR,
5253
DEFAULT_KEYBOARD_BLUR_BEHAVIOR,
5354
DEFAULT_KEYBOARD_INPUT_MODE,
55+
DEFAULT_ENABLE_BLUR_KEYBOARD_ON_GESTURE,
5456
// layout
5557
INITIAL_POSITION,
5658
INITIAL_CONTAINER_HEIGHT,

src/components/bottomSheet/types.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,11 @@ export interface BottomSheetProps
161161
* - `restore`: restore sheet position.
162162
*/
163163
keyboardBlurBehavior?: keyof typeof KEYBOARD_BLUR_BEHAVIOR;
164+
/**
165+
* Enable blurring the keyboard when user start to drag the bottom sheet.
166+
* @default false
167+
*/
168+
enableBlurKeyboardOnGesture?: boolean;
164169
/**
165170
* Defines keyboard input mode for Android only.
166171
* @link {https://developer.android.com/guide/topics/manifest/activity-element#wsoft}

0 commit comments

Comments
 (0)