diff --git a/Libraries/Components/Picker/AndroidDialogPickerNativeComponent.js b/Libraries/Components/Picker/AndroidDialogPickerNativeComponent.js index 1a39b9f5bd6d70..156b78afe824ba 100644 --- a/Libraries/Components/Picker/AndroidDialogPickerNativeComponent.js +++ b/Libraries/Components/Picker/AndroidDialogPickerNativeComponent.js @@ -41,6 +41,7 @@ type NativeProps = $ReadOnly<{| // Props color?: ?ColorValue, + backgroundColor?: ?ColorValue, enabled?: WithDefault, items: $ReadOnlyArray, prompt?: WithDefault, diff --git a/Libraries/Components/Picker/AndroidDropdownPickerNativeComponent.js b/Libraries/Components/Picker/AndroidDropdownPickerNativeComponent.js index ca155bc2e3e759..bf0b9e9ead63ec 100644 --- a/Libraries/Components/Picker/AndroidDropdownPickerNativeComponent.js +++ b/Libraries/Components/Picker/AndroidDropdownPickerNativeComponent.js @@ -41,6 +41,7 @@ type NativeProps = $ReadOnly<{| // Props color?: ?ColorValue, + backgroundColor?: ?ColorValue, enabled?: WithDefault, items: $ReadOnlyArray, prompt?: WithDefault, diff --git a/Libraries/Components/Picker/Picker.js b/Libraries/Components/Picker/Picker.js index 93f6f3830e8914..c02b18d20360df 100644 --- a/Libraries/Components/Picker/Picker.js +++ b/Libraries/Components/Picker/Picker.js @@ -96,6 +96,12 @@ type PickerProps = $ReadOnly<{| */ itemStyle?: ?TextStyleProp, + /** + * Color of the item background. + * @platform android + */ + backgroundColor?: ColorValue, + /** * Prompt string for this picker, used on Android in dialog mode as the title of the dialog. * @platform android diff --git a/Libraries/Components/Picker/PickerAndroid.android.js b/Libraries/Components/Picker/PickerAndroid.android.js index 5bd2b31b41f9dc..a47d29bd5ec6a7 100644 --- a/Libraries/Components/Picker/PickerAndroid.android.js +++ b/Libraries/Components/Picker/PickerAndroid.android.js @@ -21,6 +21,7 @@ import StyleSheet from '../../StyleSheet/StyleSheet'; import invariant from 'invariant'; import processColor from '../../StyleSheet/processColor'; +import type {ColorValue} from '../../StyleSheet/StyleSheetTypes'; import type {SyntheticEvent} from '../../Types/CoreEventTypes'; import type {TextStyleProp} from '../../StyleSheet/StyleSheet'; @@ -36,6 +37,7 @@ type Props = $ReadOnly<{| accessibilityLabel?: ?Stringish, children?: React.Node, style?: ?TextStyleProp, + backgroundColor?: ?ColorValue, selectedValue?: ?PickerItemValue, enabled?: ?boolean, mode?: ?('dialog' | 'dropdown'), @@ -123,6 +125,7 @@ function PickerAndroid(props: Props): React.Node { styles.pickerAndroid, props.style, ), + backgroundColor: props.backgroundColor, testID: props.testID, }; return props.mode === 'dropdown' ? ( diff --git a/ReactAndroid/src/main/java/com/facebook/react/viewmanagers/AndroidDialogPickerManagerDelegate.java b/ReactAndroid/src/main/java/com/facebook/react/viewmanagers/AndroidDialogPickerManagerDelegate.java index 5e882217807974..8147f55a3d5110 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/viewmanagers/AndroidDialogPickerManagerDelegate.java +++ b/ReactAndroid/src/main/java/com/facebook/react/viewmanagers/AndroidDialogPickerManagerDelegate.java @@ -26,6 +26,9 @@ public void setProperty(T view, String propName, @Nullable Object value) { case "color": mViewManager.setColor(view, value == null ? null : ((Double) value).intValue()); break; + case "backgroundColor": + mViewManager.setBackgroundColor(view, value == null ? null : ((Double) value).intValue()); + break; case "enabled": mViewManager.setEnabled(view, value == null ? true : (boolean) value); break; diff --git a/ReactAndroid/src/main/java/com/facebook/react/viewmanagers/AndroidDialogPickerManagerInterface.java b/ReactAndroid/src/main/java/com/facebook/react/viewmanagers/AndroidDialogPickerManagerInterface.java index 2a9a7cdb5faebd..796da9e5aeb5c4 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/viewmanagers/AndroidDialogPickerManagerInterface.java +++ b/ReactAndroid/src/main/java/com/facebook/react/viewmanagers/AndroidDialogPickerManagerInterface.java @@ -15,6 +15,7 @@ public interface AndroidDialogPickerManagerInterface { void setColor(T view, @Nullable Integer value); + void setBackgroundColor(T view, @Nullable int value); void setEnabled(T view, boolean value); void setItems(T view, @Nullable ReadableArray value); void setPrompt(T view, @Nullable String value); diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/picker/ReactDialogPickerManager.java b/ReactAndroid/src/main/java/com/facebook/react/views/picker/ReactDialogPickerManager.java index cf3fde687f5975..8ff961446368b4 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/picker/ReactDialogPickerManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/picker/ReactDialogPickerManager.java @@ -8,6 +8,7 @@ package com.facebook.react.views.picker; import android.widget.Spinner; +import androidx.annotation.NonNull; import com.facebook.react.module.annotations.ReactModule; import com.facebook.react.uimanager.ThemedReactContext; import com.facebook.react.uimanager.ViewManagerDelegate; @@ -41,4 +42,9 @@ protected ReactPicker createViewInstance(ThemedReactContext reactContext) { protected ViewManagerDelegate getDelegate() { return mDelegate; } + + @Override + public void setBackgroundColor(@NonNull ReactPicker view, int backgroundColor) { + view.setStagedBackgroundColor(backgroundColor); + } } diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/picker/ReactPicker.java b/ReactAndroid/src/main/java/com/facebook/react/views/picker/ReactPicker.java index fd6edeb7e2b91d..c629f26a461642 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/picker/ReactPicker.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/picker/ReactPicker.java @@ -25,6 +25,7 @@ public class ReactPicker extends AppCompatSpinner { private @Nullable List mStagedItems; private @Nullable Integer mStagedSelection; private @Nullable Integer mStagedPrimaryTextColor; + private @Nullable Integer mStagedBackgroundColor; private final OnItemSelectedListener mItemSelectedListener = new OnItemSelectedListener() { @@ -136,6 +137,10 @@ public OnSelectListener getOnSelectListener() { mStagedPrimaryTextColor = primaryColor; } + /* package */ void setStagedBackgroundColor(@Nullable Integer backgroundColor) { + mStagedBackgroundColor = backgroundColor; + } + /** * Used to commit staged data into ReactPicker view. During this period, we will disable {@link * OnSelectListener#onItemSelected(int)} temporarily, so we don't get an event when changing the @@ -171,6 +176,13 @@ public OnSelectListener getOnSelectListener() { mStagedPrimaryTextColor = null; } + if (mStagedBackgroundColor != null + && adapter != null + && mStagedBackgroundColor != adapter.getBackgroundColor()) { + adapter.setBackgroundColor(mStagedBackgroundColor); + mStagedBackgroundColor = null; + } + setOnItemSelectedListener(mItemSelectedListener); } diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/picker/ReactPickerAdapter.java b/ReactAndroid/src/main/java/com/facebook/react/views/picker/ReactPickerAdapter.java index f1c2a22c13747d..4f2890e79158c2 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/picker/ReactPickerAdapter.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/picker/ReactPickerAdapter.java @@ -23,6 +23,7 @@ class ReactPickerAdapter extends ArrayAdapter { private final LayoutInflater mInflater; private @Nullable Integer mPrimaryTextColor; + private @Nullable Integer mBackgroundColor; public ReactPickerAdapter(Context context, List data) { super(context, 0, data); @@ -67,6 +68,10 @@ private View getView(int position, View convertView, ViewGroup parent, boolean i textView.setTextColor((ColorStateList) textView.getTag()); } + if (mBackgroundColor != null) { + textView.setBackgroundColor(mBackgroundColor); + } + return textView; } @@ -74,8 +79,17 @@ private View getView(int position, View convertView, ViewGroup parent, boolean i return mPrimaryTextColor; } + public @Nullable Integer getBackgroundColor() { + return mBackgroundColor; + } + public void setPrimaryTextColor(@Nullable Integer primaryTextColor) { mPrimaryTextColor = primaryTextColor; notifyDataSetChanged(); } + + public void setBackgroundColor(@Nullable Integer backgroundColor) { + mBackgroundColor = backgroundColor; + notifyDataSetChanged(); + } }