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 TableViewRow reuse #12620

Merged
merged 4 commits into from
Mar 23, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -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