Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 15 commits into from
Jun 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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');
});

});