Skip to content

Commit 08be307

Browse files
committed
chore: refactor
1 parent 0923641 commit 08be307

File tree

5 files changed

+10
-48
lines changed

5 files changed

+10
-48
lines changed
Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
1-
// Types
1+
import { GridLayout, View } from '@nativescript/core';
22
import { TabContentItem as TabContentItemDefinition } from '.';
3-
import { TabNavigationBase } from '../tab-navigation-base';
4-
import { GridLayout, Trace, View } from '@nativescript/core';
5-
// Requires
6-
import { TabContentItemBase, traceCategory } from './tab-content-item-common';
3+
import { TabContentItemBase } from './tab-content-item-common';
74

85
export * from './tab-content-item-common';
96

107
export class TabContentItem extends TabContentItemBase {
118
public nativeViewProtected: org.nativescript.widgets.GridLayout;
129
public tabItemSpec: com.nativescript.material.core.TabItemSpec;
13-
public index: number;
1410

1511
get _hasFragments(): boolean {
1612
return true;
@@ -40,35 +36,4 @@ export class TabContentItem extends TabContentItemBase {
4036
super.disposeNativeView();
4137
(this as TabContentItemDefinition).canBeLoaded = false;
4238
}
43-
44-
public _getChildFragmentManager(): androidx.fragment.app.FragmentManager {
45-
const tabView = this.parent as TabNavigationBase;
46-
let tabFragment = null;
47-
const fragmentManager = tabView._getFragmentManager();
48-
49-
if (typeof this.index === 'undefined') {
50-
Trace.write('Current TabContentItem index is not set', traceCategory, Trace.messageType.error);
51-
}
52-
53-
const fragments = fragmentManager.getFragments().toArray();
54-
for (let i = 0; i < fragments.length; i++) {
55-
if (fragments[i].index === this.index) {
56-
tabFragment = fragments[i];
57-
break;
58-
}
59-
}
60-
61-
// TODO: can happen in a modal tabview scenario when the modal dialog fragment is already removed
62-
if (!tabFragment) {
63-
// if (Trace.isEnabled()) {
64-
// Trace.write(`Could not get child fragment manager for tab item with index ${this.index}`, traceCategory);
65-
// }
66-
67-
// TODO: fix d.ts in view module
68-
//@ts-ignore
69-
return tabView._getRootFragmentManager();
70-
}
71-
72-
return tabFragment.getChildFragmentManager();
73-
}
7439
}

src/core-tabs/tab-content-item/index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,6 @@ export class TabContentItem extends ContentView {
88
* @private
99
*/
1010
canBeLoaded?: boolean;
11+
12+
public index: number;
1113
}

src/core-tabs/tab-content-item/index.ios.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { TabContentItemBase } from './tab-content-item-common';
44
export * from './tab-content-item-common';
55

66
export class TabContentItem extends TabContentItemBase {
7-
// tslint:disable-next-line
7+
// used to store native value
88
private __controller: UIViewController;
99

1010
public setViewController(controller: UIViewController, nativeView: UIView) {
Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,20 @@
11
// Types
22
import { AddChildFromBuilder, CSSType, ContentView, View, ViewBase } from '@nativescript/core';
33
import { TabContentItem as TabContentItemDefinition } from '.';
4-
import { TabNavigationBase } from '../tab-navigation-base';
5-
6-
export const traceCategory = 'TabView';
74

85
@CSSType('MDTabContentItem')
96
export abstract class TabContentItemBase extends ContentView implements TabContentItemDefinition, AddChildFromBuilder {
7+
public index: number;
108
public eachChild(callback: (child: View) => boolean) {
119
if (this.content) {
1210
callback(this.content);
1311
}
1412
}
1513

1614
public loadView(view: ViewBase): void {
17-
const tabView = this.parent as TabNavigationBase;
18-
if (tabView && tabView.items) {
19-
// Don't load items until their fragments are instantiated.
20-
if ((this as TabContentItemDefinition).canBeLoaded) {
21-
super.loadView(view);
22-
}
15+
// Don't load items until their fragments are instantiated.
16+
if ((this as TabContentItemDefinition).canBeLoaded) {
17+
super.loadView(view);
2318
}
2419
}
2520
}

src/core-tabs/tab-navigation/index.ios.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1030,7 +1030,7 @@ export abstract class TabNavigation<
10301030
[itemsProperty.setNative](value: TabContentItem[]) {
10311031
if (value) {
10321032
value.forEach((item: TabContentItem, i) => {
1033-
(item as any).index = i;
1033+
item.index = i;
10341034
});
10351035
}
10361036
this.setViewControllers(value);

0 commit comments

Comments
 (0)