Skip to content

Commit

Permalink
fix(android): TableView regressions (#12558)
Browse files Browse the repository at this point in the history
* fix(android): amend TableViewRow image handling

* fix(android): minRowHeight and maxRowHeight implementation

* fix(android): always remove parent reference

* fix(android): swap to content view on add/remove

* fix(android): amend row index to index of table, not section

* fix(android): amend item index to index of list, not section

* fix(android): revert ListView index handling behaviour

* fix(android): use TiUIHelper.getResourceDrawable()

* fix(android): force Object variant of TiUIHelper.getResourceDrawable()
  • Loading branch information
garymathews authored and sgtcoolguy committed Mar 16, 2021
1 parent c1a5cd0 commit 65ed909
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,39 @@ public void setNativeView(View view)
}

@Override
public void add(TiUIView child)
{
// TODO: This could be improved to prevent the need for swapping native views.
// Our `nativeView` is currently set as our TableViewHolder view as a workaround
// for allowing events/properties to set on our holder instead of our row content.
// Temporarily swap our native view back to original content while new child is added.
final View nativeView = getNativeView();
if (nativeView != null) {
setNativeView(this.content);
super.add(child);
setNativeView(nativeView);
} else {
super.add(child);
}
}

@Override
public void remove(TiUIView child)
{
// TODO: This could be improved to prevent the need for swapping native views.
// Our `nativeView` is currently set as our TableViewHolder view as a workaround
// for allowing events/properties to set on our holder instead of our row content.
// Temporarily swap our native view back to original content while new child is removed.
final View nativeView = getNativeView();
if (nativeView != null) {
setNativeView(this.content);
super.remove(child);
setNativeView(nativeView);
} else {
super.remove(child);
}
}

