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(android): drop-down picker text color for dark/light theme change #12734

Merged
merged 3 commits into from
Apr 22, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ public class TiUINativePicker extends TiUIPicker
{
private static final String TAG = "TiUINativePicker";
private boolean nativeViewDrawn = false;
private static int defaultTextColor;
private static boolean setDefaultTextColor = false;

public static class TiSpinnerAdapter<T> extends ArrayAdapter<T>
{
String[] fontProperties;
private int defaultTextColor;
private boolean hasLoadedDefaultTextColor;

public TiSpinnerAdapter(Context context, int textViewResourceId, List<T> objects)
{
Expand Down Expand Up @@ -74,21 +74,25 @@ public void setFontProperties(KrollDict d)

private void styleTextView(int position, TextView tv)
{
TiViewProxy rowProxy = (TiViewProxy) this.getItem(position);
// Fetch text view's default text color if not done already.
if (!this.hasLoadedDefaultTextColor) {
this.defaultTextColor = tv.getCurrentTextColor();
this.hasLoadedDefaultTextColor = true;
}

// Update text view's font if configured.
if (fontProperties != null) {
TiUIHelper.styleText(
tv, fontProperties[TiUIHelper.FONT_FAMILY_POSITION], fontProperties[TiUIHelper.FONT_SIZE_POSITION],
fontProperties[TiUIHelper.FONT_WEIGHT_POSITION], fontProperties[TiUIHelper.FONT_STYLE_POSITION]);
}
if (!setDefaultTextColor) {
defaultTextColor = tv.getCurrentTextColor();
setDefaultTextColor = true;
}

// Update text color if configured.
TiViewProxy rowProxy = (TiViewProxy) this.getItem(position);
if (rowProxy.hasProperty(TiC.PROPERTY_COLOR)) {
final int color = TiConvert.toColor((String) rowProxy.getProperty(TiC.PROPERTY_COLOR));
String colorString = TiConvert.toString(rowProxy.getProperty(TiC.PROPERTY_COLOR));
int color = (colorString != null) ? TiConvert.toColor(colorString) : this.defaultTextColor;
tv.setTextColor(color);
} else {
tv.setTextColor(defaultTextColor);
}
}
}
Expand Down