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

fix(android): amend ListView behaviour when search view is defined #12678

Merged
merged 7 commits into from
Apr 8, 2021
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import android.graphics.drawable.GradientDrawable;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.widget.RelativeLayout;

import androidx.annotation.NonNull;
Expand Down Expand Up @@ -110,47 +111,86 @@ private void processProperty(String name, Object value)
}
}

if (name.equals(TiC.PROPERTY_SEARCH_VIEW) && value instanceof TiViewProxy) {
this.searchProxy = (TiViewProxy) value;
final TiUIView search = this.searchProxy.getOrCreateView();
if (name.equals(TiC.PROPERTY_SEARCH_VIEW)) {
final ViewParent parent = getOuterView().getParent();
final TiViewProxy parentProxy = getProxy().getParent();

if (this.searchProxy instanceof SearchBarProxy) {
((TiUISearchBar) search).setOnSearchChangeListener(listView);
} else {
((TiUISearchView) search).setOnSearchChangeListener(listView);
}
if (parent instanceof ViewGroup) {

final View searchView = search.getOuterView();
final ViewGroup searchViewParent = (ViewGroup) searchView.getParent();
final ViewGroup listViewParent = (ViewGroup) listView.getParent();
searchView.setId(SEARCHVIEW_ID);
// Remove current view from parent.
((ViewGroup) parent).removeView(getOuterView());
}

final RelativeLayout view = new RelativeLayout(proxy.getActivity());
// Reset current border and background so this does not corrupt the new view.
this.borderView = null;
this.background = null;

final RelativeLayout.LayoutParams searchViewLayout = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
searchViewLayout.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
searchViewLayout.addRule(RelativeLayout.ALIGN_PARENT_TOP);
searchViewLayout.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
final ViewParent listViewParent = this.listView.getParent();
if (listViewParent instanceof ViewGroup) {

if (searchViewParent != null) {
searchViewParent.removeView(searchView);
// Remove list view from parent, could be TiBorderWrapperView or RelativeLayout.
((ViewGroup) listViewParent).removeView(this.listView);
}
view.addView(searchView, searchViewLayout);

final RelativeLayout.LayoutParams tableViewLayout = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);
tableViewLayout.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
tableViewLayout.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
tableViewLayout.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
tableViewLayout.addRule(RelativeLayout.BELOW, SEARCHVIEW_ID);
if (value instanceof TiViewProxy) {

// Set search proxy.
this.searchProxy = (TiViewProxy) value;
final TiUIView search = this.searchProxy.getOrCreateView();

// Set search listeners.
if (this.searchProxy instanceof SearchBarProxy) {
((TiUISearchBar) search).setOnSearchChangeListener(this.listView);
} else {
((TiUISearchView) search).setOnSearchChangeListener(this.listView);
}

final RelativeLayout view = new RelativeLayout(proxy.getActivity());
final View searchView = search.getOuterView();
final ViewGroup searchViewParent = (ViewGroup) searchView.getParent();
final RelativeLayout.LayoutParams searchViewLayout = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
searchViewLayout.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
searchViewLayout.addRule(RelativeLayout.ALIGN_PARENT_TOP);
searchViewLayout.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);

searchView.setId(SEARCHVIEW_ID);

if (searchViewParent != null) {
searchViewParent.removeView(searchView);
}
view.addView(searchView, searchViewLayout);

if (listViewParent != null) {
listViewParent.removeView(listView);
final RelativeLayout.LayoutParams listViewLayout = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);
listViewLayout.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
listViewLayout.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
listViewLayout.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
listViewLayout.addRule(RelativeLayout.BELOW, SEARCHVIEW_ID);

view.addView(listView, listViewLayout);

// Set new view layout.
setNativeView(view);
} else {

// Reset back to standard list view.
setNativeView(listView);
}
view.addView(listView, tableViewLayout);

setNativeView(view);
// Re-apply background and border to new view.
super.processProperties(getProxy().getProperties());

if (parent != null && parentProxy != null) {
final TiUIView parentView = parentProxy.peekView();

if (parentView != null) {

// Release view and reconstruct parent.
proxy.releaseViews();
parentProxy.realizeViews(parentView);
}
}
}

