question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[ANDROID] react-navgiation auth flow causes the source navigator to not be removed when destination navigator uses layout animations.

See original GitHub issue

Description

I’ve been using the layout animations but have noticed odd behavior when used in conjunction with react-navigation, specifically when replacing one navigator with another, for example: during an auth flow (https://reactnavigation.org/docs/auth-flow/).

export const NavigationStacks: React.FC = () => {
  const context = useContext(MyContext);

  if (context.isLoggedIn) {
    return (
      <TabsStack.Navigator>
        <TabsStack.Screen name="HomeTab1" component={HomeScreen} />
        <TabsStack.Screen name="HomeTab2" component={HomeScreen} />
      </TabsStack.Navigator>
    );
  }

  return (
    <OnboardingStack.Navigator>
      <OnboardingStack.Screen name="HomeScreen" component={LoggedOutScreen} />
    </OnboardingStack.Navigator>
  );
};

When launching the app from cold, if you replace a navigator with a screen that does not have an Animated.View with a layout animation, eg:

export const LoggedOutScreen: React.FC = () => {
  const context = useContext(MyContext);
  const navigation = useNavigation();

  return (
    <View style={styles.container}>
      <Pressable
        style={{backgroundColor: 'black', padding: 16, marginTop: 32}}
        onPress={() => context.setIsLoggedIn(!context.isLoggedIn)}>
        <Text style={{color: 'white', fontWeight: 'bold'}}>Login</Text>
      </Pressable>
    </View>
  );
};

with a navigator whose first screen does have a layout animation, eg:

export const HomeScreen: React.FC = () => {
  const context = useContext(MyContext);

  return (
    <View style={styles.container}>
      <Animated.View entering={FadeIn}>
        <Text>This is text with entering transition</Text>
      </Animated.View>
      <Button
        onPress={() => context.setIsLoggedIn(!context.isLoggedIn)}
        title="Logout"
      />
    </View>
  );
};

The first navigator stays in the android view hierarchy:

image

Things to note:

  • If the source navigator also has an Animated.View with a layout animation, this does not happen.
  • This only happens when launching cold. If I reload the app, it then works fine.
  • The source navigator is rendered on top of the destination navigator, blocking any interaction.
  • I don’t have a mac so can’t test this on iOS.

Expected behavior

When swapping out the navigators the layout animation should play and the previous navigator should be removed

Actual behavior & steps to reproduce

When swapping out the navigators, the source navigator remains in the android view hierarchy and blocks any interaction with the destination navigator.

Snack or minimal code example

I’ve created a project to demonstrate this: https://github.com/AcidNoX/navigation-reanimated-repro

Package versions

name version
react-native 0.66.4
react-native-reanimated ^2.3.1
NodeJS 12.22.6
Xcode N/A
Gradle 4.2.2
expo N/A
@react-navigation/native ^6.0.6
react-native-gesture-handler ^2.1.1
react-native-screens ^3.10.1

Affected platforms

  • Android
  • iOS
  • Web

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:7

github_iconTop GitHub Comments

1reaction
AcidNoXcommented, Jan 21, 2022

Thank you for checking iOS @ankushss. Greatly appreciated.

1reaction
ankushsscommented, Jan 21, 2022

Happening only on Android. iOS works well

Read more comments on GitHub >

github_iconTop Results From Across the Web

Authentication flows - React Navigation
It's important to note that when using such a setup, you don't manually navigate to the Home screen by calling navigation.navigate('Home') or any...
Read more >
Migrate to the Navigation component - Android Developers
The Navigation component is a library that can manage complex navigation, transition animation, deep linking, and compile-time checked ...
Read more >
React Native Navigation: Tutorial with examples
Using the stack navigator to navigate between screen components ... and does not directly use the native navigation APIs on iOS and Android....
Read more >
Safari Technology Preview Release Notes - Apple Developer
Note: Shared Tab Groups and syncing for Tab Groups, Website Settings, and Web Extensions are not enabled in this release. Web Inspector. Elements...
Read more >
Chrome Enterprise and Education release notes
Passwords and associated notes display on a sub-page, which is protected by authentication. Google Password Manager: Updates on iOS back to top
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found