colorfy-software / react-native-modalfy

🥞 Modal citizen of React Native.
https://colorfy-software.gitbook.io/react-native-modalfy
MIT License
1.06k stars 41 forks source link

Easy way to get modal props #113

Closed GustavoBonfimS closed 1 year ago

GustavoBonfimS commented 1 year ago

Just to document and help anyone who finds it interesting. In my projects I have been using this method to import the properties of the modal. I think it's a little simpler than the default.

Instead of use

type Props = ModalComponentProp<
  ModalStackParams,
  void,
  'PaymentMethodSelectModal'
>;

We can use

type Props = ModalProps<'PaymentMethodSelectModal'>;

Or directly in the component

function PaymentMethodSelectModal({
  modal: { getParam, closeModal },
}: ModalProps<'PaymentMethodSelectModal'>) { }

With this implementation

interface ModalStackParams {
  PaymentMethodSelectModal: {
    foo: string;
  }
}

export const stack = createModalStack(modalConfig, {
  backdropOpacity: 0.3,
  position: 'bottom',
});

export type ModalProps<
  T extends keyof ModalStackParams = keyof ModalStackParams,
> = ModalComponentProp<ModalStackParams, void, T>;

I have saved this in my Stack settings file and use it when I need it.

I hope it helps. ❤️ This issue can be closed

CharlesMangwa commented 1 year ago

thanks a lot for taking the time to write this @GustavoBonfimS! actually #114 might even make the whole typescript situation even easier! 😼

CharlesMangwa commented 1 year ago

@GustavoBonfimS now that #114 is close from merging and after some clarification by @v-honcharenko, i decided to add ModalProps to the library itself. you can expect it in the next release and the documentation has already been updated to recommend ModalProps instead of ModalComponentProp. please do let me know if i got everything correctly and thx for your contribution! 🙌

GustavoBonfimS commented 1 year ago

Nice work, thanks! ❤️