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

Smooth transition only happens once #246

Open
gabrielvincent opened this issue Jun 7, 2022 · 5 comments
Open

Smooth transition only happens once #246

gabrielvincent opened this issue Jun 7, 2022 · 5 comments

Comments

@gabrielvincent
Copy link

Simulator.Screen.Recording.-.iPhone.SE.3rd.generation.-.2022-06-07.at.11.45.27.mp4

This is where I create the Navigation Container

const Root: React.FC<RootProps> = ({}) => {
  const theme = useTheme()
  return (
    <SafeAreaView
      style={{ backgroundColor: theme.colors.background, ...tw`flex-1` }}
    >
      <NavigationContainer>
        <Stack.Navigator initialRouteName='Today'>
          <Stack.Screen
            name='Today'
            component={HomePage}
            options={{
              headerShown: false,
            }}
          />
          <Stack.Screen
            name='CardDetail'
            component={CardDetail}
            options={{
              headerShown: false,
              cardStyle: {
                opacity: 1,
              },
              cardStyleInterpolator: ({ current }) => ({
                cardStyle: {
                  opacity: current.progress,
                },
              }),
            }}
            sharedElements={(route, otherRoute, showing) => {
              return [
                `birth_chart`,
                `${route.name}.${route.key}.background`,
                `${route.name}.${route.key}.compact`,
                {
                  id: `${route.name}.${route.key}.expanded`,
                  resize: 'clip',
                  animation: 'fade',
                },
                {
                  id: `${route.name}.${route.key}.back_button`,
                  resize: 'clip',
                  animation: 'fade',
                },
              ]
            }}
          />
        </Stack.Navigator>
      </NavigationContainer>
    </SafeAreaView>
  )
}

This is the CardDetail component:

const CardDetail: NavigationStackScreenComponentWithSharedComponent<
  CardDetailProps,
  RootStackParamList,
  'CardDetail'
> = ({ navigation, route }) => {
  const theme = useTheme()
  const birthChartProviderState = route.params?.birthChartProviderState

  return (
    <ScrollView style={{ backgroundColor: theme.colors.background, flex: 1 }}>
      <SkiaBirthChartProvider syncState={birthChartProviderState}>
        <SharedElement id='birth_chart'>
          <BirthChart />
        </SharedElement>

        <View style={tw`px-4`}>
          <SunInSignCard
            expanded
            onBack={() => {
              navigation.pop()
            }}
          />
        </View>
      </SkiaBirthChartProvider>
    </ScrollView>
  )
}

All the shared elements are defined in the SunInSignCard component, for example:

<SharedElement
  id='CardDetail.sun_in_sign.background'
  style={{
    ...tw`absolute inset-0`,
  }}
>
  <View
    style={{
      ...tw`rounded-xl w-full h-full bg-white`,
    }}
  />
</SharedElement>

What could be causing this?

I'm using:

  • "expo": "~45.0.0"
  • "react-native": "0.68.2"
  • "react-native-shared-element": "0.8.4"
  • "react-navigation-shared-element": "^3.1.3"
  • "@react-navigation/native": "^6.0.10"
  • "@react-navigation/native-stack": "^6.6.2"
  • "@react-navigation/stack": "^6.2.1"
@fukemy
Copy link

fukemy commented Dec 1, 2022

hi, how did u make your app run? I got this problem:

Unable to resolve module @react-navigation/stack from .../Work/VedaxLink/node_modules/react-navigation-shared-element/build/createSharedElementStackNavigator.js: @react-navigation/stack could not be found within the project or in these directories:
  node_modules
  1 | import { useNavigationBuilder, createNavigatorFactory, StackRouter, } from "@react-navigation/native";
> 2 | import { CardAnimationContext, StackView, } from "@react-navigation/stack";
    |                                                   ^
  3 | import * as React from "react";
  4 | import { Platform } from "react-native";
  5 | import { useSharedElementFocusEvents } from "./SharedElementFocusEvents";

package json:

"react-native-shared-element": "^0.8.4",
"react-navigation-shared-element": "^3.1.3",
"@react-navigation/native": "^6.0.10",
"@react-navigation/native-stack": "^6.6.1",

@gabrielvincent
Copy link
Author

@fukemy It looks like @react-navigation/stack is missing. Try npm i @react-navigation/stack or yarn add @react-navigation/stack.

@fukemy
Copy link

fukemy commented Dec 1, 2022

thanks, i forgot it

@hashhirr
Copy link

how did you resolved your issue?

@gabrielvincent
Copy link
Author

I didn't. I ended up choosing a simpler UI without a lot of fluff.

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

No branches or pull requests

3 participants