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

[Android] headers show strange artifacts after unfocus -> focus since v3.32 #2212

Closed
arjovanramshorst opened this issue Jun 26, 2024 · 1 comment · Fixed by #2216
Closed
Assignees
Labels
Platform: Android This issue is specific to Android Repro provided A reproduction with a snack or repo is provided

Comments

@arjovanramshorst
Copy link

arjovanramshorst commented Jun 26, 2024

Description

After updating to react-native 0.73 I also updated many packages that weren't locked to exact versions, including react-native-screens, which introduced a bug (android only) in how headers are rendered. It only occurs when focusing a screen for the second time (the initial render looks good, but navigating away and back leads to a 'ghost' header underneath the original header. It's mostly visible because the 'ghost' header appears to have shadows, even though my app does not have shadows below headers. Every screen that renders a native stack header is affected.

Initial render (how it's supposed to look):
image

After switching to a different screen (tab or stack does not matter) and going back:
image

Steps to reproduce

  1. Run the following code on an android emulator/device with dependencies (or checkout the reproduction in https://github.com/arjovanramshorst/react-native-screens-bug-repro)
// package.json
{
    "react-native-screens": "3.32.0",
    "@react-navigation/native": "^6.1.6",
    "@react-navigation/native-stack": "^6.9.12",
}
import React from 'react';
import {NavigationContainer} from '@react-navigation/native';
import {createNativeStackNavigator} from '@react-navigation/native-stack';
import {Button, Text, View} from 'react-native';

const Stack = createNativeStackNavigator();

export const StorybookNavigation: React.FC<{}> = () => {
  return (
    <NavigationContainer>
      <Stack.Navigator>
        <Stack.Screen
          name="Screen1"
          options={{title: 'Screen 1', headerTransparent: true}}
          component={Screen1}
        />
        <Stack.Screen
          name="Screen2"
          options={{title: 'Screen 2', headerTransparent: true}}
          component={Screen2}
        />
      </Stack.Navigator>
    </NavigationContainer>
  );
};

const Screen1 = ({navigation}: any) => {
  return (
    <View
      style={{
        flex: 1,
        alignItems: 'center',
        justifyContent: 'center',
        backgroundColor: 'white',
      }}>
      <Text>Screen 1 </Text>
      <Button
        title={'Go to screen 2'}
        onPress={() => {
          navigation.push('Screen2');
        }}
      />
    </View>
  );
};

const Screen2 = () => {
  return (
    <View
      style={{
        flex: 1,
        backgroundColor: 'white',
        alignItems: 'center',
        justifyContent: 'center',
      }}>
      <Text>Screen 2 </Text>
    </View>
  );
};
  1. Navigate to screen 2 and back to screen 1, and notice the difference between before and after navigating. It is very apparent with headerTransparent: true, however, it is also visible with other changes to options.

Snack or a link to a repository

https://github.com/arjovanramshorst/react-native-screens-bug-repro

Screens version

3.32.0

React Native version

0.73.8

Platforms

Android

JavaScript runtime

None

Workflow

React Native (without Expo)

Architecture

None

Build type

Release mode

Device

None

Device model

Every device (emulator/real/debug/release build)

Acknowledgements

Yes

@github-actions github-actions bot added Missing repro This issue need minimum repro scenario Platform: Android This issue is specific to Android labels Jun 26, 2024
@github-actions github-actions bot added Repro provided A reproduction with a snack or repo is provided and removed Missing repro This issue need minimum repro scenario labels Jun 26, 2024
@alduzy alduzy closed this as completed in 9bda252 Jun 27, 2024
@alduzy
Copy link
Member

alduzy commented Jun 27, 2024

@arjovanramshorst Thanks for reporting 👍

alduzy added a commit that referenced this issue Jun 28, 2024
## Description

This PR intents to fix header shadow not being hidden after navigating
back to a screen. The bug was visible when using `headerTransparent:
true` option.

The origin of this bug is [This
PR](#2116)
fixing build depracations. Setting the `elevation` on appBarLayout
requires resetting the `stateListAnimator` to work properly, as opossed
to deprecated `targetElevation` used before.

For more info visit:
https://developer.android.com/reference/com/google/android/material/appbar/AppBarLayout#setTargetElevation(float)

Fixes #2212 .


## Changes

- added missing `appBarLayout?.stateListAnimator` reset.

## Screenshots / GIFs

Here you can add screenshots / GIFs documenting your change.

You can add before / after section if you're changing some behavior.

### Before
![Screenshot 2024-06-27 at 11 39
50](https://github.com/software-mansion/react-native-screens/assets/91994767/78c42cd3-4523-46f2-93ea-2aa4a6f4da4f)

### After
![Screenshot 2024-06-27 at 11 39
29](https://github.com/software-mansion/react-native-screens/assets/91994767/b0d32daa-ee98-438e-90cb-621bb6b13ad0)



## Test code and steps to reproduce

1. use `Test1097.tsx` repro
2. navigate into second or third screen
3. go back to the first screen

## Checklist

- [x] Included code example that can be used to test this change
- [x] Ensured that CI passes
github-merge-queue bot pushed a commit to valora-inc/wallet that referenced this issue Aug 2, 2024
### Description

Upgrades [react-native-screens to
3.33.0](https://github.com/software-mansion/react-native-screens/releases/tag/3.33.0)
which contains a fix for the [header shadow display
issue](software-mansion/react-native-screens#2212)
on goBack.

### Screenshots

| Android Before | Android After |
| ----- | ----- |
|
![](https://github.com/user-attachments/assets/ac4a0f71-c751-45d8-b852-adb79367f78a
"Android Before") |
![](https://github.com/user-attachments/assets/ea165706-8dab-45b3-90a3-b2652014c1a6
"Android After") |

### Test plan

- [x] Tested locally on Android

### Related issues

- Fixes ACT-1335
-
react-navigation/react-navigation#12063 (comment)

### Backwards compatibility

Yes

### Network scalability

N/A
ja1ns pushed a commit to WiseOwlTech/react-native-screens that referenced this issue Oct 9, 2024
)

## Description

This PR intents to fix header shadow not being hidden after navigating
back to a screen. The bug was visible when using `headerTransparent:
true` option.

The origin of this bug is [This
PR](software-mansion#2116)
fixing build depracations. Setting the `elevation` on appBarLayout
requires resetting the `stateListAnimator` to work properly, as opossed
to deprecated `targetElevation` used before.

For more info visit:
https://developer.android.com/reference/com/google/android/material/appbar/AppBarLayout#setTargetElevation(float)

Fixes software-mansion#2212 .


## Changes

- added missing `appBarLayout?.stateListAnimator` reset.

## Screenshots / GIFs

Here you can add screenshots / GIFs documenting your change.

You can add before / after section if you're changing some behavior.

### Before
![Screenshot 2024-06-27 at 11 39
50](https://github.com/software-mansion/react-native-screens/assets/91994767/78c42cd3-4523-46f2-93ea-2aa4a6f4da4f)

### After
![Screenshot 2024-06-27 at 11 39
29](https://github.com/software-mansion/react-native-screens/assets/91994767/b0d32daa-ee98-438e-90cb-621bb6b13ad0)



## Test code and steps to reproduce

1. use `Test1097.tsx` repro
2. navigate into second or third screen
3. go back to the first screen

## Checklist

- [x] Included code example that can be used to test this change
- [x] Ensured that CI passes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Platform: Android This issue is specific to Android Repro provided A reproduction with a snack or repo is provided
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants