[TIMOB-3223] iOS - showBookmark missing from searchBar
| GitHub Issue | n/a |
|---|---|
| Type | New Feature |
| Priority | Medium |
| Status | Closed |
| Resolution | Fixed |
| Resolution Date | 2012-04-18T10:56:41.000+0000 |
| Affected Version/s | n/a |
| Fix Version/s | Release 2.1.0 |
| Components | iOS |
| Labels | core, qe-testadded |
| Reporter | Pedro Enrique |
| Assignee | Neeraj Gupta |
| Created | 2011-04-15T03:39:50.000+0000 |
| Updated | 2013-11-06T19:24:12.000+0000 |
Description
According to Apple's [Documentation](http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UISearchBar_Class/Reference/Reference.html%23//apple_ref/doc/uid/TP40007529) there is a property for the searchbar that adds a Bookmark icon to the right side of it.
I modified a little bit the Obj-C code. Specifically, I added the following code to TiUISearchBar.m and now it is working as expected:
-(void)setShowBookmark_:(id)value
{
UISearchBar *search = [self searchBar];
[search setShowsBookmarkButton:[TiUtils boolValue:value]];
[search sizeToFit];
}
To make this work on Titanium's code just added it to the searchbar with showBookmark true:
var search = Ti.UI.createSearchBar({
hintText: "Type Something",
top:0,
height:44,
showBookmark: true
});
Then for it's listener, I modified the Obj-C code a little more:
// called when bookmark button pressed
- (void)searchBarBookmarkButtonClicked:(UISearchBar *)searchBar
{
//TODO: update to the new event model
NSString * text = [searchBar text];
[self.proxy replaceValue:text forKey:@"value" notification:NO];
if ([self.proxy _hasListeners:@"bookmark"])
{
[self.proxy fireEvent:@"bookmark" withObject:[NSDictionary dictionaryWithObject:text forKey:@"value"]];
}
if (delegate!=nil && [delegate respondsToSelector:@selector(searchBarBookmarkButtonClicked:)])
{
[delegate searchBarBookmarkButtonClicked:searchBar];
}
}
And the JS is like this:
search.addEventListener('bookmark', function(e){
alert(e);
});
Tested in Ti SDK 1.6 Release
iPhone Simulator 4.2
This feature is necessary for our project, if it can be prioritized.
As a low priority item, this will not be looked at until after Sprint 16.
I've pulled request on github for Pedro Enrique's solution with adding documentation. See here: https://github.com/appcelerator/titanium_mobile/pull/1458 Ticket is already tagged for 1.8.0 release but I hope it'll be included in next release.
Tested with: Titanium SDK: 2.0.0 (04/06/12 00:35 8e4d621) iPhone SDK: 5.0 iPhone Simulator Screenshots: [http://oi41.tinypic.com/34skkcy.jpg] [http://oi42.tinypic.com/xeg3ee.jpg] [http://oi41.tinypic.com/2ibnf9s.jpg] [http://oi42.tinypic.com/30nayxs.jpg] Here are the functional test application source code:
var window = Titanium.UI.createWindow({ backgroundColor: "white" }); var searchBar = Titanium.UI.createSearchBar({ top: 0, height: 44 }); searchBar.addEventListener('bookmark', function(e) { alert('Bookmark button clicked. Value: ' + e.value); }); var buttonFocus = Titanium.UI.createButton({ title: 'Focus', top: 75, left: 20, height: 30 }); buttonFocus.addEventListener('click', function(e) { searchBar.focus(); }); var buttonBlur = Titanium.UI.createButton({ title: 'Blur', top: 75, right: 20, height: 30 }); buttonBlur.addEventListener('click', function(e) { searchBar.blur(); }); var buttonBookmark = Titanium.UI.createButton({ title: 'Toggle Bookmark', top: 125, height: 30 }); buttonBookmark.addEventListener('click', function(e) { searchBar.showBookmark = !searchBar.showBookmark; }); window.add(searchBar); window.add(buttonFocus); window.add(buttonBlur); window.add(buttonBookmark); window.open();Here is an additional test which should be run:
Searchbar w/bookmark in tableview
var window = Titanium.UI.createWindow({ backgroundColor: "white" }); var searchBar = Titanium.UI.createSearchBar({ showBookmark: true }); searchBar.addEventListener('bookmark', function(e) { alert('Bookmark button clicked. Value: ' + e.value); }); var table = Ti.UI.createTableView({ data:[{title:"Row 1"}, {title:"Row 2"}, {title:"Row 3"}], search:searchBar }); window.add(table); window.open();Tested with 2.1.0.v20120606112649 iPad 3 5.1.1 and iPhone 3gs 4.3
Anvil testcase PR https://github.com/appcelerator/titanium_mobile/pull/4758