7
7
import android .util .Log ;
8
8
import android .graphics .Canvas ;
9
9
import android .graphics .Rect ;
10
+ import android .graphics .RectF ;
10
11
import android .graphics .Color ;
11
12
import android .view .View ;
12
13
import android .view .ViewGroup ;
@@ -175,7 +176,7 @@ private void updateLayout() {
175
176
RNSharedElementTransitionItem startItem = mItems .get (Item .START .getValue ());
176
177
RNSharedElementTransitionItem endItem = mItems .get (Item .END .getValue ());
177
178
178
- // Get styles & content
179
+ // Get styles
179
180
RNSharedElementStyle startStyle = startItem .getStyle ();
180
181
RNSharedElementStyle endStyle = endItem .getStyle ();
181
182
if ((startStyle == null ) && (endStyle == null )) return ;
@@ -192,8 +193,8 @@ private void updateLayout() {
192
193
Rect startFrame = (startStyle != null ) ? startStyle .frame : EMPTY_RECT ;
193
194
Rect endLayout = (endStyle != null ) ? endStyle .layout : EMPTY_RECT ;
194
195
Rect endFrame = (endStyle != null ) ? endStyle .frame : EMPTY_RECT ;
195
- Rect parentLayout = new Rect (startLayout );
196
- parentLayout .union (endLayout );
196
+ RectF parentLayout = new RectF (startLayout );
197
+ parentLayout .union (new RectF ( endLayout ) );
197
198
198
199
// Get clipped areas
199
200
Rect startClippedLayout = (startStyle != null ) ? startItem .getClippedLayout () : EMPTY_RECT ;
@@ -202,25 +203,25 @@ private void updateLayout() {
202
203
Rect endClipInsets = getClipInsets (endLayout , endClippedLayout );
203
204
204
205
// Get interpolated layout
205
- Rect interpolatedLayout ;
206
- Rect interpolatedClipInsets ;
206
+ RectF interpolatedLayout ;
207
+ RectF interpolatedClipInsets ;
207
208
RNSharedElementStyle interpolatedStyle ;
208
209
if ((startStyle != null ) && (endStyle != null )) {
209
210
interpolatedLayout = getInterpolatedLayout (startLayout , endLayout , mNodePosition );
210
211
interpolatedClipInsets = getInterpolatedClipInsets (parentLayout , startClipInsets , startClippedLayout , endClipInsets , endClippedLayout , mNodePosition );
211
212
interpolatedStyle = getInterpolatedStyle (startStyle , startContent , endStyle , endContent , mNodePosition );
212
213
} else if (startStyle != null ) {
213
- interpolatedLayout = startLayout ;
214
+ interpolatedLayout = new RectF ( startLayout ) ;
214
215
interpolatedStyle = startStyle ;
215
- interpolatedClipInsets = startClipInsets ;
216
+ interpolatedClipInsets = new RectF ( startClipInsets ) ;
216
217
} else {
217
218
if (!mInitialNodePositionSet ) {
218
219
mNodePosition = 1.0f ;
219
220
mInitialNodePositionSet = true ;
220
221
}
221
- interpolatedLayout = endLayout ;
222
+ interpolatedLayout = new RectF ( endLayout ) ;
222
223
interpolatedStyle = endStyle ;
223
- interpolatedClipInsets = endClipInsets ;
224
+ interpolatedClipInsets = new RectF ( endClipInsets ) ;
224
225
}
225
226
226
227
// Apply clipping insets
@@ -241,8 +242,8 @@ private void updateLayout() {
241
242
super .layout (
242
243
-mParentOffset [0 ],
243
244
-mParentOffset [1 ],
244
- parentLayout .width () - mParentOffset [0 ],
245
- parentLayout .height () - mParentOffset [1 ]
245
+ ( int ) Math . ceil ( parentLayout .width () - mParentOffset [0 ]) ,
246
+ ( int ) Math . ceil ( parentLayout .height () - mParentOffset [1 ])
246
247
);
247
248
setTranslationX (parentLayout .left );
248
249
setTranslationY (parentLayout .top );
@@ -352,22 +353,22 @@ private Rect getClipInsets(Rect layout, Rect clippedLayout) {
352
353
);
353
354
}
354
355
355
- private Rect getInterpolatedClipInsets (
356
- Rect interpolatedLayout ,
356
+ private RectF getInterpolatedClipInsets (
357
+ RectF interpolatedLayout ,
357
358
Rect startClipInsets ,
358
359
Rect startClippedLayout ,
359
360
Rect endClipInsets ,
360
361
Rect endClippedLayout ,
361
362
float position ) {
362
- Rect clipInsets = new Rect ();
363
+ RectF clipInsets = new RectF ();
363
364
364
365
// Top
365
366
if ((endClipInsets .top == 0 ) && (startClipInsets .top != 0 ) && (startClippedLayout .top <= endClippedLayout .top )) {
366
367
clipInsets .top = Math .max (0 , startClippedLayout .top - interpolatedLayout .top );
367
368
} else if ((startClipInsets .top == 0 ) && (endClipInsets .top != 0 ) && (endClippedLayout .top <= startClippedLayout .top )) {
368
369
clipInsets .top = Math .max (0 , endClippedLayout .top - interpolatedLayout .top );
369
370
} else {
370
- clipInsets .top = (int ) ( startClipInsets .top + ((endClipInsets .top - startClipInsets .top ) * position ));
371
+ clipInsets .top = (startClipInsets .top + ((endClipInsets .top - startClipInsets .top ) * position ));
371
372
}
372
373
373
374
// Bottom
@@ -376,7 +377,7 @@ private Rect getInterpolatedClipInsets(
376
377
} else if ((startClipInsets .bottom == 0 ) && (endClipInsets .bottom != 0 ) && (endClippedLayout .bottom >= startClippedLayout .bottom )) {
377
378
clipInsets .bottom = Math .max (0 , interpolatedLayout .bottom - endClippedLayout .bottom );
378
379
} else {
379
- clipInsets .bottom = (int ) ( startClipInsets .bottom + ((endClipInsets .bottom - startClipInsets .bottom ) * position ));
380
+ clipInsets .bottom = (startClipInsets .bottom + ((endClipInsets .bottom - startClipInsets .bottom ) * position ));
380
381
}
381
382
382
383
// Left
@@ -385,7 +386,7 @@ private Rect getInterpolatedClipInsets(
385
386
} else if ((startClipInsets .left == 0 ) && (endClipInsets .left != 0 ) && (endClippedLayout .left <= startClippedLayout .left )) {
386
387
clipInsets .left = Math .max (0 , endClippedLayout .left - interpolatedLayout .left );
387
388
} else {
388
- clipInsets .left = (int ) ( startClipInsets .left + ((endClipInsets .left - startClipInsets .left ) * position ));
389
+ clipInsets .left = (startClipInsets .left + ((endClipInsets .left - startClipInsets .left ) * position ));
389
390
}
390
391
391
392
// Right
@@ -394,18 +395,18 @@ private Rect getInterpolatedClipInsets(
394
395
} else if ((startClipInsets .right == 0 ) && (endClipInsets .right != 0 ) && (endClippedLayout .right >= startClippedLayout .right )) {
395
396
clipInsets .right = Math .max (0 , interpolatedLayout .right - endClippedLayout .right );
396
397
} else {
397
- clipInsets .right = (int ) ( startClipInsets .right + ((endClipInsets .right - startClipInsets .right ) * position ));
398
+ clipInsets .right = (startClipInsets .right + ((endClipInsets .right - startClipInsets .right ) * position ));
398
399
}
399
400
400
401
return clipInsets ;
401
402
}
402
403
403
- private Rect getInterpolatedLayout (Rect layout1 , Rect layout2 , float position ) {
404
- return new Rect (
405
- (int ) ( layout1 .left + ((layout2 .left - layout1 .left ) * position )),
406
- (int ) ( layout1 .top + ((layout2 .top - layout1 .top ) * position )),
407
- (int ) ( layout1 .right + ((layout2 .right - layout1 .right ) * position )),
408
- (int ) ( layout1 .bottom + ((layout2 .bottom - layout1 .bottom ) * position ))
404
+ private RectF getInterpolatedLayout (Rect layout1 , Rect layout2 , float position ) {
405
+ return new RectF (
406
+ (layout1 .left + ((layout2 .left - layout1 .left ) * position )),
407
+ (layout1 .top + ((layout2 .top - layout1 .top ) * position )),
408
+ (layout1 .right + ((layout2 .right - layout1 .right ) * position )),
409
+ (layout1 .bottom + ((layout2 .bottom - layout1 .bottom ) * position ))
409
410
);
410
411
}
411
412
0 commit comments