-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement BorderRadiiDrawableUtils on 0.76
- Loading branch information
Showing
2 changed files
with
71 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 40 additions & 18 deletions
58
...ch/BorderRadiiDrawableUtils/latest/com/swmansion/reanimated/BorderRadiiDrawableUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,49 @@ | ||
package com.swmansion.reanimated; | ||
|
||
import android.graphics.drawable.Drawable; | ||
import android.graphics.Rect; | ||
import android.view.View; | ||
import com.facebook.react.uimanager.BackgroundStyleApplicator; | ||
import com.facebook.react.uimanager.LengthPercentage; | ||
import com.facebook.react.uimanager.drawable.CSSBackgroundDrawable; | ||
import com.facebook.react.uimanager.style.ComputedBorderRadius; | ||
import com.facebook.react.uimanager.style.BorderRadiusProp; | ||
|
||
public class BorderRadiiDrawableUtils { | ||
public static ReactNativeUtils.BorderRadii getBorderRadii(View view) { | ||
// Drawable background = view.getBackground(); | ||
// if (background instanceof CSSBackgroundDrawable) { | ||
// CSSBackgroundDrawable drawable = (CSSBackgroundDrawable) background; | ||
// LengthPercentage uniform = drawable.getBorderRadius().getUniform(); | ||
// float full = uniform != null ? uniform.resolve(view.getWidth(), view.getHeight()) : Float.NaN; | ||
// ComputedBorderRadius computedBorderRadius = drawable.getComputedBorderRadius(); | ||
// return new ReactNativeUtils.BorderRadii( | ||
// full, | ||
// computedBorderRadius.getTopLeft(), | ||
// computedBorderRadius.getTopRight(), | ||
// computedBorderRadius.getBottomLeft(), | ||
// computedBorderRadius.getBottomRight()); | ||
// } else { | ||
return new ReactNativeUtils.BorderRadii(0, 0, 0, 0, 0); | ||
// } | ||
Rect bounds = view.getBackground().getBounds(); | ||
LengthPercentage full = | ||
BackgroundStyleApplicator.getBorderRadius(view, BorderRadiusProp.BORDER_RADIUS); | ||
LengthPercentage topLeft = | ||
BackgroundStyleApplicator.getBorderRadius(view, BorderRadiusProp.BORDER_TOP_LEFT_RADIUS); | ||
LengthPercentage topRight = | ||
BackgroundStyleApplicator.getBorderRadius(view, BorderRadiusProp.BORDER_TOP_RIGHT_RADIUS); | ||
LengthPercentage bottomLeft = | ||
BackgroundStyleApplicator.getBorderRadius(view, BorderRadiusProp.BORDER_BOTTOM_LEFT_RADIUS); | ||
LengthPercentage bottomRight = | ||
BackgroundStyleApplicator.getBorderRadius( | ||
view, BorderRadiusProp.BORDER_BOTTOM_RIGHT_RADIUS); | ||
|
||
// This logic is valid only when `LengthPercentage.getType()` equals | ||
// `LengthPercentageType.POINT`. However, since the `SET` logic is only applicable on paper, | ||
// which only supports the `POINT` type, it's safe to assume that the type will always be | ||
// `POINT`. | ||
// https://github.com/facebook/react-native/blob/6d51c5cd8ef817fe30f01a10f2af682fc02a5fb7/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/view/ReactViewManager.java#L164 | ||
return new ReactNativeUtils.BorderRadii( | ||
full == null | ||
? 0 | ||
: full.resolve(bounds.width(), bounds.height()).toPixelFromDIP().getHorizontal(), | ||
topLeft == null | ||
? Float.NaN | ||
: topLeft.resolve(bounds.width(), bounds.height()).toPixelFromDIP().getHorizontal(), | ||
topRight == null | ||
? Float.NaN | ||
: topRight.resolve(bounds.width(), bounds.height()).toPixelFromDIP().getHorizontal(), | ||
bottomLeft == null | ||
? Float.NaN | ||
: bottomLeft.resolve(bounds.width(), bounds.height()).toPixelFromDIP().getHorizontal(), | ||
bottomRight == null | ||
? Float.NaN | ||
: bottomRight | ||
.resolve(bounds.width(), bounds.height()) | ||
.toPixelFromDIP() | ||
.getHorizontal()); | ||
} | ||
} |