protected boolean canApplyTouchFeedback(@NonNull KrollDict props)
{
// Prevent TiUIView from overriding `touchFeedback` effect.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ public KrollDict generateScrollPayload()
final int firstVisibleSectionIndex = proxy.getIndexOfSection(firstVisibleSection);
payload.put(TiC.PROPERTY_FIRST_VISIBLE_SECTION_INDEX, firstVisibleSectionIndex);
} else {

// Could not obtain section, mark as undefined.
payload.put(TiC.PROPERTY_FIRST_VISIBLE_SECTION, null);
payload.put(TiC.PROPERTY_FIRST_VISIBLE_SECTION_INDEX, -1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import org.appcelerator.titanium.TiC;
import org.appcelerator.titanium.proxy.TiViewProxy;
import org.appcelerator.titanium.util.TiConvert;
import org.appcelerator.titanium.util.TiFileHelper;
import org.appcelerator.titanium.util.TiUIHelper;

import java.lang.ref.WeakReference;
Expand All @@ -45,7 +44,6 @@ public abstract class TiRecyclerViewHolder extends RecyclerView.ViewHolder
protected static Drawable moreDrawable;

protected static Resources resources;
protected static TiFileHelper fileHelper;

protected WeakReference<TiViewProxy> proxy;

Expand Down Expand Up @@ -102,11 +100,6 @@ public TiRecyclerViewHolder(final Context context, final ViewGroup viewGroup)
} else {
Log.w(TAG, "Could not obtain context resources instance.");
}
if (fileHelper == null) {

// Obtain file helper instance.
fileHelper = new TiFileHelper(context);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,23 @@ public void bind(final TableViewRowProxy proxy, final boolean selected)
return;
}

// Set maximum row height.
final String rawMaxHeight = properties.optString(TiC.PROPERTY_MAX_ROW_HEIGHT,
tableViewProperties.getString(TiC.PROPERTY_MAX_ROW_HEIGHT));
final TiDimension maxHeightDimension = TiConvert.toTiDimension(rawMaxHeight, TiDimension.TYPE_HEIGHT);
final int maxHeight = rawMaxHeight != null ? maxHeightDimension.getAsPixels(itemView) : -1;
if (maxHeight > -1) {
nativeRowView.measure(0, 0);

// Enforce max row height.
if (nativeRowView.getMeasuredHeight() > maxHeight) {
rowView.getLayoutParams().optionHeight = maxHeightDimension;
}
}

// Set minimum row height.
final String rawMinHeight = properties.optString(TiC.PROPERTY_MIN_ROW_HEIGHT, "0");
final String rawMinHeight = properties.optString(TiC.PROPERTY_MIN_ROW_HEIGHT,
tableViewProperties.getString(TiC.PROPERTY_MIN_ROW_HEIGHT));
final int minHeight = TiConvert.toTiDimension(rawMinHeight, TiDimension.TYPE_HEIGHT).getAsPixels(itemView);
this.container.setMinimumHeight(minHeight);

Expand Down Expand Up @@ -209,15 +224,19 @@ public void bind(final TableViewRowProxy proxy, final boolean selected)
// Handle row left and right images.
if (properties.containsKeyAndNotNull(TiC.PROPERTY_LEFT_IMAGE)) {
final String url = properties.getString(TiC.PROPERTY_LEFT_IMAGE);
final Drawable drawable = fileHelper.loadDrawable(url, false);
this.leftImage.setImageDrawable(drawable);
this.leftImage.setVisibility(View.VISIBLE);
final Drawable drawable = TiUIHelper.getResourceDrawable((Object) url);
if (drawable != null) {
this.leftImage.setImageDrawable(drawable);
this.leftImage.setVisibility(View.VISIBLE);
}
}
if (properties.containsKeyAndNotNull(TiC.PROPERTY_RIGHT_IMAGE)) {
final String url = properties.getString(TiC.PROPERTY_RIGHT_IMAGE);
final Drawable drawable = fileHelper.loadDrawable(url, false);
this.rightImage.setImageDrawable(drawable);
this.rightImage.setVisibility(View.VISIBLE);
final Drawable drawable = TiUIHelper.getResourceDrawable((Object) url);
if (drawable != null) {
this.rightImage.setImageDrawable(drawable);
this.rightImage.setVisibility(View.VISIBLE);
}
} else {
final boolean hasCheck = properties.optBoolean(TiC.PROPERTY_HAS_CHECK, false);
final boolean hasChild = properties.optBoolean(TiC.PROPERTY_HAS_CHILD, false);
Expand Down Expand Up @@ -314,7 +333,6 @@ public void bind(final TableViewRowProxy proxy, final boolean selected)
// Add row to content.
this.content.addView(nativeRowView, rowView.getLayoutParams());
this.content.setVisibility(View.VISIBLE);

}
if (properties.containsKeyAndNotNull(TiC.PROPERTY_TITLE)
&& proxy.getChildren().length == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,8 @@ public void update()
final boolean filterAnchored = properties.optBoolean(TiC.PROPERTY_FILTER_ANCHORED, false);
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 Down Expand Up @@ -468,8 +470,6 @@ public void update()
this.rows.add(row);
}

int index = 0;
int filteredIndex = 0;
for (int i = 0; i < rows.length; i++) {
final TableViewRowProxy row = rows[i];

Expand Down
5 changes: 5 additions & 0 deletions android/titanium/src/java/org/appcelerator/titanium/TiC.java
Original file line number Diff line number Diff line change
Expand Up @@ -2342,6 +2342,11 @@ public class TiC
*/
public static final String PROPERTY_MAX_LINES = "maxLines";

/**
* @module.api
*/
public static final String PROPERTY_MAX_ROW_HEIGHT = "maxRowHeight";

/**
* @module.api
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -667,11 +667,11 @@ public void remove(TiViewProxy child)
} else {
if (children != null) {
children.remove(child);
if (child.parent != null && child.parent.get() == this) {
child.parent = null;
}
}
}
if (child.parent != null && child.parent.get() == this) {
child.parent = null;
}
}

/**
Expand Down

0 comments on commit 65ed909

Please sign in to comment.