Skip to content

Commit

Permalink
[react-native-shared-element] Upgrade react-native-shared-element to …
Browse files Browse the repository at this point in the history
…0.7.0 (#8427)

Fixes various native issue on iOS and Android and introduces separate border-radii transitions on iOS.
  • Loading branch information
IjzerenHein committed May 22, 2020
1 parent 5c1a1b2 commit 1576036
Show file tree
Hide file tree
Showing 27 changed files with 2,680 additions and 2,390 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -8,6 +8,7 @@ Package-specific changes not released in any SDK will be added here just before
### 📚 3rd party library updates

- Updated `react-native-reanimated` from `1.7.0` to `1.9.0`. ([#8424](https://github.com/expo/expo/pull/8424) by [@sjchmiela](https://github.com/sjchmiela))
- Updated `react-native-shared-element` from `0.5.6` to `0.7.0`. ([#8427](https://github.com/expo/expo/pull/8427) by [@IjzerenHein](https://github.com/IjzerenHein))

### 🛠 Breaking changes

Expand Down
Expand Up @@ -10,36 +10,35 @@
import com.facebook.drawee.interfaces.DraweeController;

class RNSharedElementContent {
View view;
RectF size;
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 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) {
Expand Down
Expand Up @@ -31,8 +31,14 @@ enum ViewType {
GENERIC("generic");

private final String value;
ViewType(final String newValue) { value = newValue;}
public String getValue() { return value; }

ViewType(final String newValue) {
value = newValue;
}

public String getValue() {
return value;
}
}

static private String LOG_TAG = "RNSharedElementDrawable";
Expand All @@ -58,10 +64,10 @@ float getPosition() {
}

ViewType update(
RNSharedElementContent content,
RNSharedElementStyle style,
float position
) {
RNSharedElementContent content,
RNSharedElementStyle style,
float position
) {
boolean invalidated = false;

// Update content
Expand All @@ -83,9 +89,9 @@ ViewType update(
case REACTIMAGEVIEW:
case IMAGEVIEW:
if ((mStyle.compare(style) &
(RNSharedElementStyle.PROP_BORDER
| RNSharedElementStyle.PROP_BACKGROUND_COLOR
| RNSharedElementStyle.PROP_SCALETYPE)) != 0) {
(RNSharedElementStyle.PROP_BORDER
| RNSharedElementStyle.PROP_BACKGROUND_COLOR
| RNSharedElementStyle.PROP_SCALETYPE)) != 0) {
//Log.d(LOG_TAG, "drawableChanged, viewType: " + viewType + ", changes: " + mStyle.compare(style));
invalidated = true;
} else {
Expand All @@ -94,8 +100,8 @@ ViewType update(
break;
case PLAIN:
if ((mStyle.compare(style) &
(RNSharedElementStyle.PROP_BORDER
| RNSharedElementStyle.PROP_BACKGROUND_COLOR)) != 0) {
(RNSharedElementStyle.PROP_BORDER
| RNSharedElementStyle.PROP_BACKGROUND_COLOR)) != 0) {
//Log.d(LOG_TAG, "drawableChanged, viewType: " + viewType + ", changes: " + mStyle.compare(style));
invalidated = true;
} else {
Expand Down Expand Up @@ -156,9 +162,9 @@ public void getOutline(Outline outline) {
return;
}
if ((mStyle.borderTopLeftRadius == 0) &&
(mStyle.borderTopRightRadius == 0) &&
(mStyle.borderBottomLeftRadius == 0) &&
(mStyle.borderBottomRightRadius == 0)) {
(mStyle.borderTopRightRadius == 0) &&
(mStyle.borderBottomLeftRadius == 0) &&
(mStyle.borderBottomRightRadius == 0)) {
outline.setRect(getBounds());
return;
}
Expand All @@ -170,18 +176,18 @@ public void getOutline(Outline outline) {
}
float extraRadiusForOutline = mStyle.borderWidth / 2f;
mPathForBorderRadiusOutline.addRoundRect(
new RectF(getBounds()),
new float[]{
mStyle.borderTopLeftRadius + extraRadiusForOutline,
mStyle.borderTopLeftRadius + extraRadiusForOutline,
mStyle.borderTopRightRadius + extraRadiusForOutline,
mStyle.borderTopRightRadius + extraRadiusForOutline,
mStyle.borderBottomRightRadius + extraRadiusForOutline,
mStyle.borderBottomRightRadius + extraRadiusForOutline,
mStyle.borderBottomLeftRadius + extraRadiusForOutline,
mStyle.borderBottomLeftRadius + extraRadiusForOutline
},
Path.Direction.CW
new RectF(getBounds()),
new float[]{
mStyle.borderTopLeftRadius + extraRadiusForOutline,
mStyle.borderTopLeftRadius + extraRadiusForOutline,
mStyle.borderTopRightRadius + extraRadiusForOutline,
mStyle.borderTopRightRadius + extraRadiusForOutline,
mStyle.borderBottomRightRadius + extraRadiusForOutline,
mStyle.borderBottomRightRadius + extraRadiusForOutline,
mStyle.borderBottomLeftRadius + extraRadiusForOutline,
mStyle.borderBottomLeftRadius + extraRadiusForOutline
},
Path.Direction.CW
);
outline.setConvexPath(mPathForBorderRadiusOutline);
}
Expand Down Expand Up @@ -249,10 +255,10 @@ private void drawReactImageView(Canvas canvas) {
roundingParams.setBorderWidth(style.borderWidth);
roundingParams.setRoundingMethod(RoundingParams.RoundingMethod.BITMAP_ONLY);
roundingParams.setCornersRadii(
style.borderTopLeftRadius,
style.borderTopRightRadius,
style.borderBottomRightRadius,
style.borderBottomLeftRadius
style.borderTopLeftRadius,
style.borderTopRightRadius,
style.borderBottomRightRadius,
style.borderBottomLeftRadius
);
hierarchy.setRoundingParams(roundingParams);
hierarchy.setBackgroundImage(null);
Expand Down
Expand Up @@ -12,38 +12,38 @@

@ReactModule(name = RNSharedElementModule.MODULE_NAME)
public class RNSharedElementModule extends ReactContextBaseJavaModule {
public static final String MODULE_NAME = "RNSharedElementTransition";
static String LOG_TAG = "RNSharedElementModule";

private RNSharedElementNodeManager mNodeManager;

public RNSharedElementModule(ReactApplicationContext reactContext) {
super(reactContext);
mNodeManager = new RNSharedElementNodeManager(reactContext);
}

@Override
public String getName() {
return MODULE_NAME;
}

RNSharedElementNodeManager getNodeManager() {
return mNodeManager;
}

@ReactMethod
public void configure(final ReadableMap config, final Promise promise) {

// Store a reference to the native view manager in the node-manager.
// This is done so that we can efficiently resolve a view when the
// start- and end props are set on the Transition view.
final ReactApplicationContext context = getReactApplicationContext();
final UIManagerModule uiManager = context.getNativeModule(UIManagerModule.class);
uiManager.prependUIBlock(new UIBlock() {
@Override
public void execute(NativeViewHierarchyManager nativeViewHierarchyManager) {
mNodeManager.setNativeViewHierarchyManager(nativeViewHierarchyManager);
}
});
}
public static final String MODULE_NAME = "RNSharedElementTransition";
static String LOG_TAG = "RNSharedElementModule";

private RNSharedElementNodeManager mNodeManager;

public RNSharedElementModule(ReactApplicationContext reactContext) {
super(reactContext);
mNodeManager = new RNSharedElementNodeManager(reactContext);
}

@Override
public String getName() {
return MODULE_NAME;
}

RNSharedElementNodeManager getNodeManager() {
return mNodeManager;
}

@ReactMethod
public void configure(final ReadableMap config, final Promise promise) {

// Store a reference to the native view manager in the node-manager.
// This is done so that we can efficiently resolve a view when the
// start- and end props are set on the Transition view.
final ReactApplicationContext context = getReactApplicationContext();
final UIManagerModule uiManager = context.getNativeModule(UIManagerModule.class);
uiManager.prependUIBlock(new UIBlock() {
@Override
public void execute(NativeViewHierarchyManager nativeViewHierarchyManager) {
mNodeManager.setNativeViewHierarchyManager(nativeViewHierarchyManager);
}
});
}
}

0 comments on commit 1576036

Please sign in to comment.