gorhom / react-native-portal

A simplified portal implementation for ⭕️ React Native & Web ⭕️.
MIT License
655 stars 36 forks source link

Use contextBridge? #45

Open natew opened 1 year ago

natew commented 1 year ago

Found this: https://github.com/pmndrs/its-fine#usecontextbridge

Think we could make this work with this library to avoid the context clearing issue? I could try out a PR

gorhom commented 1 year ago

good suggestion, i will look into , but feel free to submit a CR and i'll look into it this weekend

gorhom commented 1 year ago

@natew thanks for the suggestion, the library seemed to expose the internal contexts, but there is something wrong with passing values

https://github.com/gorhom/react-native-portal/assets/4061838/0e8f371d-0476-4e33-85db-dae7a404ad14

gorhom commented 1 year ago

i think i found the issue with the memoized bridge that it returns https://github.com/pmndrs/its-fine/blob/main/src/index.tsx#L221-L233 the equality check does not run a deep equality check which causes the return memoized value to be static and never change.

CJY0208 commented 1 year ago

I found this library while making a RN modal component. I noticed that its implementation method is very similar to my library react-activation(implements Vue keep alive in React).

Due to the movement of the virtual DOM, they both encountered the problem of context discontinuity. The approach of react-activation to this problem is to leave a consumer that listens to the context at the position of transferring the virtual DOM, and transfer all captured context content along with the virtual DOM to the outside. At the position of rendering the virtual DOM, the provider is rebuilt based on the captured context content.

This approach seems to have similarities with useContextBridge, hoping it could be of some help to this library.