|
1 |
| -import { ChangeType, Device, Property, StackLayout, Utils, View, ViewBase, profile } from '@nativescript/core'; |
2 |
| -import { KeyedTemplate } from '@nativescript/core/ui/core/view'; |
| 1 | +import { ChangeType, ContentView, Device, KeyedTemplate, Property, ProxyViewContainer, StackLayout, Utils, View, ViewBase } from '@nativescript/core'; |
3 | 2 | import { isString } from '@nativescript/core/utils/types';
|
4 | 3 | import {
|
5 | 4 | ItemEventData,
|
@@ -754,22 +753,23 @@ function initPagerRecyclerAdapter() {
|
754 | 753 | if (!view && owner._itemViewLoader !== undefined) {
|
755 | 754 | view = owner._itemViewLoader(template.key);
|
756 | 755 | }
|
757 |
| - const sp = new StackLayout(); |
758 |
| - if (view) { |
759 |
| - sp.addChild(view); |
760 |
| - } else { |
761 |
| - sp[PLACEHOLDER] = true; |
| 756 | + const isNonSync = view === undefined; |
| 757 | + if (isNonSync || view instanceof ProxyViewContainer) { |
| 758 | + const parentView = new ContentView(); |
| 759 | + parentView.id = 'pagerViewHolder'; |
| 760 | + view = parentView; |
| 761 | + view[PLACEHOLDER] = true; |
762 | 762 | }
|
763 |
| - owner._addView(sp); |
| 763 | + owner._addView(view); |
764 | 764 | // sp._setupAsRootView(owner._context);
|
765 | 765 | // //@ts-ignore
|
766 | 766 | // sp.parent = owner;
|
767 | 767 | // sp._isAddedToNativeVisualTree = true;
|
768 | 768 | // sp.callLoaded();
|
769 |
| - sp.nativeView.setLayoutParams(new android.view.ViewGroup.LayoutParams(android.view.ViewGroup.LayoutParams.MATCH_PARENT, android.view.ViewGroup.LayoutParams.MATCH_PARENT)); |
| 769 | + view.nativeView.setLayoutParams(new android.view.ViewGroup.LayoutParams(android.view.ViewGroup.LayoutParams.MATCH_PARENT, android.view.ViewGroup.LayoutParams.MATCH_PARENT)); |
770 | 770 |
|
771 | 771 | initPagerViewHolder();
|
772 |
| - const holder = new PagerViewHolder(sp, new WeakRef(owner)); |
| 772 | + const holder = new PagerViewHolder(view, new WeakRef(owner)); |
773 | 773 | owner._viewHolders.add(holder);
|
774 | 774 | return holder;
|
775 | 775 | }
|
@@ -822,24 +822,23 @@ function initPagerRecyclerAdapter() {
|
822 | 822 | }
|
823 | 823 | }
|
824 | 824 | const bindingContext = owner._getDataItem(index);
|
| 825 | + let view = holder.view; |
| 826 | + const isNonSync = holder.view[PLACEHOLDER] === true; |
| 827 | + view = isNonSync ? view.content : view; |
825 | 828 | const args = {
|
826 | 829 | eventName: Pager.itemLoadingEvent,
|
827 | 830 | object: owner,
|
828 | 831 | android: holder,
|
829 |
| - ios: undefined, |
830 | 832 | index,
|
831 | 833 | bindingContext,
|
832 |
| - view: holder.view[PLACEHOLDER] ? null : holder.view.getChildAt(0) |
| 834 | + view |
833 | 835 | } as ItemEventData;
|
834 | 836 |
|
835 | 837 | owner.notify(args);
|
836 |
| - if (holder.view[PLACEHOLDER]) { |
837 |
| - if (args.view) { |
838 |
| - holder.view.addChild(args.view); |
839 |
| - } else { |
840 |
| - holder.view.addChild(owner._getDefaultItemContent(index)); |
841 |
| - } |
842 |
| - holder.view[PLACEHOLDER] = false; |
| 838 | + if (isNonSync && args.view !== view) { |
| 839 | + view = args.view; |
| 840 | + // the view has been changed on the event handler |
| 841 | + (holder.view as ContentView).content = args.view; |
843 | 842 | }
|
844 | 843 | owner._prepareItem(holder.view, index);
|
845 | 844 | }
|
|
0 commit comments