Skip to content

Commit fd1a772

Browse files
committed
fix(android): fixed internal style fetch when element was unmounted
1 parent 9785ae4 commit fd1a772

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

android/src/main/java/com/ijzerenhein/sharedelement/RNSharedElementNode.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,8 @@ private boolean fetchInitialStyle() {
162162
int width = view.getWidth();
163163
int height = view.getHeight();
164164
if (width == 0 && height == 0) return false;
165-
Matrix transform = RNSharedElementStyle.getAbsoluteViewTransform(view);
166-
Matrix ancestorTransform = RNSharedElementStyle.getAbsoluteViewTransform(mAncestorView);
165+
Matrix transform = RNSharedElementStyle.getAbsoluteViewTransform(view, false);
166+
Matrix ancestorTransform = RNSharedElementStyle.getAbsoluteViewTransform(mAncestorView, true);
167167
if ((transform == null) || (ancestorTransform == null)) return false;
168168
Rect frame = new Rect(left, top, left + width, top + height);
169169

@@ -260,6 +260,8 @@ private boolean fetchInitialContent() {
260260
// Update cache
261261
mContentCache = content;
262262

263+
// Log.d(LOG_TAG, "Content fetched: " + content);
264+
263265
// Notify callbacks
264266
ArrayList<Callback> callbacks = mContentCallbacks;
265267
mContentCallbacks = null;

android/src/main/java/com/ijzerenhein/sharedelement/RNSharedElementStyle.java

+8-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.util.Locale;
44

5+
import android.util.Log;
56
import android.graphics.Rect;
67
import android.graphics.Color;
78
import android.graphics.Matrix;
@@ -17,6 +18,8 @@
1718
import com.facebook.react.modules.i18nmanager.I18nUtil;
1819

1920
public class RNSharedElementStyle {
21+
static private String LOG_TAG = "RNSharedElementStyle";
22+
2023
static int PROP_OPACITY = 1 << 0;
2124
static int PROP_ELEVATION = 1 << 1;
2225
static int PROP_BACKGROUND_COLOR = 1 << 2;
@@ -131,13 +134,14 @@ static ScaleType getInterpolatingScaleType(RNSharedElementStyle style1, RNShared
131134
return scaleType;
132135
}
133136

134-
static Matrix getAbsoluteViewTransform(View view) {
137+
static Matrix getAbsoluteViewTransform(View view, boolean failIfNotMounted) {
135138
Matrix matrix = new Matrix(view.getMatrix());
136139
float[] vals = new float[9];
137140
matrix.getValues(vals);
138141

139142
float[] vals2 = new float[9];
140143
ViewParent parentView = view.getParent();
144+
141145
while (parentView != null && parentView instanceof View) {
142146
Matrix parentMatrix = ((View)parentView).getMatrix();
143147
parentMatrix.getValues(vals2);
@@ -154,7 +158,9 @@ static Matrix getAbsoluteViewTransform(View view) {
154158

155159
parentView = parentView.getParent();
156160
}
157-
if (parentView == null) return null;
161+
if (parentView == null && failIfNotMounted) {
162+
return null;
163+
}
158164
matrix.setValues(vals);
159165
return matrix;
160166
}

0 commit comments

Comments
 (0)