-
-
Notifications
You must be signed in to change notification settings - Fork 530
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
SVG component becomes transparent when goBack #773
Comments
I have same issue with custom headerCenter and headerLeft, if you add any Image component in screen or header the same thing happen, maybe native stack is very fast? or React Native bridge its slower? @wkozyra95 |
FIY: only happen in Android |
android react-native-fast-image have the same problem when goback android ViewManager onDropViewInstance method callback immediately and view detach the tree (android native), although view detach the tree view can't invisible immediately until animation finished
image will white requestManager.clear(view) immediately
i think SVG component is the same issue as fastimage View detached Animation has not started SVG component redraw empty bitmap |
@fangasvsass amazing! but the same happen with de header (react-native-screens's HeaderConfig), Do you found any solution? |
@msvargas HeaderConfig view is not rnscreen child ,you can call startViewTransition with HeaderConfig views add code
Complete code
|
Got the same problem with react-native-svg and on Android. When you trigger to go back, the svgs disappear while the transitions happens. |
Thank you!! this fix the header, @WoLewicki please check this fix the same issue but in StackHeaderConfig with headerLeft config + Image component. Short solution: react-native-screens+2.16.1.patchindex 56ffaf2..32e741f 100644
--- a/node_modules/react-native-screens/android/src/main/java/com/swmansion/rnscreens/ScreenStackHeaderConfig.java
+++ b/node_modules/react-native-screens/android/src/main/java/com/swmansion/rnscreens/ScreenStackHeaderConfig.java
@@ -300,9 +301,20 @@ public class ScreenStackHeaderConfig extends ViewGroup {
view.setLayoutParams(params);
mToolbar.addView(view);
+
}
}
+ @Override
+ public View getChildAt(int index) {
+ return getConfigSubview(index);
+ }
+
+ @Override
+ public int getChildCount() {
+ return getConfigSubviewsCount();
+ }
+
private void maybeUpdate() {
if (getParent() != null && !mDestroyed) {
onUpdate(); |
Hi @fangasvsass with react-native-svg happen the same with, it calls onDropInstance, Do you found any solution for this in react-native-fast-image? thank you SvgViewManager.java @Override
public void onDropViewInstance(@Nonnull ReactViewGroup view) {
super.onDropViewInstance(view);
mTagToSvgView.remove(view.getId());
}
|
Can you submit a PR with the changes and a test case that shows it fixes the bug? |
as @msvargas I'm having the same issue on fast-image. See comment with sample. Maybe a solution would be the to wait the animation interaction to finish so it can drop the view instances. |
Sure, this only working when you have image components in HeaderConfig. |
Thanks! I will check about it |
Update: If replace headerLeft with backButtonImage, the SVG working properly. @WoLewicki Do you have any idea about it? thanks! |
The |
Ok, but a minor change in StackHeaderConfig I fix the header when calling goBack in JS, however, thank you |
I'm to be working on the issue, create Test773, and share with your another video with the issue in the header and screen. :) Scenaries to reproduce issue:
react-native-screens v2.17.1 TestsExample/src/Test773.jsimport React from 'react';
import {Button, Text, View, StyleSheet, Image, Pressable} from 'react-native';
import {NavigationContainer, useNavigation} from '@react-navigation/native';
import {createNativeStackNavigator} from 'react-native-screens/native-stack';
import Svg, {Circle, Rect} from 'react-native-svg';
const backButtonImage = require('../assets/backButton.png');
const navigationRef = React.createRef();
const HeaderBackButton = () => (
<Pressable onPress={() => navigationRef.current.goBack()}>
<Image source={backButtonImage} />
</Pressable>
);
const Screen2 = () => {
const navigation = useNavigation();
return (
<View
style={{
backgroundColor: '#08141B',
flex: 1,
justifyContent: 'center',
alignItems: 'center',
}}>
<View
style={[
StyleSheet.absoluteFill,
{alignItems: 'center', justifyContent: 'center'},
]}>
<Svg height="50%" width="50%" viewBox="0 0 100 100">
<Circle
cx="50"
cy="50"
r="45"
stroke="blue"
strokeWidth="2.5"
fill="green"
/>
<Rect
x="15"
y="15"
width="70"
height="70"
stroke="red"
strokeWidth="2"
fill="yellow"
/>
</Svg>
</View>
<Button title="navigation.goBack()" onPress={() => navigation.goBack()}>
<Text>Go back JS</Text>
</Button>
</View>
);
};
const Screen1 = () => {
const navigation = useNavigation();
return (
<View
style={{
flex: 1,
justifyContent: 'center',
alignItems: 'center',
}}>
<Button
title="Go to Screen 2"
onPress={() => navigation.navigate('Screen2')}
/>
</View>
);
};
const Stack = createNativeStackNavigator();
const App = () => {
return (
<NavigationContainer ref={navigationRef}>
<Stack.Navigator
// mode="modal"
screenOptions={{
// backButtonImage,
headerLeft: HeaderBackButton,
gestureEnabled: true,
topInsetEnabled: false,
stackAnimation: 'slide_from_right',
}}>
<Stack.Screen
name="Screen1"
options={{headerShown: false}}
component={Screen1}
/>
<Stack.Screen name="Screen2" component={Screen2} />
</Stack.Navigator>
</NavigationContainer>
);
};
export default App; |
@hehex9 @ferrannp After spending 3 days approx. I found the error and the solution, the error is that react-native-svg calls bitmap.recycle() and ignore when react-native-screen call startViewTransition. I share the solution to help anybody You can apply this patch: react-native-svg+12.1.0diff --git a/node_modules/react-native-svg/android/src/main/java/com/horcrux/svg/SvgView.java b/node_modules/react-native-svg/android/src/main/java/com/horcrux/svg/SvgView.java
index 5c792bd..d070e0e 100644
--- a/node_modules/react-native-svg/android/src/main/java/com/horcrux/svg/SvgView.java
+++ b/node_modules/react-native-svg/android/src/main/java/com/horcrux/svg/SvgView.java
@@ -66,6 +66,7 @@ public class SvgView extends ReactViewGroup implements ReactCompoundView, ReactC
}
private @Nullable Bitmap mBitmap;
+ private boolean mRemovalTransitionStarted = false;
public SvgView(ReactContext reactContext) {
super(reactContext);
@@ -90,12 +91,30 @@ public class SvgView extends ReactViewGroup implements ReactCompoundView, ReactC
((VirtualView) parent).getSvgView().invalidate();
return;
}
- if (mBitmap != null) {
- mBitmap.recycle();
+ // Additional: maybe its not necessary since Android 2.3.3 https://developer.android.com/topic/performance/graphics/manage-memory#recycle
+ if(!mRemovalTransitionStarted){
+ if (mBitmap != null) {
+ mBitmap.recycle();
+ }
+ mBitmap = null;
+ }
+ }
+
+ @Override
+ public void startViewTransition(View view) {
+ super.startViewTransition(view);
+ mRemovalTransitionStarted = true;
+ }
+
+ @Override
+ public void endViewTransition(View view) {
+ super.endViewTransition(view);
+ if (mRemovalTransitionStarted) {
+ mRemovalTransitionStarted = false;
}
- mBitmap = null;
}
+
@Override
protected void onDraw(Canvas canvas) {
if (getParent() instanceof VirtualView) {
Thanks |
So it is rather an issue on the side of |
I think the issue is on the react-native-svg side, Can you create a PR in react-native-svg to support o fix correct behavior with react-native-screens? because react-native-svg is used in a lot of apps
|
I think you should create this PR @msvargas since you have a lot of insight to this. Therefore, you could submit a much more descriptive PR with the examples of how the change fixes the problems. You can link that PR here so it is easy to elaborate if needed. |
@msvargas can confirm your patch works great on my device |
I made a PR in |
test the code not work and if use native stack only one screen attached Window pre screen images will call onDetachedFromWindow when goBack image becomes transparent |
@fangasvsass I am sorry, but I don't understand. Could you be more descriptive? |
sorry My English is bad ,open the A screen then open b Screen ,when open b Screen A screen's view will detachedFromWindow because A screen removed from android rootview A screen's image will be cleared @WoLewicki |
@fangasvsass can you post a reproduction where it is an issue? What is the problem with clearing the image after the screen is detached? |
can confirm the PR for |
Ok so I will close this issue since there is nothing that can be done in |
It works !! Thanks |
+1 working on static and animated svgs. |
can i get SvgView.java full code,thanks!!! |
This PR fixes the issues in `react-native-screens` and probably other libraries using native `Fragments` for transitions on Android (see software-mansion/react-native-screens#773). It moves the recycling and setting `mBitMap` to `null` to `onDetachedFromWindow` when the view is removed from `react` view hierarchy. `invalidate` is not always the proper place for doing it since the native view can still be visible for the user after the `invalidate` is called (see this comment with video: software-mansion/react-native-screens#773 (comment)).
The same issue occurs with React Native Skia: when clicking away from the current screen on a |
I can confirm that we are affected by an issue that seems familiar. |
Description
There is an obvious UI blinking that occurs when returning from a screen that uses svg (react-native-svg), svg views in the child screen will become transparent and then disappear with the screen. (check the video)
It happens in navigators created by native-stack (createNativeStackNavigator) @react-navigation/stack works just fine in this scenario.
Not sure if it's related to react-native-svg.
(only happens on Android)
Screenshots
Screenrecord-2021-01-11-15-37-14-455.mp4
Steps To Reproduce
check the snack below
Expected behavior
SVG View should be visible util the screen is completely disappear (pop to bottom / right)
Actual behavior
will becomes transparent when navigating back to its parent screen
Snack or minimal code example
https://snack.expo.io/@hehex/native-stack-svg-blink
Package versions
The text was updated successfully, but these errors were encountered: