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-26021] iOS: Search Bar- search results tableview background color change #10033

Merged
merged 8 commits into from
May 17, 2018
47 changes: 47 additions & 0 deletions apidoc/Titanium/UI/TableView.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1486,6 +1486,53 @@ properties:
constants: Titanium.UI.iOS.TableViewStyle.*
platforms: [iphone, ipad]

- name: resultsBackgroundColor
summary: The background color of the search results (iOS-only).
description: |
For information about color values, see the "Colors" section of <Titanium.UI>.
Note: A transparent background-color is not officially supported by Apple to
prevent that the list of results overlaps with the list view below it.
type: String
default: undefined (behaves as white)
since: 7.3.0
platforms: [iphone, ipad]
availability: creation

- name: resultsSeparatorColor
summary: |
Separator line color between rows inside search results,
as a color name or hex triplet (iOS-only).
description: |
To make the line invisible, set this property to `transparent`, or the same value as the
[backgroundColor](Titanium.UI.TableView.backgroundColor) property.
For information about color values, see the "Colors" section of <Titanium.UI>.
type: String
default: undefined (behaves as gray)
since: 7.3.0
platforms: [iphone, ipad]
availability: creation

- name: resultsSeparatorStyle
summary: The separator style of the search results (iOS-only).
type: Number
constants: Titanium.UI.TABLE_VIEW_SEPARATOR_STYLE_*
since: 7.3.0
platforms: [iphone, ipad]
availability: creation

- name: resultsSeparatorInsets
summary: |
The insets for search results separators (applies to all cells & iOS-only).
description: |
In iOS 7 and later, cell separators do not extend all the way to the edge of the list view.
This property sets the default inset for all cells in the table.
Set this to a dictionary with two keys, `left` specifying inset from left edge and `right`
specifying the inset from the right edge.
type: Dictionary
since: 7.3.0
platforms: [iphone, ipad]
availability: creation

examples:
- title: Simple Table View
example: |
Expand Down
25 changes: 25 additions & 0 deletions iphone/Classes/TiUITableView.m
Original file line number Diff line number Diff line change
Expand Up @@ -2767,6 +2767,31 @@ - (void)didDismissSearchController:(UISearchController *)searchController

