Skip to content

Commit

Permalink
[TIMOB-25866] : iOS TiUISearchBar getter is returning value from prox…
Browse files Browse the repository at this point in the history
…y not from searchbar view (#9947)

* [TIMOB-225850] : iOS SearchBar doesn't show Bookmark button when set on creation in TableView

* [TIMOB-25850] : iOS SearchBar doesn't show Bookmark button when set on creation in TableView

* [TIMOB-25850] : Color properties  set for search bar with other properties

* [TIMOB-25866] : iOS TiUISearchBar getter is returning value from proxy not from searchbar view

* [TIMOB-25866] : Unit test added for properties of search bar

* [TIMOB-25866] : Fix linting issue
  • Loading branch information
vijaysingh-axway authored and hansemannn committed Jun 21, 2018
1 parent ec56053 commit d03b8f6
Show file tree
Hide file tree
Showing 2 changed files with 195 additions and 14 deletions.
102 changes: 88 additions & 14 deletions iphone/Classes/TiUISearchBarProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -73,22 +73,17 @@ - (UISearchBar *)searchBar

- (void)setSearchBar:(UISearchBar *)searchBar
{
// We need to manually handle this property as it will be overwritten
// by the search controller otherwise (TIMOB-10368)
if ([self valueForKey:@"color"] != nil) {
UIView *searchContainerView = [[searchBar subviews] firstObject];
UIColor *color = [TiUtils colorValue:[self valueForKey:@"color"]].color;

[[searchContainerView subviews] enumerateObjectsUsingBlock:^(__kindof UIView *_Nonnull obj, NSUInteger idx, BOOL *_Nonnull stop) {
if ([obj isKindOfClass:[UITextField class]]) {
[(UITextField *)obj setTextColor:color];
*stop = YES;
}
}];
}

// In UISearchController searchbar is readonly. We have to replace that search bar with existing search bar of proxy.
[(TiUISearchBar *)[self view] setSearchBar:searchBar];

// Set search bar properties to new search bar
NSDictionary *properties = [self allProperties];
for (NSString *key in properties.allKeys) {
SEL selector = SetterForKrollProperty(key);
if ([(TiUISearchBar *)[self view] respondsToSelector:selector]) {
[(TiUISearchBar *)[self view] performSelector:selector withObject:[properties objectForKey:key]];
}
}
}

- (void)ensureSearchBarHierarchy
Expand All @@ -113,6 +108,85 @@ - (TiDimension)defaultAutoHeightBehavior:(id)unused
return TiDimensionAutoSize;
}

#pragma mark getters

- (NSString *)value
{
return [[self searchBar] text];
}

- (NSNumber *)showBookmark
{
return NUMBOOL([[self searchBar] showsBookmarkButton]);
}

- (NSNumber *)showCancel
{
return NUMBOOL([[self searchBar] showsCancelButton]);
}

- (NSString *)hintText
{
return [[self searchBar] placeholder];
}

- (id)hintTextColor
{
return [self valueForUndefinedKey:@"hintTextColor"];
}

- (id)color
{
return [self valueForUndefinedKey:@"color"];
}

- (NSNumber *)keyboardType
{
return NUMINT([[self searchBar] keyboardType]);
}

- (NSNumber *)keyboardAppearance
{
return NUMINT([[self searchBar] keyboardAppearance]);
}

- (NSString *)prompt
{
return [[self searchBar] prompt];
}

- (NSNumber *)autocorrect
{
UITextAutocorrectionType autocorrectionType = [[self searchBar] autocorrectionType];
if (autocorrectionType == UITextAutocorrectionTypeYes) {
return NUMBOOL(YES);
} else if (autocorrectionType == UITextAutocorrectionTypeNo) {
return NUMBOOL(NO);
} else {
return nil;
}
}

- (NSNumber *)autocapitalization
{
return NUMINT([[self searchBar] autocapitalizationType]);
}

- (id)tintColor
{
return [self valueForUndefinedKey:@"tintColor"];
}

- (id)barColor
{
return [self valueForUndefinedKey:@"barColor"];
}

- (NSNumber *)style
{
return NUMINT([[self searchBar] searchBarStyle]);
}

USE_VIEW_FOR_CONTENT_HEIGHT
@end

Expand Down
107 changes: 107 additions & 0 deletions tests/Resources/ti.ui.searchbar.addontest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/*
* Appcelerator Titanium Mobile
* Copyright (c) 2011-Present by Appcelerator, Inc. All Rights Reserved.
* Licensed under the terms of the Apache Public License
* Please see the LICENSE included with this distribution for details.
*/
/* eslint-env mocha */
/* global Ti */
/* eslint no-unused-expressions: "off" */
'use strict';
var should = require('./utilities/assertions');

