Skip to content

Commit 77ccc57

Browse files
committed
fix(bottom-navigation/tabs): android refactor regressions fix
1 parent ed7744d commit 77ccc57

File tree

1 file changed

+28
-10
lines changed

1 file changed

+28
-10
lines changed

src/core/tab-navigation-base/tab-navigation/index.android.ts

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { TabContentItem } from '../tab-content-item';
33
import { getIconSpecSize, itemsProperty, selectedIndexProperty, tabStripProperty } from '../tab-navigation-base';
44
import { TabStrip } from '../tab-strip';
55
import { TabStripItem } from '../tab-strip-item';
6-
import { TabNavigationBase, animationEnabledProperty, offscreenTabLimitProperty, swipeEnabledProperty } from './index-common';
6+
import { TabNavigationBase, TabsPosition, animationEnabledProperty, offscreenTabLimitProperty, swipeEnabledProperty } from './index-common';
77
export * from './index-common';
88
export { TabContentItem, TabStrip, TabStripItem };
99

@@ -27,6 +27,22 @@ function makeFragmentName(viewId: number, id: number): string {
2727
return 'android:viewpager:' + viewId + ':' + id;
2828
}
2929

30+
/**
31+
* Gets the parent fragment manager from a fragment to be used in destroying or hiding it.
32+
* @param fragment target fragment
33+
* @returns the parent fragment manager or null if none exists.
34+
*/
35+
function _getParentFragmentManagerFromFragment(fragment: androidx.fragment.app.Fragment) {
36+
if (!fragment) {
37+
return null;
38+
}
39+
try {
40+
return fragment.getParentFragmentManager();
41+
} catch (e) {
42+
return null;
43+
}
44+
}
45+
3046
function getTabById(id: number): TabNavigation {
3147
const ref = tabs.find((ref) => {
3248
const tab = ref.get();
@@ -89,8 +105,8 @@ function initializeNativeClasses() {
89105
// TODO: Consider removing it when update to androidx.fragment:1.2.0
90106
if (hasRemovingParent && this.owner.selectedIndex === this.index && this.owner.nativeViewProtected) {
91107
const bitmapDrawable = new android.graphics.drawable.BitmapDrawable(appResources, this.backgroundBitmap);
92-
this.owner.mOriginalBackground = this.owner.backgroundColor || new Color('White');
93-
this.owner.nativeViewProtected.setBackgroundDrawable(bitmapDrawable);
108+
this.owner._originalBackground = this.owner.backgroundColor || new Color('White');
109+
this.owner.nativeViewProtected.setBackground(bitmapDrawable);
94110
this.backgroundBitmap = null;
95111
}
96112

@@ -209,7 +225,7 @@ function initializeNativeClasses() {
209225
}
210226
const fragment: androidx.fragment.app.Fragment = object as androidx.fragment.app.Fragment;
211227
if (!this.mCurTransaction) {
212-
const fragmentManager = fragment.getParentFragmentManager();
228+
const fragmentManager = _getParentFragmentManagerFromFragment(fragment);
213229
this.mCurTransaction = fragmentManager?.beginTransaction();
214230
}
215231

@@ -389,7 +405,8 @@ export abstract class TabNavigation<T extends android.view.ViewGroup = any> exte
389405
protected mViewPager: com.nativescript.material.core.TabViewPager;
390406
protected mPagerAdapter: androidx.viewpager.widget.PagerAdapter;
391407
protected mAndroidViewId = -1;
392-
public mOriginalBackground: any;
408+
// value from N core!!!
409+
public _originalBackground: any;
393410
protected mTextTransform: CoreTypes.TextTransformType = 'uppercase';
394411
protected mSelectedItemColor: Color;
395412
protected mUnSelectedItemColor: Color;
@@ -483,7 +500,8 @@ export abstract class TabNavigation<T extends android.view.ViewGroup = any> exte
483500
const context = this._context;
484501
const tabsBar = (this.mTabsBar = this.createNativeTabBar(context));
485502
setElevation(null, tabsBar, this.tabsPosition);
486-
if (this.tabsPosition !== 'top') {
503+
console.log('handleTabStripChanged', this.tabsPosition);
504+
if (this.tabsPosition !== TabsPosition.Top) {
487505
tabsBar.setLayoutParams(this.tabBarLayoutParams);
488506
}
489507
nativeView.addView(tabsBar);
@@ -587,10 +605,10 @@ export abstract class TabNavigation<T extends android.view.ViewGroup = any> exte
587605
public onLoaded(): void {
588606
super.onLoaded();
589607

590-
if (this.mOriginalBackground) {
608+
if (this._originalBackground) {
591609
this.backgroundColor = null;
592-
this.backgroundColor = this.mOriginalBackground;
593-
this.mOriginalBackground = null;
610+
this.backgroundColor = this._originalBackground;
611+
this._originalBackground = null;
594612
}
595613

596614
this.setItems(this.items as any);
@@ -660,7 +678,7 @@ export abstract class TabNavigation<T extends android.view.ViewGroup = any> exte
660678
fragmentExitTransition.setResetOnTransitionEnd(true);
661679
}
662680
if (fragment && fragment.isAdded() && !fragment.isRemoving()) {
663-
const pfm = fragment.getParentFragmentManager();
681+
const pfm = _getParentFragmentManagerFromFragment(fragment);
664682
if (pfm && !pfm.isDestroyed()) {
665683
try {
666684
if (pfm.isStateSaved()) {

0 commit comments

Comments
 (0)