Skip to content

Commit

Permalink
fix(android): fixed support.v4 build error and RTL detection
Browse files Browse the repository at this point in the history
  • Loading branch information
IjzerenHein committed Sep 4, 2019
1 parent e983892 commit 9c374e9
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
Expand Up @@ -17,6 +17,7 @@ public class RNSharedElementModule extends ReactContextBaseJavaModule {
public RNSharedElementModule(ReactApplicationContext reactContext, RNSharedElementNodeManager nodeManager) {
super(reactContext);
mNodeManager = nodeManager;
mNodeManager.setContext(reactContext);
}

@Override
Expand Down
Expand Up @@ -12,6 +12,7 @@
import android.graphics.Matrix;
import android.graphics.drawable.Animatable;
import android.widget.ImageView;
import android.content.Context;

import com.facebook.react.bridge.Callback;
import com.facebook.react.bridge.ReadableMap;
Expand All @@ -34,6 +35,7 @@ class RNSharedElementNode {
private View mAncestorView;
private boolean mIsParent;
private ReadableMap mStyleConfig;
private Context mContext;
private View mResolvedView;
private int mRefCount;
private int mHideRefCount;
Expand All @@ -45,12 +47,13 @@ class RNSharedElementNode {
private BaseControllerListener<ImageInfo> mDraweeControllerListener;
private Handler mRetryHandler;

RNSharedElementNode(int reactTag, View view, boolean isParent, View ancestorView, ReadableMap styleConfig) {
RNSharedElementNode(int reactTag, View view, boolean isParent, View ancestorView, ReadableMap styleConfig, Context context) {
mReactTag = reactTag;
mView = view;
mAncestorView = ancestorView;
mIsParent = isParent;
mStyleConfig = styleConfig;
mContext = context;
mRefCount = 1;
mHideRefCount = 0;
mHideAlpha = 1;
Expand Down Expand Up @@ -191,7 +194,7 @@ private boolean fetchInitialStyle() {
Rect layout = new Rect(left, top, left + width, top + height);

// Create style
RNSharedElementStyle style = new RNSharedElementStyle(mStyleConfig);
RNSharedElementStyle style = new RNSharedElementStyle(mStyleConfig, mContext);
style.layout = layout;
style.frame = frame;
style.transform = transform;
Expand All @@ -207,6 +210,8 @@ private boolean fetchInitialStyle() {
// Update initial style cache
mStyleCache = style;

//Log.d(LOG_TAG, "Style fetched: " + style);

// Notify callbacks
ArrayList<Callback> callbacks = mStyleCallbacks;
mStyleCallbacks = null;
Expand Down
Expand Up @@ -4,13 +4,15 @@
import java.util.HashMap;

import android.view.View;
import android.content.Context;

import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.uimanager.NativeViewHierarchyManager;

class RNSharedElementNodeManager {
private Map<Integer, RNSharedElementNode> mNodes = new HashMap<Integer, RNSharedElementNode>();
private NativeViewHierarchyManager mNativeViewHierarchyManager;
private Context mContext;

void setNativeViewHierarchyManager(NativeViewHierarchyManager nativeViewHierarchyManager) {
mNativeViewHierarchyManager = nativeViewHierarchyManager;
Expand All @@ -20,14 +22,22 @@ NativeViewHierarchyManager getNativeViewHierarchyManager() {
return mNativeViewHierarchyManager;
}

void setContext(Context context) {
mContext = context;
}

Context getContext() {
return mContext;
}

RNSharedElementNode acquire(int reactTag, View view, boolean isParent, View ancestor, ReadableMap styleConfig) {
synchronized (mNodes) {
RNSharedElementNode node = mNodes.get(reactTag);
if (node != null) {
node.setRefCount(node.getRefCount() + 1);
return node;
}
node = new RNSharedElementNode(reactTag, view, isParent, ancestor, styleConfig);
node = new RNSharedElementNode(reactTag, view, isParent, ancestor, styleConfig, mContext);
mNodes.put(reactTag, node);
return node;
}
Expand Down
Expand Up @@ -5,16 +5,16 @@
import android.graphics.Rect;
import android.graphics.Color;
import android.graphics.Matrix;
import android.support.v4.text.TextUtilsCompat;
import android.support.v4.view.ViewCompat;
import android.view.View;
import android.view.ViewParent;
import android.content.Context;

import com.facebook.react.uimanager.PixelUtil;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.drawee.drawable.ScalingUtils.ScaleType;
import com.facebook.drawee.drawable.ScalingUtils.InterpolatingScaleType;
import com.facebook.react.views.image.ImageResizeMode;
import com.facebook.react.modules.i18nmanager.I18nUtil;

public class RNSharedElementStyle {
static int PROP_OPACITY = 1 << 0;
Expand Down Expand Up @@ -56,7 +56,7 @@ public class RNSharedElementStyle {
// nop
}

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

// Border-radius
boolean isRTL = TextUtilsCompat.getLayoutDirectionFromLocale(Locale.getDefault()) == ViewCompat.LAYOUT_DIRECTION_RTL;
boolean isRTL = I18nUtil.getInstance().isRTL(context);
if (config.hasKey("borderRadius")) {
float borderRadius = PixelUtil.toPixelFromDIP((float) config.getDouble("borderRadius"));
borderTopLeftRadius = borderRadius;
Expand Down

0 comments on commit 9c374e9

Please sign in to comment.