Skip to content

Commit

Permalink
fix(android): optimized ScrollableView "views" property assignment
Browse files Browse the repository at this point in the history
Fixes TIMOB-28516
  • Loading branch information
jquick-axway authored and ewanharris committed Aug 9, 2021
1 parent bbb4a11 commit 459679a
Showing 1 changed file with 43 additions and 11 deletions.
Expand Up @@ -148,28 +148,60 @@ public TiViewProxy[] getViews()
@Kroll.setProperty
public void setViews(Object views)
{
removeAllViews();
// Clone current view list.
ArrayList<TiViewProxy> oldViewList = new ArrayList<>(this.views);

// Replace all views with the given view collection.
this.views.clear();
if (views instanceof Object[]) {
for (final Object view : (Object[]) views) {
if (view instanceof TiViewProxy) {
addView((TiViewProxy) view);
for (final Object nextObject : (Object[]) views) {
if (nextObject instanceof TiViewProxy) {
TiViewProxy view = (TiViewProxy) nextObject;
if (!this.views.contains(view)) {
view.setActivity(getActivity());
view.setParent(this);
this.views.add(view);
}
}
}
}

// Release all of the views that are no longer attached to this scrollable view.
// Note: If given collection contains views in old collection, then do not release them.
for (TiViewProxy oldView : oldViewList) {
if (!this.views.contains(oldView)) {
oldView.releaseViews();
oldView.setParent(null);
}
}

// Notify native scrollable view about the view collection change.
if (this.scrollableView != null) {
this.scrollableView.getAdapter().notifyDataSetChanged();
}
}

@Kroll.method
public void addView(TiViewProxy view)
{
if (!this.views.contains(view)) {
view.setActivity(getActivity());
view.setParent(this);
this.views.add(view);
// Validate argument.
if (view == null) {
return;
}

if (scrollableView != null) {
scrollableView.getAdapter().notifyDataSetChanged();
}
// Do not continue if already added.
if (this.views.contains(view)) {
return;
}

// Add given view to collection.
view.setActivity(getActivity());
view.setParent(this);
this.views.add(view);

// Notify native scrollable view about the added child view.
if (this.scrollableView != null) {
this.scrollableView.getAdapter().notifyDataSetChanged();
}
}

Expand Down

0 comments on commit 459679a

Please sign in to comment.