Skip to content

Conversation

@gorhom
Copy link
Owner

@gorhom gorhom commented Mar 14, 2021

Closes #343

Motivation

  • improve modal dismissing
  • fix crash when trying to find node when modal is umounted

Installation

yarn add ssh://[email protected]:gorhom/react-native-bottom-sheet#fix/improve-modal-dismiss

@gorhom gorhom added the v3 Written in Reanimated v2 label Mar 14, 2021
@gorhom
Copy link
Owner Author

gorhom commented Mar 14, 2021

@Dallas62 could you try this pr :)

@Dallas62
Copy link

Hi @gorhom

Trying with the following code:

import React, { useRef } from 'react';
import { TouchableOpacity, Text } from 'react-native';
import { BottomSheetModal } from '@gorhom/bottom-sheet';

const snap_points = ['20%'];

function MyComp() {
  const bottom_sheet_modal1_ref = useRef(null);
  const bottom_sheet_modal2_ref = useRef(null);

  const open_modal1 = () => {
    bottom_sheet_modal1_ref.current.present();
  };

  const open_modal2 = () => {
    bottom_sheet_modal2_ref.current.present();
  };

  const close_both_modals = () => {
    bottom_sheet_modal2_ref.current.dismiss();
    bottom_sheet_modal1_ref.current.dismiss();
  };

  return (
    <>
        <TouchableOpacity onPress={open_modal1}><Text>Open modal1</Text></TouchableOpacity>
        <BottomSheetModal ref={bottom_sheet_modal1_ref} snapPoints={snap_points}>
          <TouchableOpacity onPress={open_modal2}><Text>Open modal2</Text></TouchableOpacity>
        </BottomSheetModal>
        <BottomSheetModal ref={bottom_sheet_modal2_ref} snapPoints={snap_points}>
          <TouchableOpacity onPress={close_both_modals}><Text>Close both modal</Text></TouchableOpacity>
        </BottomSheetModal>
    </>
  );
}

It's working, but when i reorder the close_both_modals:

  const close_both_modals = () => {
    bottom_sheet_modal1_ref.current.dismiss();
    bottom_sheet_modal2_ref.current.dismiss();
  };

I got:

 TypeError: null is not an object (evaluating '_sheetsQueue[_sheetsQueue.length - 2].ref.current.restore')

@gorhom
Copy link
Owner Author

gorhom commented Mar 14, 2021

hmm i am testing it here , and it works just fine.

try to clean install and clear metro cache

@Dallas62
Copy link

Restarting bundler made it works 😉
Also working with my small use.

Didn't test more cases.

@gorhom gorhom merged commit fd9ae1c into v3 Mar 15, 2021
@gorhom gorhom deleted the fix/improve-modal-dismiss branch March 15, 2021 21:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

v3 Written in Reanimated v2

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants