mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
RN picker - implement background color
Summary: add support to the android implementation of the Picker component for setting the background color. Changelog: [Android] [Added] - Support item background color in Dialog Picker Differential Revision: D20566131 fbshipit-source-id: d693b40803fa1051ec955c5728994c820fecd9e9
This commit is contained in:
committed by
Facebook GitHub Bot
parent
327fbd0509
commit
22eb711c84
+3
@@ -26,6 +26,9 @@ public class AndroidDialogPickerManagerDelegate<T extends View, U extends BaseVi
|
||||
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;
|
||||
|
||||
+1
@@ -15,6 +15,7 @@ import com.facebook.react.bridge.ReadableArray;
|
||||
|
||||
public interface AndroidDialogPickerManagerInterface<T extends View> {
|
||||
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);
|
||||
|
||||
+6
@@ -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 @@ public class ReactDialogPickerManager extends ReactPickerManager
|
||||
protected ViewManagerDelegate<ReactPicker> getDelegate() {
|
||||
return mDelegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBackgroundColor(@NonNull ReactPicker view, int backgroundColor) {
|
||||
view.setStagedBackgroundColor(backgroundColor);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ public class ReactPicker extends AppCompatSpinner {
|
||||
private @Nullable List<ReactPickerItem> mStagedItems;
|
||||
private @Nullable Integer mStagedSelection;
|
||||
private @Nullable Integer mStagedPrimaryTextColor;
|
||||
private @Nullable Integer mStagedBackgroundColor;
|
||||
|
||||
private final OnItemSelectedListener mItemSelectedListener =
|
||||
new OnItemSelectedListener() {
|
||||
@@ -136,6 +137,10 @@ public class ReactPicker extends AppCompatSpinner {
|
||||
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 class ReactPicker extends AppCompatSpinner {
|
||||
mStagedPrimaryTextColor = null;
|
||||
}
|
||||
|
||||
if (mStagedBackgroundColor != null
|
||||
&& adapter != null
|
||||
&& mStagedBackgroundColor != adapter.getBackgroundColor()) {
|
||||
adapter.setBackgroundColor(mStagedBackgroundColor);
|
||||
mStagedBackgroundColor = null;
|
||||
}
|
||||
|
||||
setOnItemSelectedListener(mItemSelectedListener);
|
||||
}
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ class ReactPickerAdapter extends ArrayAdapter<ReactPickerItem> {
|
||||
|
||||
private final LayoutInflater mInflater;
|
||||
private @Nullable Integer mPrimaryTextColor;
|
||||
private @Nullable Integer mBackgroundColor;
|
||||
|
||||
public ReactPickerAdapter(Context context, List<ReactPickerItem> data) {
|
||||
super(context, 0, data);
|
||||
@@ -67,6 +68,10 @@ class ReactPickerAdapter extends ArrayAdapter<ReactPickerItem> {
|
||||
textView.setTextColor((ColorStateList) textView.getTag());
|
||||
}
|
||||
|
||||
if (mBackgroundColor != null) {
|
||||
textView.setBackgroundColor(mBackgroundColor);
|
||||
}
|
||||
|
||||
return textView;
|
||||
}
|
||||
|
||||
@@ -74,8 +79,17 @@ class ReactPickerAdapter extends ArrayAdapter<ReactPickerItem> {
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user