Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-25832] Android: Setting Ti.UI.SearchBar "hintText" property after creation causes a crash as of 7.0.0

GitHub Issuen/a
TypeBug
PriorityNone
StatusClosed
ResolutionFixed
Resolution Date2019-04-25T10:28:10.000+0000
Affected Version/sRelease 7.0.0
Fix Version/sRelease 8.0.1
ComponentsAndroid
LabelsSearchBar, android, hintText, regression
ReporterLokesh Choudhary
AssigneeJoshua Quick
Created2018-03-02T19:45:01.000+0000
Updated2019-04-25T10:28:10.000+0000

Description

*Summary:* Assigning a string to Ti.UI.SearchBar property "hintText" after it has been created will cause a crash on Android as of Titanium 7.0.0. *Steps to reproduce:*

Build and run the below code on Android.

Notice the app crashes on startup.

var window = Ti.UI.createWindow();
var searchBar = Ti.UI.createSearchBar({
	barColor: "white",
	top: 0,
	width: Ti.UI.FILL,
	height: "50dp",
});
window.add(searchBar);
window.add(Ti.UI.createLabel({ text: "SearchBar Test" }));
window.addEventListener("open", function(e) {
	searchBar.hintText = "Hint Text";
});
window.open();
*Recommended Fix:* When Titanium's "TiUIText.java" class reads property PROPERTY_HINT_TYPE via TiConvert.toInt(), the code needs to set the default value to UIModule.HINT_TYPE_STATIC in the following places in the code. [TiUIText.java#L350](https://github.com/appcelerator/titanium_mobile/blob/master/android/modules/ui/src/java/ti/modules/titanium/ui/widget/TiUIText.java#L350) [TiUIText.java#L924](https://github.com/appcelerator/titanium_mobile/blob/master/android/modules/ui/src/java/ti/modules/titanium/ui/widget/TiUIText.java#L924) *Work-Around 1:* Set the "hintText" property when creating the SearchBar, but never afterwards.
var searchBar = Ti.UI.createSearchBar({
	hintText: "Hint Text",
});
*Work-Around 2:* Set SearchBar property "hintType" to Ti.UI.HINT_TYPE_STATIC. This is an undocumented feature of SearchBar but it supports on Android since it internally uses Ti.UI.TextField within the SearchBar.
var window = Ti.UI.createWindow();
var searchBar = Ti.UI.createSearchBar({
	hintType: Ti.UI.HINT_TYPE_STATIC,  // <- This works-around the issue.
});
window.add(searchBar);
window.addEventListener("open", function() {
	searchBar.hintText = "Hint Text";
});
window.open();

Comments

  1. Joshua Quick 2019-04-13

    PR (master): https://github.com/appcelerator/titanium_mobile/pull/10848 PR (8.0.x): https://github.com/appcelerator/titanium_mobile/pull/10849
  2. Keerthi Mahalingam 2019-04-23

    FR Passed. PR merged.
  3. Samir Mohammed 2019-04-25

    Closing ticket, fix verified in SDK version 8.1.0.v20190423134840 and SDK version 8.0.1.v20190423123234. Test and other information can be found at: PR (master): https://github.com/appcelerator/titanium_mobile/pull/10848 PR (8.0.x): https://github.com/appcelerator/titanium_mobile/pull/10849

JSON Source