Skip to content

Smooth transition only happens once #246

Open

Description

@gabrielvincent
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"

Activity

  1. fukemy commented on Dec 1, 2022

    @fukemy

    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",
    
  2. gabrielvincent commented on Dec 1, 2022

    @gabrielvincent
    Author

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

  3. fukemy commented on Dec 1, 2022

    @fukemy

    thanks, i forgot it

  4. hashhirr commented on Apr 26, 2024

    @hashhirr

    how did you resolved your issue?

  5. gabrielvincent commented on Apr 26, 2024

    @gabrielvincent
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions