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] Visibility Artifact During Page Transition and Possible Solution #1968

Open
alabsi91 opened this issue Nov 14, 2023 · 3 comments · May be fixed by #2110
Open

[Android] Visibility Artifact During Page Transition and Possible Solution #1968

alabsi91 opened this issue Nov 14, 2023 · 3 comments · May be fixed by #2110
Labels
Missing info The user didn't precise the problem enough Platform: Android This issue is specific to Android Repro provided A reproduction with a snack or repo is provided

Comments

@alabsi91
Copy link

alabsi91 commented Nov 14, 2023

The Issue

In the new Android 13 screen transition, an issue arises when the new screen pushes the old one, causing a white or black layer to appear between them. While this problem may exist in the old screen transition, it becomes more noticeable in the new version.

Note
In the following examples to make the animation more obvious, I adjusted the animation durations in the files located at node_modules\react-native-screens\android\src\main\res\v33\anim-v33.

Default Fixed
before.mp4
after.mp4

The Fix

Fortunately, I have fixed this issue by implementing the following changes:

  1. Step One: Create a file at android\app\src\main\res\drawable\alpha_screen.xml.
<?xml version="1.0" encoding="utf-8"?>
<layer-list
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:opacity="opaque">
    <item android:gravity="fill">
        <color android:color="@android:color/transparent" />
    </item>
</layer-list>
  1. Step Two: Add the following line to the file at android\app\src\main\res\values\styles.xml.
<resources>
    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="android:editTextBackground">@drawable/rn_edit_text_material</item>
+       <item name="android:windowBackground">@drawable/alpha_screen</item>
    </style>
</resources>
  1. Step Three: For older Android versions, you might have to make the default navigation background color transparent:
<NavigationContainer>
    <Stack.Navigator
       screenOptions={{contentStyle: {backgroundColor: 'transparent'}}} // 👈  add this
       initialRouteName="screen1">
       <Stack.Screen name="screen1" component={Screen1} />
       <Stack.Screen name="screen2" component={Screen2} />
    </Stack.Navigator>
</NavigationContainer>

Steps to reproduce

  1. Setup a new project with react-navigation

Snack or a link to a repository

https://github.com/alabsi91/rn-screens-android-transitions-animation-fix

Screens version

3.27.0

React Native version

0.72.6

Platforms

Android

JavaScript runtime

Hermes

Workflow

React Native (without Expo)

Architecture

Paper (Old Architecture)

Build type

Debug mode

Device

Android emulator

Device model

Android 13

Acknowledgements

Yes

@github-actions github-actions bot added Missing info The user didn't precise the problem enough Repro provided A reproduction with a snack or repo is provided labels Nov 14, 2023
Copy link

github-actions bot commented Nov 14, 2023

Hey! 👋

It looks like you've omitted a few important sections from the issue template.

Please complete Description section.

@github-actions github-actions bot added the Platform: Android This issue is specific to Android label Nov 14, 2023
@kkafar
Copy link
Member

kkafar commented Nov 16, 2023

Hey, this looks great, thanks for contributing!
I'll get back to you once I have opportunity to test these changes

@alabsi91
Copy link
Author

alabsi91 commented Dec 9, 2023

UPDATE: This approach does not work on One UI Samsung devices; you will still see black edges during the transition animation. The only fix I found is to set the screen options presentation to 'transparentModal' This will have a different transition animation, and I'm not sure if it has any performance drawbacks.

@tboba tboba linked a pull request Apr 24, 2024 that will close this issue
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Missing info The user didn't precise the problem enough 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