|
1 |
| -import { GridLayout, View } from '@nativescript/core'; |
| 1 | +import { GridLayout, View, Trace } from '@nativescript/core'; |
2 | 2 | import { TabContentItem as TabContentItemDefinition } from '.';
|
3 | 3 | import { TabContentItemBase } from './tab-content-item-common';
|
4 | 4 |
|
@@ -37,20 +37,30 @@ export class TabContentItem extends TabContentItemBase {
|
37 | 37 | (this as TabContentItemDefinition).canBeLoaded = false;
|
38 | 38 | }
|
39 | 39 |
|
40 |
| - _getChildFragmentManager() { |
41 |
| - const tabView = this.parent as View; |
42 |
| - let tabFragment = null; |
43 |
| - const fragmentManager = tabView._getFragmentManager(); |
| 40 | + private _fragmentMatches(fragment: any) { |
| 41 | + // ensure index AND owner for when 2 tabviews are in the same page |
| 42 | + return fragment.index === this.index && fragment.owner === this.parent; |
| 43 | + } |
| 44 | + private _findFragment(fragmentManager: androidx.fragment.app.FragmentManager) { |
| 45 | + if (!fragmentManager) { |
| 46 | + return null; |
| 47 | + } |
44 | 48 | const fragments = fragmentManager.getFragments().toArray();
|
45 | 49 | for (let i = 0; i < fragments.length; i++) {
|
46 |
| - // ensure index AND owner for when 2 tabviews are in the same page |
47 |
| - if (fragments[i].index === this.index && fragments[i].owner === tabView) { |
48 |
| - tabFragment = fragments[i]; |
49 |
| - break; |
| 50 | + if (fragments[i].index === this.index && fragments[i].owner === this.parent) { |
| 51 | + return fragments[i]; |
50 | 52 | }
|
51 | 53 | }
|
| 54 | + return null; |
| 55 | + } |
| 56 | + |
| 57 | + _getChildFragmentManager() { |
| 58 | + const tabView = this.parent as View; |
| 59 | + let tabFragment = null; |
| 60 | + tabFragment = this._findFragment(tabView._getRootFragmentManager()) || this._findFragment(tabView._getFragmentManager()); |
52 | 61 | if (!tabFragment) {
|
53 |
| - return fragmentManager; |
| 62 | + Trace.write(`No fragment found for ${tabView} with index ${this.index}`, Trace.categories.Error, Trace.messageType.error); |
| 63 | + return tabView._getFragmentManager(); |
54 | 64 | }
|
55 | 65 | return tabFragment.getChildFragmentManager();
|
56 | 66 | }
|
|
0 commit comments