2
\$\begingroup\$

I have many stacks with the same navigation options. How do I abstract the navigationOptions part to have it repeat in all my stacks?

export const MakePaymentStack = createStackNavigator(
  {
    PaymentsBpayNewScreen,
    PaymentsBpayNewAmountScreen,
  },
  {
    ...defaultNavStyle,
    initialRouteName: APP_SCREENS.PaymentsBpayNewScreen,
  },
);
(MakePaymentStack as any).navigationOptions = () => ({
  animationEnabled: true,
  gesturesEnabled: false, // disable swipe down to dismiss on iOS
});

and like that all the others:

export const StatementsStack = createStackNavigator(
  {
    StatementPdfScreen,
  },
  {
    ...defaultNavStyle,
    initialRouteName: APP_SCREENS.StatementPdfScreen,
  },
);
(StatementsStack as any).navigationOptions = () => ({
  animationEnabled: true,
  gesturesEnabled: false, // disable swipe down to dismiss on iOS
});

How can I abstract the "navigationOptions"?

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

What I would suggest is to wrap createStackNavigator in another function where you mimic the API but with different defaults.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.