From 0acae329d69cd77b9e93349e08407681ce388e25 Mon Sep 17 00:00:00 2001 From: Jakub Grzywacz Date: Thu, 19 Sep 2024 17:05:51 +0200 Subject: [PATCH] add source set for BorderRadiiDrawableUtils on 0.75 --- .../android/build.gradle | 2 ++ .../reanimated/BorderRadiiDrawableUtils.java | 27 +++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 packages/react-native-reanimated/android/src/reactNativeVersionPatch/BorderRadiiDrawableUtils/75/com/swmansion/reanimated/BorderRadiiDrawableUtils.java diff --git a/packages/react-native-reanimated/android/build.gradle b/packages/react-native-reanimated/android/build.gradle index 8e5bfb3d9f1..3995ab1dacc 100644 --- a/packages/react-native-reanimated/android/build.gradle +++ b/packages/react-native-reanimated/android/build.gradle @@ -397,6 +397,8 @@ android { // BorderRadiiDrawableUtils if (REACT_NATIVE_MINOR_VERSION <= 74) { srcDirs += "src/reactNativeVersionPatch/BorderRadiiDrawableUtils/74" + } else if (REACT_NATIVE_MINOR_VERSION <= 75) { + srcDirs += "src/reactNativeVersionPatch/BorderRadiiDrawableUtils/75" } else { srcDirs += "src/reactNativeVersionPatch/BorderRadiiDrawableUtils/latest" } diff --git a/packages/react-native-reanimated/android/src/reactNativeVersionPatch/BorderRadiiDrawableUtils/75/com/swmansion/reanimated/BorderRadiiDrawableUtils.java b/packages/react-native-reanimated/android/src/reactNativeVersionPatch/BorderRadiiDrawableUtils/75/com/swmansion/reanimated/BorderRadiiDrawableUtils.java new file mode 100644 index 00000000000..2f4cd130809 --- /dev/null +++ b/packages/react-native-reanimated/android/src/reactNativeVersionPatch/BorderRadiiDrawableUtils/75/com/swmansion/reanimated/BorderRadiiDrawableUtils.java @@ -0,0 +1,27 @@ +package com.swmansion.reanimated; + +import android.graphics.drawable.Drawable; +import android.view.View; +import com.facebook.react.uimanager.LengthPercentage; +import com.facebook.react.uimanager.drawable.CSSBackgroundDrawable; +import com.facebook.react.uimanager.style.ComputedBorderRadius; + +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); + } + } +}