Skip to content

Commit

Permalink
fix(android): amend TableViewRow reuse (#12620)
Browse files Browse the repository at this point in the history
* validate activity for ripple effect

Fixes TIMOB-28399
  • Loading branch information
garymathews committed Mar 23, 2021
1 parent c85eec4 commit af3a091
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -317,9 +317,14 @@ public void deleteRow(Object rowObj, @Kroll.argument(optional = true) KrollDict
@Kroll.method
public void deleteSection(int index, @Kroll.argument(optional = true) KrollDict animation)
{
this.sections.remove(getSectionByIndex(index));
final TableViewSectionProxy section = getSectionByIndex(index);

update();
if (section != null) {
this.sections.remove(section);
section.setParent(null);

update();
}
}

@Override
Expand Down Expand Up @@ -351,6 +356,10 @@ public Object[] getData()
public void setData(Object[] data)
// clang-format on
{
for (final TableViewSectionProxy section : this.sections) {
section.releaseViews();
section.setParent(null);
}
this.sections.clear();

for (Object d : data) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import java.util.List;

import org.appcelerator.kroll.KrollDict;
import org.appcelerator.kroll.KrollProxy;
import org.appcelerator.kroll.annotations.Kroll;
import org.appcelerator.kroll.common.Log;
import org.appcelerator.titanium.TiC;
Expand Down Expand Up @@ -81,14 +80,10 @@ public TableViewRowProxy(boolean placeholder)
*
* @return TableViewRowProxy
*/
@Override
public TableViewRowProxy clone()
{
final TableViewRowProxy proxy = (TableViewRowProxy) KrollProxy.createProxy(
this.getClass(),
getKrollObject(),
new Object[] { properties },
this.creationUrl.url
);
final TableViewRowProxy proxy = (TableViewRowProxy) super.clone();

// Reference clone, to update properties.
clones.add(new WeakReference<>(proxy));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ public void add(int index, Object rowObj)

if (row != null) {

if (row.getParent() != null) {
final TiViewProxy parent = row.getParent();
if (parent != null && parent.getParent() != null) {

// Row already exists, clone.
row = row.clone();
Expand Down Expand Up @@ -79,7 +80,8 @@ public void add(Object rowObj)

if (row != null) {

if (row.getParent() != null) {
final TiViewProxy parent = row.getParent();
if (parent != null && parent.getParent() != null) {

// Row already exists, clone.
row = row.clone();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,19 +110,23 @@ public TiRecyclerViewHolder(final Context context, final ViewGroup viewGroup)
*/
protected Drawable generateRippleDrawable(Drawable drawable, String color)
{
final int[][] rippleStates = new int[][] { new int[] { } };
final TypedValue typedValue = new TypedValue();
final Activity activity = TiApplication.getAppCurrentActivity();
final TypedArray colorControlHighlight = activity.obtainStyledAttributes(
typedValue.data, new int[] { android.R.attr.colorControlHighlight });
final int colorControlHighlightInt = color != null && !color.isEmpty()
? TiConvert.toColor(color) : colorControlHighlight.getColor(0, 0);
final int[] rippleColors = new int[] { colorControlHighlightInt };
final ColorStateList colorStateList = new ColorStateList(rippleStates, rippleColors);
final ShapeDrawable maskDrawable = drawable == null ? new ShapeDrawable() : null;

// Create the RippleDrawable.
drawable = new RippleDrawable(colorStateList, drawable, maskDrawable);

if (activity != null) {
final int[][] rippleStates = new int[][] { new int[] {} };
final TypedValue typedValue = new TypedValue();

final TypedArray colorControlHighlight = activity.obtainStyledAttributes(
typedValue.data, new int[] { android.R.attr.colorControlHighlight });
final int colorControlHighlightInt = color != null && !color.isEmpty()
? TiConvert.toColor(color) : colorControlHighlight.getColor(0, 0);
final int[] rippleColors = new int[] { colorControlHighlightInt };
final ColorStateList colorStateList = new ColorStateList(rippleStates, rippleColors);
final ShapeDrawable maskDrawable = drawable == null ? new ShapeDrawable() : null;

// Create the RippleDrawable.
drawable = new RippleDrawable(colorStateList, drawable, maskDrawable);
}

return drawable;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,28 @@ public void release()
*/
public abstract TiUIView createView(Activity activity);

/**
* Create clone of existing proxy, including children.
*
* @return TiViewProxy
*/
public TiViewProxy clone()
{
final TiViewProxy proxy = (TiViewProxy) KrollProxy.createProxy(
this.getClass(),
getKrollObject(),
new Object[] { properties },
this.creationUrl.url
);

// Include children.
for (final TiViewProxy child : this.children) {
proxy.add(child.clone());
}

return proxy;
}

/**
* Adds a child to this view proxy.
* @param args The child view proxy/proxies to add.
Expand Down

0 comments on commit af3a091

Please sign in to comment.