Set color filter so that the arrow matches the text color

Summary: We support setting the text color in the ReactPicker component, but we don't apply the text color to the little arrow icon that appears next to it. This diff applies the color tint from the picker's primary text color (set with a style prop on the main picker component, *not* the 'color' prop on the Picker.Item) to the background of the picker, which tints the arrow icon.

Reviewed By: makovkastar

Differential Revision: D24480642

fbshipit-source-id: 7ce84d616ae677da8975be9444428392020c57dc
This commit is contained in:
Emily Janzer
2020-11-27 11:35:06 +00:00
committed by Lorenzo Sciandra
parent f0b6eb7d9f
commit 29972f9602
3 changed files with 21 additions and 9 deletions
@@ -1,12 +1,11 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated by codegen project: GeneratePropsJavaDelegate.js
*/
* Copyright (c) Facebook, Inc. and its affiliates.
*
* <p>This source code is licensed under the MIT license found in the LICENSE file in the root
* directory of this source tree.
*
* @generated by codegen project: GeneratePropsJavaDelegate.js
*/
package com.facebook.react.viewmanagers;
import android.view.View;
@@ -16,10 +15,14 @@ import com.facebook.react.uimanager.BaseViewManagerDelegate;
import com.facebook.react.uimanager.BaseViewManagerInterface;
import com.facebook.react.uimanager.LayoutShadowNode;
public class AndroidDropdownPickerManagerDelegate<T extends View, U extends BaseViewManagerInterface<T> & AndroidDropdownPickerManagerInterface<T>> extends BaseViewManagerDelegate<T, U> {
public class AndroidDropdownPickerManagerDelegate<
T extends View,
U extends BaseViewManagerInterface<T> & AndroidDropdownPickerManagerInterface<T>>
extends BaseViewManagerDelegate<T, U> {
public AndroidDropdownPickerManagerDelegate(U viewManager) {
super(viewManager);
}
@Override
public void setProperty(T view, String propName, @Nullable Object value) {
switch (propName) {
@@ -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 ReactDropdownPickerManager extends ReactPickerManager
protected ViewManagerDelegate<ReactPicker> getDelegate() {
return mDelegate;
}
@Override
public void setBackgroundColor(@NonNull ReactPicker view, int backgroundColor) {
view.setStagedBackgroundColor(backgroundColor);
}
}
@@ -8,12 +8,14 @@
package com.facebook.react.views.picker;
import android.content.Context;
import android.content.res.ColorStateList;
import android.util.AttributeSet;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Spinner;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.AppCompatSpinner;
import androidx.core.view.ViewCompat;
import com.facebook.react.common.annotations.VisibleForTesting;
import java.util.List;
@@ -173,6 +175,7 @@ public class ReactPicker extends AppCompatSpinner {
&& adapter != null
&& mStagedPrimaryTextColor != adapter.getPrimaryTextColor()) {
adapter.setPrimaryTextColor(mStagedPrimaryTextColor);
ViewCompat.setBackgroundTintList(this, ColorStateList.valueOf(mStagedPrimaryTextColor));
mStagedPrimaryTextColor = null;
}