Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix getViewProp on Android, RN.74 #6441

Merged
merged 12 commits into from
Sep 23, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,12 @@
import com.facebook.react.uimanager.UIManagerModule;
import com.facebook.react.uimanager.UIManagerReanimatedHelper;
import com.facebook.react.uimanager.common.UIManagerType;
import com.facebook.react.uimanager.drawable.CSSBackgroundDrawable;
import com.facebook.react.uimanager.events.Event;
import com.facebook.react.uimanager.events.EventDispatcherListener;
import com.facebook.react.uimanager.events.RCTEventEmitter;
import com.facebook.react.views.view.ReactViewBackgroundDrawable;
import com.swmansion.reanimated.layoutReanimation.AnimationsManager;
import com.swmansion.reanimated.nativeProxy.NoopEventHandler;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
Expand Down Expand Up @@ -458,26 +457,17 @@ public String obtainProp(int viewTag, String propName) {
}
case "backgroundColor" -> {
Drawable background = view.getBackground();
int actualColor = -1;
try {
Method getColor = background.getClass().getMethod("getColor");
int actualColor = (int) getColor.invoke(background);

// ReactViewBackgroundDrawable got deprecated in react-native 0.75.
//noinspection deprecation
if (background instanceof ReactViewBackgroundDrawable) {
//noinspection deprecation
actualColor = ((ReactViewBackgroundDrawable) background).getColor();
}
String invertedColor = String.format("%08x", (0xFFFFFFFF & actualColor));
// By default transparency is first, color second
return "#" + invertedColor.substring(2, 8) + invertedColor.substring(0, 2);

if (background instanceof CSSBackgroundDrawable) {
actualColor = ((CSSBackgroundDrawable) background).getColor();
}

if (actualColor == -1) {
} catch (Exception e) {
return "Unable to resolve background color";
}

String invertedColor = String.format("%08x", actualColor);
// By default transparency is first, color second
return "#" + invertedColor.substring(2, 8) + invertedColor.substring(0, 2);
}
default -> {
throw new IllegalArgumentException(
Expand Down
Loading