- (void)presentSearchController:(UISearchController *)controller
{
TiColor *resultsBackgroundColor = [TiUtils colorValue:[[self proxy] valueForKey:@"resultsBackgroundColor"]];
TiColor *resultsSeparatorColor = [TiUtils colorValue:[[self proxy] valueForKey:@"resultsSeparatorColor"]];
id resultsSeparatorInsets = [[self proxy] valueForKey:@"resultsSeparatorInsets"];
id resultsSeparatorStyle = [[self proxy] valueForKey:@"resultsSeparatorStyle"];

ENSURE_TYPE_OR_NIL(resultsSeparatorInsets, NSDictionary);
ENSURE_TYPE_OR_NIL(resultsSeparatorStyle, NSNumber);

if (resultsBackgroundColor) {
// TIMOB-23281: Hack to support transparent backgrounds (not officially supported)
UIColor *color = [resultsBackgroundColor _color] == [UIColor clearColor] ? [UIColor colorWithWhite:1.0 alpha:0.0001] : [resultsBackgroundColor _color];
[tableview setBackgroundColor:color];
}

if (resultsSeparatorColor) {
[tableview setSeparatorColor:[resultsSeparatorColor _color]];
}

if (resultsSeparatorInsets) {
[tableview setSeparatorInset:[TiUtils contentInsets:resultsSeparatorInsets]];
}

if (resultsSeparatorStyle) {
[tableview setSeparatorStyle:[TiUtils intValue:resultsSeparatorStyle def:UITableViewCellSeparatorStyleSingleLine]];
}
tableContentOffset = [tableview contentOffset];

if (!searchControllerPresenter) {
Expand Down
106 changes: 106 additions & 0 deletions tests/Resources/ti.ui.tableview.addontest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/*
* Appcelerator Titanium Mobile
* Copyright (c) 2015-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.TableView', function () {
it.ios('#separatorStyle', function () {
var section_0,
tableView;
section_0 = Ti.UI.createTableViewSection({ headerTitle: 'Zero' });
section_0.add(Ti.UI.createTableViewRow({ title: 'Red' }));
section_0.add(Ti.UI.createTableViewRow({ title: 'White' }));

tableView = Ti.UI.createTableView({
data: [ section_0 ],
separatorStyle: Ti.UI.TABLE_VIEW_SEPARATOR_STYLE_SINGLE_LINE
});
should(tableView.getSeparatorStyle).be.a.Function;
should(tableView.separatorStyle).eql(Ti.UI.TABLE_VIEW_SEPARATOR_STYLE_SINGLE_LINE);
should(tableView.getSeparatorStyle()).eql(Ti.UI.TABLE_VIEW_SEPARATOR_STYLE_SINGLE_LINE);
tableView.setSeparatorStyle(Ti.UI.TABLE_VIEW_SEPARATOR_STYLE_NONE);
should(tableView.separatorStyle).eql(Ti.UI.TABLE_VIEW_SEPARATOR_STYLE_NONE);
should(tableView.getSeparatorStyle()).eql(Ti.UI.TABLE_VIEW_SEPARATOR_STYLE_NONE);
});

it.ios('#separatorColor', function () {
var section_0,
tableView;
section_0 = Ti.UI.createTableViewSection({ headerTitle: 'Zero' });
section_0.add(Ti.UI.createTableViewRow({ title: 'Red' }));
section_0.add(Ti.UI.createTableViewRow({ title: 'White' }));

tableView = Ti.UI.createTableView({
data: [ section_0 ],
separatorColor: 'red'
});
should(tableView.getSeparatorColor).be.a.Function;
should(tableView.separatorColor).eql('red');
should(tableView.getSeparatorColor()).eql('red');
tableView.setSeparatorColor('blue');
should(tableView.separatorColor).eql('blue');
should(tableView.getSeparatorColor()).eql('blue');
});

it.ios('#resultsBackgroundColor', function () {
var section_0,
tableView;
section_0 = Ti.UI.createTableViewSection({ headerTitle: 'Zero' });
section_0.add(Ti.UI.createTableViewRow({ title: 'Red' }));
section_0.add(Ti.UI.createTableViewRow({ title: 'White' }));

tableView = Ti.UI.createTableView({
data: [ section_0 ],
resultsBackgroundColor: 'red'
});
should(tableView.getResultsBackgroundColor).be.a.Function;
should(tableView.resultsBackgroundColor).eql('red');
should(tableView.getResultsBackgroundColor()).eql('red');
});

it.ios('#resultsSeparatorColor', function () {
var section_0,
tableView;
section_0 = Ti.UI.createTableViewSection({ headerTitle: 'Zero' });
section_0.add(Ti.UI.createTableViewRow({ title: 'Red' }));
section_0.add(Ti.UI.createTableViewRow({ title: 'White' }));

tableView = Ti.UI.createTableView({
data: [ section_0 ],
resultsSeparatorColor: 'red'
});
should(tableView.getResultsSeparatorColor).be.a.Function;
should(tableView.resultsSeparatorColor).eql('red');
should(tableView.getResultsSeparatorColor()).eql('red');
});

it.ios('#resultsSeparatorStyle', function () {
var section_0,
tableView;
section_0 = Ti.UI.createTableViewSection({ headerTitle: 'Zero' });
section_0.add(Ti.UI.createTableViewRow({ title: 'Red' }));
section_0.add(Ti.UI.createTableViewRow({ title: 'White' }));

tableView = Ti.UI.createTableView({
data: [ section_0 ],
resultsSeparatorStyle: Ti.UI.TABLE_VIEW_SEPARATOR_STYLE_SINGLE_LINE
});
should(tableView.getResultsSeparatorStyle).be.a.Function;
should(tableView.resultsSeparatorStyle).eql(Ti.UI.TABLE_VIEW_SEPARATOR_STYLE_SINGLE_LINE);
should(tableView.getResultsSeparatorStyle()).eql(Ti.UI.TABLE_VIEW_SEPARATOR_STYLE_SINGLE_LINE);
});

it.windowsMissing('scrollable', function () {
var tableView = Ti.UI.createTableView({ scrollable: false });
should(tableView.scrollable).be.eql(false);
tableView.scrollable = !tableView.scrollable;
should(tableView.scrollable).be.eql(true);
});
});