Skip to content

Commit

Permalink
feat(all): fixed rows in filtered results (#13684)
Browse files Browse the repository at this point in the history
* feat(android): fixed rows in filtered results

* android listview

* ios tableview

* listview ios

* chore: update docs

---------

Co-authored-by: Hans Knöchel <hansemannn@users.noreply.github.com>
  • Loading branch information
m1ga and hansemannn authored May 3, 2023
1 parent bfa2bc5 commit bb23609
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -689,8 +689,10 @@ public void update(boolean force)
int filteredIndex = 0;
for (final ListItemProxy item : sectionItems) {

boolean alwaysInclude = item.getProperties()
.optBoolean(TiC.PROPERTY_FILTER_ALWAYS_INCLUDE, false);
// Handle search query.
if (query != null) {
if (query != null && !alwaysInclude) {
String searchableText = item.getProperties().optString(TiC.PROPERTY_SEARCHABLE_TEXT, null);
if (searchableText != null) {
if (caseInsensitive) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -671,9 +671,11 @@ public void update(boolean force)

// Maintain true row index.
row.index = index++;
boolean alwaysInclude = row.getProperties()
.optBoolean(TiC.PROPERTY_FILTER_ALWAYS_INCLUDE, false);

// Handle search query.
if (query != null) {
if (query != null && !alwaysInclude) {
String attribute = row.getProperties().optString(filterAttribute, null);

if (attribute != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,7 @@ public class TiC
public static final String PROPERTY_FILTER_ANCHORED = "filterAnchored";
public static final String PROPERTY_FILTER_CASE_INSENSITIVE = "filterCaseInsensitive";
public static final String PROPERTY_FILTER_TOUCHES_WHEN_OBSCURED = "filterTouchesWhenObscured";
public static final String PROPERTY_FILTER_ALWAYS_INCLUDE = "filterAlwaysInclude";
public static final String PROPERTY_FIRSTNAME = "firstName";
public static final String PROPERTY_FIRST_VISIBLE_ITEM = "firstVisibleItem";
public static final String PROPERTY_FIRST_VISIBLE_ITEM_INDEX = "firstVisibleItemIndex";
Expand Down
8 changes: 8 additions & 0 deletions apidoc/Titanium/UI/TableViewRow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,14 @@ properties:
platforms: [android, iphone, ipad, macos]
since: {android: "9.3.0", iphone: "3.2.0", ipad: "3.2.0", macos: "9.2.0"}

- name: filterAlwaysInclude
summary: |
This row will always be visible when you filter your content.
type: Boolean
default: false
platforms: [android, iphone, ipad, macos]
since: "12.2.0"

- name: font
summary: Font to use for the row title.
type: Font
Expand Down
3 changes: 2 additions & 1 deletion iphone/Classes/TiUIListView.m
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,8 @@ - (void)buildResultsForSearchText
for (int j = 0; j < maxItems; j++) {
NSIndexPath *thePath = [NSIndexPath indexPathForRow:j inSection:i];
id theValue = [self valueWithKey:@"searchableText" atIndexPath:thePath];
if (theValue != nil && [[TiUtils stringValue:theValue] rangeOfString:self.searchString options:searchOpts].location != NSNotFound) {
BOOL alwaysInclude = [TiUtils boolValue:[self valueWithKey:@"filterAlwaysInclude" atIndexPath:thePath] def:NO];
if (alwaysInclude || (theValue != nil && [[TiUtils stringValue:theValue] rangeOfString:self.searchString options:searchOpts].location != NSNotFound)) {
(thisSection != nil) ? [thisSection addObject:thePath] : [singleSection addObject:thePath];
hasResults = YES;
}
Expand Down
3 changes: 2 additions & 1 deletion iphone/Classes/TiUITableView.m
Original file line number Diff line number Diff line change
Expand Up @@ -1357,7 +1357,8 @@ - (void)updateSearchResultIndexes
int cellIndex = 0;
for (TiUITableViewRowProxy *row in [thisSection rows]) {
id value = [row valueForKey:ourSearchAttribute];
if (value != nil && [[TiUtils stringValue:value] rangeOfString:searchString options:searchOpts].location != NSNotFound) {
BOOL alwaysInclude = [TiUtils boolValue:[row valueForKey:@"filterAlwaysInclude"] def:NO];
if (alwaysInclude || (value != nil && [[TiUtils stringValue:value] rangeOfString:searchString options:searchOpts].location != NSNotFound)) {
[thisIndexSet addIndex:cellIndex];
}
cellIndex++;
Expand Down

0 comments on commit bb23609

Please sign in to comment.