octopitus / rn-sliding-up-panel

Draggable sliding up panel implemented in React Native https://octopitus.github.io/rn-sliding-up-panel/
MIT License
929 stars 157 forks source link

How to open() or hide() panel with Redux actions #207

Open mhb-yt opened 2 years ago

mhb-yt commented 2 years ago

How can I triger open() / hide() from anywhere in my App? Ideally I would like to use Redux actions for this.

Since the prop visible is not available, I don't know how to control the open/close state using redux actions. The only solution I see is forwardRefs, but it makes the code quite complicated.

Any advice on that?

YuryKorovko commented 2 years ago

The same question for me as well

keeprock commented 2 years ago

There is no other way except using the Ref.

const panelReference = React.createRef();

When pass it to the SlidingUpPanel:

<SlidingUpPanel
            ref={panelReference}
            ...
>

Now you can access various methods (code in Typescript):

panelReference.current?.hide();
panelReference.current?.show();

https://octopitus.github.io/rn-sliding-up-panel/#methods