[TIMOB-25832] Android: Setting Ti.UI.SearchBar "hintText" property after creation causes a crash as of 7.0.0
| GitHub Issue | n/a |
|---|---|
| Type | Bug |
| Priority | None |
| Status | Closed |
| Resolution | Fixed |
| Resolution Date | 2019-04-25T10:28:10.000+0000 |
| Affected Version/s | Release 7.0.0 |
| Fix Version/s | Release 8.0.1 |
| Components | Android |
| Labels | SearchBar, android, hintText, regression |
| Reporter | Lokesh Choudhary |
| Assignee | Joshua Quick |
| Created | 2018-03-02T19:45:01.000+0000 |
| Updated | 2019-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();
PR (master): https://github.com/appcelerator/titanium_mobile/pull/10848 PR (8.0.x): https://github.com/appcelerator/titanium_mobile/pull/10849
FR Passed. PR merged.
Closing ticket, fix verified in SDK version
8.1.0.v20190423134840and SDK version8.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