From ef5c95dcbd2d911291309cbe9d632f360ded6ce7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hans=20Kn=C3=B6chel?= Date: Thu, 11 Mar 2021 15:44:31 +0100 Subject: [PATCH] fix(android): fragments in children of list view and tableview header/footerview (#12524) specifically allow to add a MapView ("ti.map") inside headerView of Ti.UI.ListView Fixes TIMOB-28376 --- .../ui/widget/listview/ListItemProxy.java | 17 ----------------- .../ui/widget/listview/ListSectionProxy.java | 13 +++++++++++-- .../ui/widget/listview/ListViewHolder.java | 12 ++++++++++++ .../ui/widget/tableview/TableViewHolder.java | 14 ++++++++++++-- 4 files changed, 35 insertions(+), 21 deletions(-) diff --git a/android/modules/ui/src/java/ti/modules/titanium/ui/widget/listview/ListItemProxy.java b/android/modules/ui/src/java/ti/modules/titanium/ui/widget/listview/ListItemProxy.java index 045057fdc79..727556843a6 100644 --- a/android/modules/ui/src/java/ti/modules/titanium/ui/widget/listview/ListItemProxy.java +++ b/android/modules/ui/src/java/ti/modules/titanium/ui/widget/listview/ListItemProxy.java @@ -648,23 +648,6 @@ public void releaseViews() { this.holder = null; - final KrollDict properties = getProperties(); - - if (properties.containsKeyAndNotNull(TiC.PROPERTY_HEADER_VIEW)) { - final TiViewProxy header = (TiViewProxy) properties.get(TiC.PROPERTY_HEADER_VIEW); - - if (header.getParent() == this) { - header.releaseViews(); - } - } - if (properties.containsKeyAndNotNull(TiC.PROPERTY_FOOTER_VIEW)) { - final TiViewProxy footer = (TiViewProxy) properties.get(TiC.PROPERTY_FOOTER_VIEW); - - if (footer.getParent() == this) { - footer.releaseViews(); - } - } - super.releaseViews(); } diff --git a/android/modules/ui/src/java/ti/modules/titanium/ui/widget/listview/ListSectionProxy.java b/android/modules/ui/src/java/ti/modules/titanium/ui/widget/listview/ListSectionProxy.java index 9bda0bd78c1..3ff2fa9c598 100644 --- a/android/modules/ui/src/java/ti/modules/titanium/ui/widget/listview/ListSectionProxy.java +++ b/android/modules/ui/src/java/ti/modules/titanium/ui/widget/listview/ListSectionProxy.java @@ -357,11 +357,20 @@ public void release() @Override public void releaseViews() { + // Release all section item views. for (final ListItemProxy item : this.items) { - - // Release all section item views. item.releaseViews(); } + + // Release header/footer views. + if (hasPropertyAndNotNull(TiC.PROPERTY_HEADER_VIEW)) { + final TiViewProxy headerProxy = (TiViewProxy) getProperty(TiC.PROPERTY_HEADER_VIEW); + headerProxy.releaseViews(); + } + if (hasPropertyAndNotNull(TiC.PROPERTY_FOOTER_VIEW)) { + final TiViewProxy footerProxy = (TiViewProxy) getProperty(TiC.PROPERTY_FOOTER_VIEW); + footerProxy.releaseViews(); + } } /** diff --git a/android/modules/ui/src/java/ti/modules/titanium/ui/widget/listview/ListViewHolder.java b/android/modules/ui/src/java/ti/modules/titanium/ui/widget/listview/ListViewHolder.java index d44ab4ceefd..d7d84b2bb42 100644 --- a/android/modules/ui/src/java/ti/modules/titanium/ui/widget/listview/ListViewHolder.java +++ b/android/modules/ui/src/java/ti/modules/titanium/ui/widget/listview/ListViewHolder.java @@ -313,6 +313,8 @@ private void setHeaderFooter(TiViewProxy listViewProxy, return; } + final Context context = this.itemView.getContext(); + // Handle `header` and `footer`. if (updateHeader) { if (properties.containsKeyAndNotNull(TiC.PROPERTY_HEADER_TITLE)) { @@ -325,6 +327,11 @@ private void setHeaderFooter(TiViewProxy listViewProxy, // Handle header view. final TiViewProxy headerProxy = (TiViewProxy) properties.get(TiC.PROPERTY_HEADER_VIEW); + if ((context instanceof Activity) && (headerProxy.getActivity() != context)) { + headerProxy.releaseViews(); + headerProxy.setActivity((Activity) context); + } + final TiUIView view = headerProxy.getOrCreateView(); if (view != null) { final View headerView = view.getOuterView(); @@ -354,6 +361,11 @@ private void setHeaderFooter(TiViewProxy listViewProxy, // Handle footer view. final TiViewProxy footerProxy = (TiViewProxy) properties.get(TiC.PROPERTY_FOOTER_VIEW); + if ((context instanceof Activity) && (footerProxy.getActivity() != context)) { + footerProxy.releaseViews(); + footerProxy.setActivity((Activity) context); + } + final TiUIView view = footerProxy.getOrCreateView(); if (view != null) { final View footerView = view.getOuterView(); diff --git a/android/modules/ui/src/java/ti/modules/titanium/ui/widget/tableview/TableViewHolder.java b/android/modules/ui/src/java/ti/modules/titanium/ui/widget/tableview/TableViewHolder.java index d3a1fac9bea..0ca14dc3a68 100644 --- a/android/modules/ui/src/java/ti/modules/titanium/ui/widget/tableview/TableViewHolder.java +++ b/android/modules/ui/src/java/ti/modules/titanium/ui/widget/tableview/TableViewHolder.java @@ -520,6 +520,8 @@ private void setHeaderFooter(TiViewProxy tableViewProxy, return; } + final Context context = this.itemView.getContext(); + // Handle `header` and `footer`. if (updateHeader) { @@ -536,8 +538,12 @@ private void setHeaderFooter(TiViewProxy tableViewProxy, // Handle header view. final TiViewProxy headerProxy = (TiViewProxy) properties.get(TiC.PROPERTY_HEADER_VIEW); - final TiUIView view = headerProxy.getOrCreateView(); + if ((context instanceof Activity) && (headerProxy.getActivity() != context)) { + headerProxy.releaseViews(); + headerProxy.setActivity((Activity) context); + } + final TiUIView view = headerProxy.getOrCreateView(); if (view != null) { final View headerView = view.getOuterView(); @@ -574,8 +580,12 @@ private void setHeaderFooter(TiViewProxy tableViewProxy, // Handle footer view. final TiViewProxy footerProxy = (TiViewProxy) properties.get(TiC.PROPERTY_FOOTER_VIEW); - final TiUIView view = footerProxy.getOrCreateView(); + if ((context instanceof Activity) && (footerProxy.getActivity() != context)) { + footerProxy.releaseViews(); + footerProxy.setActivity((Activity) context); + } + final TiUIView view = footerProxy.getOrCreateView(); if (view != null) { final View footerView = view.getOuterView();