Skip to content
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

Support ModalPresentationIOS transition preset #23

Open
mrousavy opened this issue Mar 28, 2020 · 7 comments
Open

Support ModalPresentationIOS transition preset #23

mrousavy opened this issue Mar 28, 2020 · 7 comments
Labels
enhancement New feature or request react-navigation

Comments

@mrousavy
Copy link

The animation begins smoothly, but when the animation finishes, the items (SharedElements) are off by some pixels which causes this stuttering glitch. This issue only appears when using the ModalPresentationIOS transition preset. All other presets work fine.

Demo here:
Screen-Recording-2020-03-28-at-19 09 06

My Navigator:

const SharedElementStack = createSharedElementStackNavigator();
function HomeSharedElementStackNavigator() {
  return (
    <SharedElementStack.Navigator
      mode="modal"
      screenOptions={{
        gestureEnabled: false,
        cardOverlayEnabled: true,
        ...TransitionPresets.ModalPresentationIOS,     // <-- The preset causing this issue!
      }}
      headerMode="none">
      <SharedElementStack.Screen
        name="HomeGridScreen"
        component={HomeGridScreen}
      />
      <SharedElementStack.Screen
        name="ItemDetailsScreen"
        component={ItemDetailsScreen}
        sharedElementsConfig={(route, otherRoute, showing) => {
          const {item} = route.params;
          return [
            {
              id: `item.${item.id}.image`,
              animation: 'fade',
            },
            {
              id: `item.${item.id}.title`,
              animation: 'fade',
            },
            {
              id: `item.${item.id}.description`,
              animation: 'fade',
            },
          ];
        }}
      />
    </SharedElementStack.Navigator>
  );
}

I've tried playing around with the animation property, but I can't seem to get it working with this animation I found in the example project (springyFadeIn.js):

import {Animated} from 'react-native';
export function springyFadeIn() {
  const transitionSpec = {
    timing: Animated.spring,
    tension: 10,
    useNativeDriver: true,
  };
  return {
    transitionSpec,
    screenInterpolator: ({position, scene}) => {
      const {index} = scene;

      const opacity = position.interpolate({
        inputRange: [index - 1, index],
        outputRange: [0, 1],
      });

      return {opacity};
    },
  };
}

Packages used:

// ...
    "react": "16.9.0",
    "react-native": "0.61.5",
    "react-navigation-shared-element": "^5.0.0-alpha1",
// ...

I don't know if that's a bug in the library or if I am making a mistake, would appreciate some help here!

@mrousavy
Copy link
Author

mrousavy commented Mar 29, 2020

I've investigated the issue further and noticed that this bug only appears when using the ModalPresentationIOS or ScaleFromCenterAndroid transition preset in the screenOptions of the Navigator.

<SharedElementStack.Navigator
  mode="modal"
  screenOptions={{
    gestureEnabled: false,
    cardOverlayEnabled: true,
    ...TransitionPresets.ModalPresentationIOS,      // <-- this right here
  }}
  ...

@mrousavy mrousavy changed the title Item position inaccurate after animation ends Item position inaccurate when using ModalPresentationIOS transition preset Mar 29, 2020
@IjzerenHein
Copy link
Owner

Hi 👋This problem appears to be on the native side and is has to do with additional "transforms" applied by the ModalPresentationIOS.

Unfortunately ModalPresentationIOS wont work at the moment.

@IjzerenHein IjzerenHein transferred this issue from IjzerenHein/react-navigation-shared-element Mar 29, 2020
@IjzerenHein
Copy link
Owner

I've moved this issue here 👍

@IjzerenHein IjzerenHein changed the title Item position inaccurate when using ModalPresentationIOS transition preset Support ModalPresentationIOS transition preset Mar 29, 2020
@IjzerenHein IjzerenHein added the enhancement New feature or request label Mar 29, 2020
@AmnaHijjawi
Copy link

+1

1 similar comment
@evanjmg
Copy link

evanjmg commented May 13, 2021

+1

@evanjmg
Copy link

evanjmg commented May 13, 2021

TransitionPresets.ModalSlideFromBottomIOS works better for now as a workaround

@IjzerenHein
Copy link
Owner

Status update: This preset still doesn't work on both Android and iOS. Some glitches have been resolved with regards to vertical translations, but the top position is still not obtained correctly.
As an alternative, please use one of the other presets (nearly all of them work correctly).
You can view the supported transitions in the react-navigation example app:
https://github.com/IjzerenHein/react-navigation-shared-element/tree/main/example

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request react-navigation
Projects
None yet
Development

No branches or pull requests

4 participants