Skip to content

Commit

Permalink
fix: prevent keyboard change to snap sheet while user is interacting
Browse files Browse the repository at this point in the history
  • Loading branch information
gorhom committed Aug 18, 2021
1 parent 73decd3 commit dd632b0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
10 changes: 6 additions & 4 deletions example/src/screens/advanced/KeyboardHandlingExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ import ContactList from '../../components/contactList';

const KeyboardHandlingExample = () => {
// state
const [keyboardBehavior, setKeyboardBehavior] =
useState<'extend' | 'fillParent' | 'interactive'>('interactive');
const [keyboardBlurBehavior, setKeyboardBlurBehavior] =
useState<'none' | 'restore'>('none');
const [keyboardBehavior, setKeyboardBehavior] = useState<
'extend' | 'fillParent' | 'interactive'
>('interactive');
const [keyboardBlurBehavior, setKeyboardBlurBehavior] = useState<
'none' | 'restore'
>('none');

// hooks
const bottomSheetRef = useRef<BottomSheet>(null);
Expand Down
18 changes: 17 additions & 1 deletion src/components/bottomSheet/BottomSheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1272,9 +1272,25 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
useAnimatedReaction(
() => animatedKeyboardState.value,
(_keyboardState, _previousKeyboardState) => {
const hasActiveGesture =
animatedContentGestureState.value === State.ACTIVE ||
animatedContentGestureState.value === State.BEGAN ||
animatedHandleGestureState.value === State.ACTIVE ||
animatedHandleGestureState.value === State.BEGAN;

if (
!isAnimatedOnMount.value ||
/**
* if keyboard state is equal to the previous state, then exit the method
*/
_keyboardState === _previousKeyboardState ||
/**
* if user is interacting with sheet, then exit the method
*/
hasActiveGesture ||
/**
* if sheet not animated on mount yet, then exit the method
*/
!isAnimatedOnMount.value ||
/**
* if new keyboard state is hidden and blur behavior is none, then exit the method
*/
Expand Down

0 comments on commit dd632b0

Please sign in to comment.