Skip to content

Commit ee27709

Browse files
committed
fix(android): fixed transition when element was scaled
1 parent 09c6c56 commit ee27709

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

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

+12-7
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
public class RNSharedElementTransition extends ViewGroup {
2323
static private String LOG_TAG = "RNSharedElementTransition";
24+
static private Rect EMPTY_RECT = new Rect();
2425

2526
enum Item {
2627
START(0),
@@ -180,15 +181,17 @@ private void updateLayout() {
180181
RNSharedElementContent endContent = endItem.getContent();
181182

182183
// Get layout
183-
Rect startLayout = (startStyle != null) ? startStyle.layout : new Rect();
184-
Rect endLayout = (endStyle != null) ? endStyle.layout : new Rect();
184+
Rect startLayout = (startStyle != null) ? startStyle.layout : EMPTY_RECT;
185+
Rect startFrame = (startStyle != null) ? startStyle.frame : EMPTY_RECT;
186+
Rect endLayout = (endStyle != null) ? endStyle.layout : EMPTY_RECT;
187+
Rect endFrame = (endStyle != null) ? endStyle.frame : EMPTY_RECT;
185188
Rect parentLayout = new Rect(startLayout);
186189
parentLayout.union(endLayout);
187190

188191
// Get clipped areas
189-
Rect startClippedLayout = (startStyle != null) ? startItem.getClippedLayout() : new Rect();
192+
Rect startClippedLayout = (startStyle != null) ? startItem.getClippedLayout() : EMPTY_RECT;
190193
Rect startClipInsets = getClipInsets(startLayout, startClippedLayout);
191-
Rect endClippedLayout = (endStyle != null) ? endItem.getClippedLayout() : new Rect();
194+
Rect endClippedLayout = (endStyle != null) ? endItem.getClippedLayout() : EMPTY_RECT;
192195
Rect endClipInsets = getClipInsets(endLayout, endClippedLayout);
193196

194197
// Get interpolated layout
@@ -260,8 +263,9 @@ private void updateLayout() {
260263
mStartView.updateViewAndDrawable(
261264
interpolatedLayout,
262265
parentLayout,
263-
startContent,
264266
startLayout,
267+
startFrame,
268+
startContent,
265269
interpolatedStyle,
266270
startAlpha,
267271
mResize,
@@ -275,8 +279,9 @@ private void updateLayout() {
275279
mEndView.updateViewAndDrawable(
276280
interpolatedLayout,
277281
parentLayout,
278-
endContent,
279282
endLayout,
283+
endFrame,
284+
endContent,
280285
interpolatedStyle,
281286
endAlpha,
282287
mResize,
@@ -464,4 +469,4 @@ private void fireMeasureEvent(String name, RNSharedElementTransitionItem item, R
464469
"onMeasureNode",
465470
eventData);
466471
}
467-
}
472+
}

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

+6-5
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ public boolean hasOverlappingRendering() {
2727
void updateViewAndDrawable(
2828
Rect layout,
2929
Rect parentLayout,
30-
RNSharedElementContent content,
3130
Rect originalLayout,
31+
Rect originalFrame,
32+
RNSharedElementContent content,
3233
RNSharedElementStyle style,
3334
float alpha,
3435
RNSharedElementResize resize,
@@ -51,8 +52,8 @@ void updateViewAndDrawable(
5152
int width = layout.width();
5253
int height = layout.height();
5354
if (useGPUScaling) {
54-
int originalWidth = originalLayout.width();
55-
int originalHeight = originalLayout.height();
55+
int originalWidth = originalFrame.width();
56+
int originalHeight = originalFrame.height();
5657

5758
// Update view
5859
layout(0, 0, originalWidth, originalHeight);
@@ -71,8 +72,8 @@ void updateViewAndDrawable(
7172
break;
7273
case CLIP:
7374
case NONE:
74-
scaleX = 1.0f;
75-
scaleY = 1.0f;
75+
scaleX = (float) originalWidth / (float) originalLayout.width();
76+
scaleY = (float) originalHeight / (float) originalLayout.height();
7677
break;
7778
}
7879

0 commit comments

Comments
 (0)