if ((name.equals(TiC.PROPERTY_SEPARATOR_STYLE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import android.graphics.drawable.GradientDrawable;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.widget.RelativeLayout;

import androidx.annotation.NonNull;
Expand Down Expand Up @@ -113,26 +114,45 @@ private void processProperty(String name, Object value)
}

if (name.equals(TiC.PROPERTY_SEARCH) || name.equals(TiC.PROPERTY_SEARCH_AS_CHILD)) {
final ViewParent parent = getOuterView().getParent();
final TiViewProxy parentProxy = getProxy().getParent();
final KrollDict properties = getProxy().getProperties();
final boolean searchAsChild = TiConvert.toBoolean(
name.equals(TiC.PROPERTY_SEARCH_AS_CHILD)
? value : properties.optBoolean(TiC.PROPERTY_SEARCH_AS_CHILD, true));

if (parent instanceof ViewGroup) {

// Remove current view from parent.
((ViewGroup) parent).removeView(getOuterView());
}

this.searchProxy = (TiViewProxy) (name.equals(TiC.PROPERTY_SEARCH)
? value : properties.get(TiC.PROPERTY_SEARCH));

// Reset current border and background so this does not corrupt the new view.
this.borderView = null;
this.background = null;

final ViewParent tableViewParent = this.tableView.getParent();
if (tableViewParent instanceof ViewGroup) {

// Remove table view from parent, could be TiBorderWrapperView or RelativeLayout.
((ViewGroup) tableViewParent).removeView(this.tableView);
}

if (this.searchProxy != null) {
final TiUIView search = this.searchProxy.getOrCreateView();

if (this.searchProxy instanceof SearchBarProxy) {
((TiUISearchBar) search).setOnSearchChangeListener(tableView);
((TiUISearchBar) search).setOnSearchChangeListener(this.tableView);
} else {
((TiUISearchView) search).setOnSearchChangeListener(tableView);
((TiUISearchView) search).setOnSearchChangeListener(this.tableView);
}

if (searchAsChild) {
final View searchView = search.getOuterView();
final ViewGroup searchViewParent = (ViewGroup) searchView.getParent();
final ViewGroup tableViewParent = (ViewGroup) tableView.getParent();
searchView.setId(SEARCHVIEW_ID);

final RelativeLayout view = new RelativeLayout(proxy.getActivity());
Expand All @@ -155,14 +175,31 @@ private void processProperty(String name, Object value)
tableViewLayout.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
tableViewLayout.addRule(RelativeLayout.BELOW, SEARCHVIEW_ID);

if (tableViewParent != null) {
tableViewParent.removeView(tableView);
}
view.addView(tableView, tableViewLayout);
view.addView(this.tableView, tableViewLayout);

// Set new view layout with search child.
setNativeView(view);
}
}
if (this.searchProxy == null || !searchAsChild) {

// No search proxy or not child, reset back to table.
setNativeView(this.tableView);
}

// Re-apply background and border to new view.
super.processProperties(getProxy().getProperties());

if (parent != null && parentProxy != null) {
final TiUIView parentView = parentProxy.peekView();

if (parentView != null) {

// Release view and reconstruct parent.
proxy.releaseViews();
parentProxy.realizeViews(parentView);
}
}
}

if ((name.equals(TiC.PROPERTY_SEPARATOR_STYLE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,6 @@ public void update()
final String filterAttribute = properties.optString(TiC.PROPERTY_FILTER_ATTRIBUTE, TiC.PROPERTY_TITLE);
int filterResultsCount = 0;
int index = 0;
int filteredIndex = 0;

String query = this.filterQuery;
if (query != null && caseInsensitive) {
Expand All @@ -458,6 +457,7 @@ public void update()
// Iterate through data, processing each supported entry.
for (final Object entry : this.proxy.getData()) {

int filteredIndex = 0;
if (entry instanceof TableViewSectionProxy) {
final TableViewSectionProxy section = (TableViewSectionProxy) entry;
final TableViewRowProxy[] rows = section.getRows();
Expand All @@ -473,6 +473,9 @@ public void update()
for (int i = 0; i < rows.length; i++) {
final TableViewRowProxy row = rows[i];

// Maintain true row index.
row.index = index++;

// Handle search query.
if (query != null) {
String attribute = row.getProperties().optString(filterAttribute, null);
Expand All @@ -492,7 +495,6 @@ public void update()
// Update filtered index of row.
row.setFilteredIndex(query != null ? filteredIndex++ : -1);

row.index = index++;
this.rows.add(row);
}
filterResultsCount += filteredIndex;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public TiBackgroundDrawable getBackground()
private WeakReference<View> touchView = null;

private boolean zIndexChanged = false;
private TiBorderWrapperView borderView;
protected TiBorderWrapperView borderView;
// For twofingertap detection
private boolean didScale = false;

Expand Down