/
RNSharedElementContent.java
76 lines (71 loc) · 2.83 KB
/
RNSharedElementContent.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package versioned.host.exp.exponent.modules.api.components.sharedelement;
import android.view.View;
import android.graphics.RectF;
import android.graphics.drawable.Drawable;
import android.widget.ImageView;
import com.facebook.drawee.view.GenericDraweeView;
import com.facebook.drawee.generic.GenericDraweeHierarchy;
import com.facebook.drawee.interfaces.DraweeController;
class RNSharedElementContent {
View view;
RectF size;
static RectF getSize(View view) {
if (view instanceof GenericDraweeView) {
GenericDraweeView imageView = (GenericDraweeView) view;
DraweeController controller = imageView.getController();
GenericDraweeHierarchy hierarchy = imageView.getHierarchy();
String controllerDetails = controller.toString();
if (controllerDetails.contains("fetchedImage=0,")) {
return null;
}
Drawable drawable = imageView.getDrawable();
RectF imageBounds = new RectF();
hierarchy.getActualImageBounds(imageBounds);
return imageBounds;
} else if (view instanceof ImageView) {
ImageView imageView = (ImageView) view;
Drawable drawable = imageView.getDrawable();
if (drawable == null) return null;
int width = drawable.getIntrinsicWidth();
int height = drawable.getIntrinsicHeight();
if ((width <= 0) || (height <= 0)) {
return null;
}
return new RectF(0, 0, width, height);
}
return new RectF(0, 0, view.getWidth(), view.getHeight());
}
/*
static public Rect getLayout(Rect layout, RectF contentSize, ScaleType scaleType, boolean reverse) {
float width = layout.width();
float height = layout.height();
float contentAspectRatio = (contentSize.width() / contentSize.height());
boolean lo = (width / height) < contentAspectRatio;
boolean aspectRatioCriteria = reverse ? !lo : lo;
if (scaleType == ScaleType.FIT_CENTER) {
// contain
if (aspectRatioCriteria) {
height = width / contentAspectRatio;
} else {
width = height * contentAspectRatio;
}
} else if (scaleType == ScaleType.CENTER_CROP) {
// cover
if (aspectRatioCriteria) {
width = height * contentAspectRatio;
} else {
height = width / contentAspectRatio;
}
} else if (scaleType == ScaleType.CENTER_INSIDE) {
// center
width = contentSize.width();
height = contentSize.height();
}
return new Rect(
(int) (layout.left + ((layout.width() - width) / 2)),
(int) (layout.top + ((layout.height() - height) / 2)),
(int) (layout.right - ((layout.width() - width) / 2)),
(int) (layout.bottom - ((layout.height() - height) / 2))
);
}*/
}