describe('Titanium.UI.SearchBar', function () {
var win;

afterEach(function () {
if (win) {
win.close();
}
win = null;
});

it.ios('.showBookmark', function () {
var searchBar = Ti.UI.createSearchBar({
showBookmark: true
});
should(searchBar.getShowBookmark).be.a.Function;
should(searchBar.showBookmark).be.true;
should(searchBar.getShowBookmark()).be.true;
searchBar.showBookmark = false;
should(searchBar.showBookmark).be.false;
should(searchBar.getShowBookmark()).be.fasle;
});

it.ios('.keyboardType', function () {
var searchBar = Ti.UI.createSearchBar({
keyboardType: Ti.UI.KEYBOARD_TYPE_NUMBER_PAD
});
should(searchBar.getKeyboardType).be.a.Function;
should(searchBar.keyboardType).eql(Ti.UI.KEYBOARD_TYPE_NUMBER_PAD);
should(searchBar.getKeyboardType()).eql(Ti.UI.KEYBOARD_TYPE_NUMBER_PAD);
searchBar.keyboardType = Ti.UI.KEYBOARD_TYPE_EMAIL;
should(searchBar.keyboardType).eql(Ti.UI.KEYBOARD_TYPE_EMAIL);
should(searchBar.getKeyboardType()).eql(Ti.UI.KEYBOARD_TYPE_EMAIL);
});

it.ios('.autocorrect', function () {
var searchBar = Ti.UI.createSearchBar({
autocorrect: true
});
should(searchBar.getAutocorrect).be.a.Function;
should(searchBar.autocorrect).be.true;
should(searchBar.getAutocorrect()).be.true;
searchBar.autocorrect = false;
should(searchBar.autocorrect).be.false;
should(searchBar.getAutocorrect()).be.false;
});

it.ios('.autocapitalization', function () {
var searchBar = Ti.UI.createSearchBar({
autocapitalization: Ti.UI.TEXT_AUTOCAPITALIZATION_ALL
});
should(searchBar.getAutocapitalization).be.a.Function;
should(searchBar.autocapitalization).eql(Ti.UI.TEXT_AUTOCAPITALIZATION_ALL);
should(searchBar.getAutocapitalization()).eql(Ti.UI.TEXT_AUTOCAPITALIZATION_ALL);
searchBar.autocapitalization = Ti.UI.TEXT_AUTOCAPITALIZATION_SENTENCES;
should(searchBar.autocapitalization).eql(Ti.UI.TEXT_AUTOCAPITALIZATION_SENTENCES);
should(searchBar.getAutocapitalization()).eql(Ti.UI.TEXT_AUTOCAPITALIZATION_SENTENCES);
});

it.ios('.keyboardAppearance', function () {
var searchBar = Ti.UI.createSearchBar({
keyboardAppearance: Ti.UI.KEYBOARD_APPEARANCE_LIGHT
});
should(searchBar.getKeyboardAppearance).be.a.Function;
should(searchBar.keyboardAppearance).eql(Ti.UI.KEYBOARD_APPEARANCE_LIGHT);
should(searchBar.getKeyboardAppearance()).eql(Ti.UI.KEYBOARD_APPEARANCE_LIGHT);
searchBar.keyboardAppearance = Ti.UI.KEYBOARD_APPEARANCE_DARK;
should(searchBar.keyboardAppearance).eql(Ti.UI.KEYBOARD_APPEARANCE_DARK);
should(searchBar.getKeyboardAppearance()).eql(Ti.UI.KEYBOARD_APPEARANCE_DARK);
});

it.ios('.style', function () {
var searchBar = Ti.UI.createSearchBar({
style: Ti.UI.iOS.SEARCH_BAR_STYLE_PROMINENT
});
should(searchBar.getStyle).be.a.Function;
should(searchBar.style).eql(Ti.UI.iOS.SEARCH_BAR_STYLE_PROMINENT);
should(searchBar.getStyle()).eql(Ti.UI.iOS.SEARCH_BAR_STYLE_PROMINENT);
searchBar.style = Ti.UI.iOS.SEARCH_BAR_STYLE_MINIMAL;
should(searchBar.style).eql(Ti.UI.iOS.SEARCH_BAR_STYLE_MINIMAL);
should(searchBar.getStyle()).eql(Ti.UI.iOS.SEARCH_BAR_STYLE_MINIMAL);
});

it.ios('.prompt', function () {
var searchBar = Ti.UI.createSearchBar({
prompt: 'value'
});
should(searchBar.getStyle).be.a.Function;
should(searchBar.prompt).eql('value');
should(searchBar.getPrompt()).eql('value');
searchBar.prompt = 'another value';
should(searchBar.prompt).eql('another value');
should(searchBar.getPrompt()).eql('another value');
});

});

0 comments on commit d03b8f6

Please sign in to comment.