Skip to content

Commit

Permalink
feat(android): update Ti.UI.SearchBar to use native SearchView (#12624)
Browse files Browse the repository at this point in the history
Fixes TIMOB-28390
  • Loading branch information
build committed Mar 23, 2021
1 parent cee557b commit 9637ac1
Show file tree
Hide file tree
Showing 5 changed files with 379 additions and 190 deletions.
Original file line number Diff line number Diff line change
@@ -1,53 +1,53 @@
/**
* Appcelerator Titanium Mobile
* Copyright (c) 2009-2016 by Appcelerator, Inc. All Rights Reserved.
* Copyright (c) 2009-2021 by Axway, Inc. All Rights Reserved.
* Licensed under the terms of the Apache Public License
* Please see the LICENSE included with this distribution for details.
*/
package ti.modules.titanium.ui;

import org.appcelerator.kroll.KrollDict;
import org.appcelerator.kroll.KrollModule;
import org.appcelerator.kroll.annotations.Kroll;
import org.appcelerator.titanium.TiC;
import org.appcelerator.titanium.proxy.TiViewProxy;
import org.appcelerator.titanium.util.TiConvert;
import org.appcelerator.titanium.view.TiUIView;

import ti.modules.titanium.ui.widget.searchbar.TiUISearchBar;
import android.app.Activity;

@Kroll.proxy(creatableInModule = UIModule.class,
propertyAccessors = {
"prompt",
"promptid",
"hintText",
"hinttextid",
"showCancel",
"barColor",
TiC.PROPERTY_AUTOCAPITALIZATION,
TiC.PROPERTY_AUTOCORRECT,
TiC.PROPERTY_BAR_COLOR,
TiC.PROPERTY_COLOR,
TiC.PROPERTY_HINT_TEXT,
TiC.PROPERTY_HINT_TEXT_COLOR,
TiC.PROPERTY_HINT_TEXT_ID,
TiC.PROPERTY_ICONIFIED,
TiC.PROPERTY_ICONIFIED_BY_DEFAULT,
TiC.PROPERTY_PROMPT,
TiC.PROPERTY_PROMPT_ID,
TiC.PROPERTY_VALUE
})
public class SearchBarProxy extends TiViewProxy
{
public SearchBarProxy()
{
super();
}

@Override
public void handleCreationArgs(KrollModule createdInModule, Object[] args)
{
super.handleCreationArgs(createdInModule, args);
setProperty(TiC.PROPERTY_VALUE, "");
this.defaultValues.put(TiC.PROPERTY_AUTOCAPITALIZATION, UIModule.TEXT_AUTOCAPITALIZATION_NONE);
this.defaultValues.put(TiC.PROPERTY_AUTOCORRECT, false);
this.defaultValues.put(TiC.PROPERTY_ICONIFIED_BY_DEFAULT, false);
this.defaultValues.put(TiC.PROPERTY_SHOW_CANCEL, false);
this.defaultValues.put(TiC.PROPERTY_VALUE, "");
}

@Override
protected KrollDict getLangConversionTable()
{
KrollDict table = new KrollDict();
table.put("prompt", "promptid");
table.put("hintText", "hinttextid");
table.put(TiC.PROPERTY_PROMPT, TiC.PROPERTY_PROMPT_ID);
table.put(TiC.PROPERTY_HINT_TEXT, TiC.PROPERTY_HINT_TEXT_ID);
return table;
}

Expand All @@ -57,12 +57,6 @@ public TiUIView createView(Activity activity)
return new TiUISearchBar(this);
}

@Override
public String getApiName()
{
return "Ti.UI.SearchBar";
}

@Kroll.getProperty(name = "focused")
public boolean isFocused()
{
Expand All @@ -72,4 +66,28 @@ public boolean isFocused()
}
return false;
}

@Kroll.getProperty
public boolean getShowCancel()
{
return TiConvert.toBoolean(getProperty(TiC.PROPERTY_SHOW_CANCEL), false);
}

@Kroll.setProperty
public void setShowCancel(boolean isShown)
{
setShowCancel(isShown, null);
}

@Kroll.method
public void setShowCancel(boolean isShown, @Kroll.argument(optional = true) KrollDict options)
{
setPropertyAndFire(TiC.PROPERTY_SHOW_CANCEL, isShown);
}

@Override
public String getApiName()
{
return "Ti.UI.SearchBar";
}
}

0 comments on commit 9637ac1

Please sign in to comment.