Skip to content

Commit

Permalink
feat(android): searchBar iconColor (#13622)
Browse files Browse the repository at this point in the history
  • Loading branch information
m1ga committed Nov 4, 2022
1 parent 12b2a71 commit 7fc1c5c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import android.app.Activity;
import android.content.Context;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.text.InputType;
import android.view.View;
Expand Down Expand Up @@ -157,13 +158,29 @@ public void processProperties(KrollDict properties)
if (properties.containsKey(TiC.PROPERTY_ICONIFIED_BY_DEFAULT)) {
searchView.setIconifiedByDefault(TiConvert.toBoolean(properties, TiC.PROPERTY_ICONIFIED_BY_DEFAULT, false));
}
if (properties.containsKey(TiC.PROPERTY_ICON_COLOR)) {
updateIconColor(searchView, TiConvert.toColor(properties, TiC.PROPERTY_ICON_COLOR, activity));
}
updateCloseButton();
updateInputType();

// Let base class handle all other properties.
super.processProperties(properties);
}

private void updateIconColor(SearchView searchView, int color)
{
ImageView imgSearch = searchView.findViewById(R.id.search_mag_icon);
ImageView imgClose = searchView.findViewById(R.id.search_close_btn);

if (imgSearch != null) {
imgSearch.setColorFilter(color, PorterDuff.Mode.SRC_IN);
}
if (imgClose != null) {
imgClose.setColorFilter(color, PorterDuff.Mode.SRC_IN);
}
}

@Override
public void propertyChanged(String key, Object oldValue, Object newValue, KrollProxy proxy)
{
Expand Down Expand Up @@ -206,6 +223,8 @@ public void propertyChanged(String key, Object oldValue, Object newValue, KrollP
searchView.setIconifiedByDefault(TiConvert.toBoolean(newValue, false));
} else if (key.equals(TiC.PROPERTY_AUTOCAPITALIZATION) || key.equals(TiC.PROPERTY_AUTOCORRECT)) {
updateInputType();
} else if (key.equals(TiC.PROPERTY_ICON_COLOR)) {
updateIconColor(searchView, TiConvert.toColor(newValue, proxy.getActivity()));
} else {
super.propertyChanged(key, oldValue, newValue, proxy);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,7 @@ public class TiC
public static final String PROPERTY_HTML = "html";
public static final String PROPERTY_HTTP_ONLY = "httponly";
public static final String PROPERTY_ICON = "icon";
public static final String PROPERTY_ICON_COLOR = "iconColor";
public static final String PROPERTY_ICON_LEVEL = "iconLevel";
public static final String PROPERTY_ICONIFIED = "iconified";
public static final String PROPERTY_ICONIFIED_BY_DEFAULT = "iconifiedByDefault";
Expand Down
6 changes: 6 additions & 0 deletions apidoc/Titanium/UI/SearchBar.yml
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,12 @@ properties:
type: Boolean
default: false

- name: iconColor
summary: Color of the search and close icon. Search icon will only work for `iconified:false`.
type: [String, Titanium.UI.Color]
platforms: [android]
since: "12.0.0"

- name: keyboardType
summary: Keyboard type constant to use when the field is focused.
type: Number
Expand Down

0 comments on commit 7fc1c5c

Please sign in to comment.