React Native启动页转场安卓与iOS表现不一致,如何消除安卓额外动画?
Hey there! Let's fix those extra transition effects on Android for your react-native-splash-screen setup. I've dealt with this exact issue before, so here's what you need to do step by step:
1. Disable the fade-out animation when hiding the splash screen
The library's hide() method on Android actually accepts an optional parameter for animation duration. By setting this to 0, you'll skip the default fade-out effect entirely. Update your React Native code where you call hide():
// Replace this: SplashScreen.hide(); // With this: SplashScreen.hide(0);
2. Remove Android's default Activity transition animations
If your initial screen is still sliding up from the bottom, that's Android's default Activity switch animation. To turn this off, open your android/app/src/main/AndroidManifest.xml and add the android:windowAnimationStyle="@null" attribute to your MainActivity:
<activity android:name=".MainActivity" android:label="@string/app_name" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize|uiMode" android:launchMode="singleTask" android:exported="true" android:windowAnimationStyle="@null"> <!-- Add this line --> </activity>
3. Fix the "shrinking with black edges" issue
That slight shrink usually happens because your splash screen drawable isn't properly set to fill the screen. Open your splash screen drawable file (usually at android/app/src/main/res/drawable/splash_screen.xml) and make sure the bitmap is configured to fill the screen correctly:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <!-- Match your splash image's background color to avoid black edges --> <item android:drawable="@color/splash_background" /> <item> <bitmap android:gravity="fill" <!-- Use fill or centerCrop depending on your image --> android:src="@drawable/your_splash_image" /> </item> </layer-list>
Also, double-check that your SplashTheme in android/app/src/main/res/values/styles.xml doesn't have any unintended animation properties. Add these lines to ensure no extra animations are applied:
<style name="SplashTheme" parent="Theme.AppCompat.Light.NoActionBar"> <!-- Your existing windowBackground and other properties --> <item name="android:windowAnimationStyle">@null</item> <item name="android:windowEnterAnimation">@null</item> <item name="android:windowExitAnimation">@null</item> </style>
After making these changes, rebuild your Android app (npx react-native run-android) and the transitions should match the iOS behavior—straight replacement with no extra effects.
内容的提问来源于stack exchange,提问作者Juan

