Skip to content

Commit

Permalink
Fix some cases where we override setBackgroundColor on View-level ins…
Browse files Browse the repository at this point in the history
…tead of VM level (#46846)

Summary:
Pull Request resolved: #46846

As of D61658739, BaseViewManager setting color now goes through BackgroundStyleApplicator, which gives a default implementation of setting a background color, while storing information in a way where we can impement things like border radii and shadows on background for out of the box views.

I knew this could lead to breaks where we previously overrode view-level `setBackgroundColor` to do something custom, but didn't override on VM level, but didn't see any external usages so I assumed it should be relatively safe. Turns out we have some internal usages which run into this pattern (D63913128 already fixed one), including a usage in RN itself! Let's override the view managers in these to delegate to the view's custom drawing.

Changelog:
[Android][Fixed] - Fix some cases where we override setBackgroundColor on View-level instead of VM level

Reviewed By: Abbondanzo

Differential Revision: D63922722

fbshipit-source-id: af988d1436c790be97b2be1325541aa418bf43a3
  • Loading branch information
NickGerleman authored and facebook-github-bot committed Oct 5, 2024
1 parent 3f1e381 commit 0b0ac81
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/react-native/ReactAndroid/api/ReactAndroid.api
Original file line number Diff line number Diff line change
Expand Up @@ -7484,6 +7484,8 @@ public class com/facebook/react/views/switchview/ReactSwitchManager : com/facebo
public fun measure (Landroid/content/Context;Lcom/facebook/react/bridge/ReadableMap;Lcom/facebook/react/bridge/ReadableMap;Lcom/facebook/react/bridge/ReadableMap;FLcom/facebook/yoga/YogaMeasureMode;FLcom/facebook/yoga/YogaMeasureMode;[F)J
public synthetic fun receiveCommand (Landroid/view/View;Ljava/lang/String;Lcom/facebook/react/bridge/ReadableArray;)V
public fun receiveCommand (Lcom/facebook/react/views/switchview/ReactSwitch;Ljava/lang/String;Lcom/facebook/react/bridge/ReadableArray;)V
public synthetic fun setBackgroundColor (Landroid/view/View;I)V
public fun setBackgroundColor (Lcom/facebook/react/views/switchview/ReactSwitch;I)V
public synthetic fun setDisabled (Landroid/view/View;Z)V
public fun setDisabled (Lcom/facebook/react/views/switchview/ReactSwitch;Z)V
public synthetic fun setEnabled (Landroid/view/View;Z)V
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import android.content.Context;
import android.view.View;
import android.widget.CompoundButton;
import androidx.annotation.ColorInt;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.facebook.react.bridge.ReactContext;
Expand Down Expand Up @@ -117,6 +118,11 @@ protected ReactSwitch createViewInstance(ThemedReactContext context) {
return view;
}

@Override
public void setBackgroundColor(ReactSwitch view, @ColorInt int backgroundColor) {
view.setBackgroundColor(backgroundColor);
}

@Override
@ReactProp(name = "disabled", defaultBoolean = false)
public void setDisabled(ReactSwitch view, boolean disabled) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
package com.facebook.react.uiapp.component

import android.graphics.Color
import androidx.annotation.ColorInt
import com.facebook.react.bridge.ReadableArray
import com.facebook.react.module.annotations.ReactModule
import com.facebook.react.uimanager.SimpleViewManager
Expand Down Expand Up @@ -68,6 +69,10 @@ internal class MyNativeViewManager :
view.emitOnArrayChangedEvent(values)
}

override fun setBackgroundColor(view: MyNativeView, @ColorInt backgroundColor: Int) {
view.setBackgroundColor(backgroundColor)
}

override fun getExportedCustomBubblingEventTypeConstants(): Map<String, Any> =
mapOf(
"topIntArrayChanged" to
Expand Down

0 comments on commit 0b0ac81

Please sign in to comment.