Skip to content

Commit d6e1445

Browse files
committed
fix(android): fixed text context sometimes not visible (clipped)
1 parent 9c374e9 commit d6e1445

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

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

+1
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ private boolean fetchInitialStyle() {
198198
style.layout = layout;
199199
style.frame = frame;
200200
style.transform = transform;
201+
style.ancestorTransform = ancestorTransform;
201202

202203
// Get opacity
203204
style.opacity = view.getAlpha();

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

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public class RNSharedElementStyle {
4040
Rect layout = new Rect(); // absolute layout on screen
4141
Rect frame = new Rect(); // frame rect relative to parent
4242
Matrix transform = new Matrix();
43+
Matrix ancestorTransform = new Matrix();
4344
ScaleType scaleType = ScaleType.FIT_XY;
4445
int backgroundColor = Color.TRANSPARENT;
4546
float opacity = 1;

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

+10-4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import android.view.ViewParent;
66
import android.view.ViewGroup;
77
import android.graphics.Rect;
8+
import android.graphics.Matrix;
89

910
class RNSharedElementTransitionItem {
1011
static private String LOG_TAG = "RNSharedElementTransitionItem";
@@ -109,10 +110,15 @@ View getView() {
109110
Rect getClippedLayout() {
110111
if (mClippedLayoutCache != null) return mClippedLayoutCache;
111112
if (mStyle == null) return null;
113+
112114
View view = getView();
113115
View ancestorView = mNode.getAncestorView();
114-
int[] ancestorLocation = new int[2];
115-
ancestorView.getLocationOnScreen(ancestorLocation);
116+
117+
// Get ancestor transform
118+
float[] f = new float[9];
119+
mStyle.ancestorTransform.getValues(f);
120+
int ancestorTranslateX = (int) f[Matrix.MTRANS_X];
121+
int ancestorTranslateY = (int) f[Matrix.MTRANS_Y];
116122

117123
// Get visible area (some parts may be clipped in a scrollview or something)
118124
Rect clippedLayout = new Rect(mStyle.layout);
@@ -123,8 +129,8 @@ Rect getClippedLayout() {
123129
if (!(parentView instanceof ViewGroup)) break;
124130
ViewGroup viewGroup = (ViewGroup) parentView;
125131
viewGroup.getLocationOnScreen(location);
126-
location[0] -= ancestorLocation[0];
127-
location[1] -= ancestorLocation[1];
132+
location[0] -= ancestorTranslateX;
133+
location[1] -= ancestorTranslateY;
128134

129135
bounds.left = location[0];
130136
bounds.top = location[1];

0 commit comments

Comments
 (0)