Skip to content

Commit 9c374e9

Browse files
committed
fix(android): fixed support.v4 build error and RTL detection
1 parent e983892 commit 9c374e9

File tree

4 files changed

+23
-7
lines changed

4 files changed

+23
-7
lines changed

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

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public class RNSharedElementModule extends ReactContextBaseJavaModule {
1717
public RNSharedElementModule(ReactApplicationContext reactContext, RNSharedElementNodeManager nodeManager) {
1818
super(reactContext);
1919
mNodeManager = nodeManager;
20+
mNodeManager.setContext(reactContext);
2021
}
2122

2223
@Override

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

+7-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import android.graphics.Matrix;
1313
import android.graphics.drawable.Animatable;
1414
import android.widget.ImageView;
15+
import android.content.Context;
1516

1617
import com.facebook.react.bridge.Callback;
1718
import com.facebook.react.bridge.ReadableMap;
@@ -34,6 +35,7 @@ class RNSharedElementNode {
3435
private View mAncestorView;
3536
private boolean mIsParent;
3637
private ReadableMap mStyleConfig;
38+
private Context mContext;
3739
private View mResolvedView;
3840
private int mRefCount;
3941
private int mHideRefCount;
@@ -45,12 +47,13 @@ class RNSharedElementNode {
4547
private BaseControllerListener<ImageInfo> mDraweeControllerListener;
4648
private Handler mRetryHandler;
4749

48-
RNSharedElementNode(int reactTag, View view, boolean isParent, View ancestorView, ReadableMap styleConfig) {
50+
RNSharedElementNode(int reactTag, View view, boolean isParent, View ancestorView, ReadableMap styleConfig, Context context) {
4951
mReactTag = reactTag;
5052
mView = view;
5153
mAncestorView = ancestorView;
5254
mIsParent = isParent;
5355
mStyleConfig = styleConfig;
56+
mContext = context;
5457
mRefCount = 1;
5558
mHideRefCount = 0;
5659
mHideAlpha = 1;
@@ -191,7 +194,7 @@ private boolean fetchInitialStyle() {
191194
Rect layout = new Rect(left, top, left + width, top + height);
192195

193196
// Create style
194-
RNSharedElementStyle style = new RNSharedElementStyle(mStyleConfig);
197+
RNSharedElementStyle style = new RNSharedElementStyle(mStyleConfig, mContext);
195198
style.layout = layout;
196199
style.frame = frame;
197200
style.transform = transform;
@@ -207,6 +210,8 @@ private boolean fetchInitialStyle() {
207210
// Update initial style cache
208211
mStyleCache = style;
209212

213+
//Log.d(LOG_TAG, "Style fetched: " + style);
214+
210215
// Notify callbacks
211216
ArrayList<Callback> callbacks = mStyleCallbacks;
212217
mStyleCallbacks = null;

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

+11-1
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44
import java.util.HashMap;
55

66
import android.view.View;
7+
import android.content.Context;
78

89
import com.facebook.react.bridge.ReadableMap;
910
import com.facebook.react.uimanager.NativeViewHierarchyManager;
1011

1112
class RNSharedElementNodeManager {
1213
private Map<Integer, RNSharedElementNode> mNodes = new HashMap<Integer, RNSharedElementNode>();
1314
private NativeViewHierarchyManager mNativeViewHierarchyManager;
15+
private Context mContext;
1416

1517
void setNativeViewHierarchyManager(NativeViewHierarchyManager nativeViewHierarchyManager) {
1618
mNativeViewHierarchyManager = nativeViewHierarchyManager;
@@ -20,14 +22,22 @@ NativeViewHierarchyManager getNativeViewHierarchyManager() {
2022
return mNativeViewHierarchyManager;
2123
}
2224

25+
void setContext(Context context) {
26+
mContext = context;
27+
}
28+
29+
Context getContext() {
30+
return mContext;
31+
}
32+
2333
RNSharedElementNode acquire(int reactTag, View view, boolean isParent, View ancestor, ReadableMap styleConfig) {
2434
synchronized (mNodes) {
2535
RNSharedElementNode node = mNodes.get(reactTag);
2636
if (node != null) {
2737
node.setRefCount(node.getRefCount() + 1);
2838
return node;
2939
}
30-
node = new RNSharedElementNode(reactTag, view, isParent, ancestor, styleConfig);
40+
node = new RNSharedElementNode(reactTag, view, isParent, ancestor, styleConfig, mContext);
3141
mNodes.put(reactTag, node);
3242
return node;
3343
}

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@
55
import android.graphics.Rect;
66
import android.graphics.Color;
77
import android.graphics.Matrix;
8-
import android.support.v4.text.TextUtilsCompat;
9-
import android.support.v4.view.ViewCompat;
108
import android.view.View;
119
import android.view.ViewParent;
10+
import android.content.Context;
1211

1312
import com.facebook.react.uimanager.PixelUtil;
1413
import com.facebook.react.bridge.ReadableMap;
1514
import com.facebook.drawee.drawable.ScalingUtils.ScaleType;
1615
import com.facebook.drawee.drawable.ScalingUtils.InterpolatingScaleType;
1716
import com.facebook.react.views.image.ImageResizeMode;
17+
import com.facebook.react.modules.i18nmanager.I18nUtil;
1818

1919
public class RNSharedElementStyle {
2020
static int PROP_OPACITY = 1 << 0;
@@ -56,7 +56,7 @@ public class RNSharedElementStyle {
5656
// nop
5757
}
5858

59-
RNSharedElementStyle(ReadableMap config) {
59+
RNSharedElementStyle(ReadableMap config, Context context) {
6060
// Pre-fill the style with the style-config
6161
if (config.hasKey("opacity")) opacity = (float) config.getDouble("opacity");
6262
if (config.hasKey("backgroundColor")) backgroundColor = config.getInt("backgroundColor");
@@ -67,7 +67,7 @@ public class RNSharedElementStyle {
6767
if (config.hasKey("elevation")) elevation = PixelUtil.toPixelFromDIP((float) config.getDouble("elevation"));
6868

6969
// Border-radius
70-
boolean isRTL = TextUtilsCompat.getLayoutDirectionFromLocale(Locale.getDefault()) == ViewCompat.LAYOUT_DIRECTION_RTL;
70+
boolean isRTL = I18nUtil.getInstance().isRTL(context);
7171
if (config.hasKey("borderRadius")) {
7272
float borderRadius = PixelUtil.toPixelFromDIP((float) config.getDouble("borderRadius"));
7373
borderTopLeftRadius = borderRadius;

0 commit comments

Comments
 (0)