Skip to content

horizontal gestureDirection does not work for modal stack #6969

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
abegehr opened this issue Feb 3, 2020 · 6 comments
Closed

horizontal gestureDirection does not work for modal stack #6969

abegehr opened this issue Feb 3, 2020 · 6 comments

Comments

@abegehr
Copy link

abegehr commented Feb 3, 2020

Current Behavior

navigationOptions: {gestureDirection: 'horizontal'} does not work for stack navigators with mode: 'modal'. Using gestureDirection: 'horizontal-inverted', leeds to a vertical-inverted gestureDirection.

See my current stack navigator setup here:

const MainModalNavigator = createStackNavigator(
  {
    Main: {screen: MainDrawerNavigator},
    Notifications: {
      screen: NotificationsScreen,
      navigationOptions: {gestureDirection: 'horizontal'},
    },
  },
  {
    mode: 'modal',
    headerMode: 'none',
    initialRouteName: 'Main',
    defaultNavigationOptions: {
      cardStyle: {
        backgroundColor: 'rgba(0, 0, 0, 0)',
      },
    },
  },
);

Expected Behaviorx

Stack navigators with mode: 'modal' should allow horizontal gestureDirection.

How to reproduce

Find a minimal GH repo to reproduce the issue here: https://github.com/abegehr/react-navigation-horizontal-modal-stack
The repo is based on expo and can be run easily through the expo-cli.

The repo was produced by:

  • expo init with react-navigation 'tabs' template
  • removed unnecessary files and code
  • simple Home, Links and Settings screen with rudimentary navigation between them
  • use same navigation setup as described in 'Current Behavior'

=> Please let me know if this is helpful and if I can do anything else to make the issue more clear

Your Environment

  • iOS 13.3
  • "react-navigation": "^4.1.0",
  • "react-navigation-stack": "^2.0.16",
  • "react-native-gesture-handler": "^1.5.4",
  • "react-native-safe-area-context": "^0.6.4",
  • "react-native-screens": "^2.0.0-alpha.32",
  • "react-native": "^0.61.5",
  • Now using node v12.14.1 (npm v6.13.4)
  • yarn 1.19.2
@satya164
Copy link
Member

satya164 commented Feb 3, 2020

You're talking about the animation, not gesture. You need to use a horizontal animation if you want to see your screen slide horizontally.

@satya164 satya164 closed this as completed Feb 3, 2020
@abegehr
Copy link
Author

abegehr commented Feb 3, 2020

@satya164, thank you for the quick response!
The documentation states: "gestureDirection - The direction of swipe gestures as well as animations" https://reactnavigation.org/docs/en/stack-navigator.html#animation-related-options
Therefore, I assumed setting the gestureDirection would apply animations as well. I can confirm that the gesture direction for closing works as expected 👍
I will try to apply a horizontal animation aswell.

@satya164
Copy link
Member

satya164 commented Feb 3, 2020

The direction of swipe gestures as well as animations

This is just referring to the "inverted" part. I'll clarify it.

@abegehr
Copy link
Author

abegehr commented Feb 3, 2020

Thanks for pointing me in the right direction, @satya164!
I achieved the horizontal modal by adjusting the cardStyleInterpolator forHorizontaliOS to this:

export function forHorizontalModal({
  current,
  next,
  inverted,
  layouts: { screen }
}: StackCardInterpolationProps): StackCardInterpolatedStyle {
  const translateFocused = multiply(
    current.progress.interpolate({
      inputRange: [0, 1],
      outputRange: [screen.width, 0],
      extrapolate: "clamp"
    }),
    inverted
  );

  const overlayOpacity = current.progress.interpolate({
    inputRange: [0, 1],
    outputRange: [0, 0.07],
    extrapolate: "clamp"
  });

  const shadowOpacity = current.progress.interpolate({
    inputRange: [0, 1],
    outputRange: [0, 0.3],
    extrapolate: "clamp"
  });

  return {
    cardStyle: {
      transform: [
        // Translation for the animation of the current card
        { translateX: translateFocused },
        // Translation for the animation of the card in back
        { translateX: 0 }
      ]
    },
    overlayStyle: { opacity: overlayOpacity },
    shadowStyle: { shadowOpacity }
  };
}

And applying it in the navgiationOptions:

Links: {
  screen: LinksScreen,
  navigationOptions: {
    gestureDirection: "horizontal",
    cardStyleInterpolator: forHorizontalModal
  }
},

@satya164 satya164 transferred this issue from react-navigation/stack Feb 24, 2020
@Jogre900
Copy link

excuse me but i got an error with the multiply variable, is not defined.

@enGMzizo
Copy link

@Jogre900

import {Animated} from 'react-native';
// then use it as 
Animated.multiply() 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants