Skip to content

Commit 6e1e0e8

Browse files
ADjenkovdtopuzov
authored andcommitted
fix(android-tabs): tabstripitem tap does not change tabs (#7468)
1 parent 8756b3d commit 6e1e0e8

1 file changed

Lines changed: 25 additions & 8 deletions

File tree

tns-core-modules/ui/tabs/tabs.ios.ts

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,15 @@ class MDCTabBarDelegateImpl extends NSObject implements MDCTabBarDelegate {
3434
}
3535

3636
public tabBarShouldSelectItem(tabBar: MDCTabBar, item: UITabBarItem): boolean {
37-
return true;
37+
const owner = this._owner.get();
38+
const shouldSelectItem = owner._canSelectItem;
39+
const selectedIndex = owner.tabBarItems.indexOf(item);
40+
41+
if (owner.selectedIndex !== selectedIndex) {
42+
owner._canSelectItem = false;
43+
}
44+
45+
return shouldSelectItem;
3846
}
3947

4048
public tabBarWillSelectItem(tabBar: MDCTabBar, item: UITabBarItem): void {
@@ -53,6 +61,7 @@ class MDCTabBarDelegateImpl extends NSObject implements MDCTabBarDelegate {
5361
class UIPageViewControllerImpl extends UIPageViewController {
5462
tabBar: MDCTabBar;
5563
scrollView: UIScrollView;
64+
tabBarDelegate: MDCTabBarDelegateImpl;
5665

5766
private _owner: WeakRef<Tabs>;
5867

@@ -87,7 +96,7 @@ class UIPageViewControllerImpl extends UIPageViewController {
8796
// UITabBarItem.alloc().initWithTitleImageTag("Test", null, 0),
8897
// ]);
8998

90-
tabBar.delegate = MDCTabBarDelegateImpl.initWithOwner(new WeakRef(owner));
99+
tabBar.delegate = this.tabBarDelegate = MDCTabBarDelegateImpl.initWithOwner(new WeakRef(owner));
91100
tabBar.itemAppearance = MDCTabBarItemAppearance.Titles;
92101
tabBar.tintColor = UIColor.blueColor;
93102
tabBar.barTintColor = UIColor.whiteColor;
@@ -287,7 +296,7 @@ class UIPageViewControllerDataSourceImpl extends NSObject implements UIPageViewC
287296
const owner = this._owner.get();
288297
let selectedIndex = owner.selectedIndex;
289298

290-
if (selectedIndex === 2) {
299+
if (selectedIndex === owner.items.length - 1) {
291300
return null;
292301
}
293302

@@ -352,7 +361,7 @@ class UIPageViewControllerDelegateImpl extends NSObject implements UIPageViewCon
352361
//
353362
}
354363

355-
public pageViewControllerDidFinishAnimatingPreviousViewControllersTransitionCompleted(pageViewController: UIPageViewController, didFinishAnimating: boolean, previousViewControllers: NSArray<UIViewController>, transitionCompleted: boolean): void {
364+
public pageViewControllerDidFinishAnimatingPreviousViewControllersTransitionCompleted(pageViewController: UIPageViewController, didFinishAnimating: boolean, previousViewControllers: NSArray<UIViewController>, transitionCompleted: boolean): void {
356365
if (!transitionCompleted) {
357366
return;
358367
}
@@ -365,8 +374,9 @@ class UIPageViewControllerDelegateImpl extends NSObject implements UIPageViewCon
365374

366375
if (selectedIndex !== nextViewControllerIndex) {
367376
owner.selectedIndex = nextViewControllerIndex;
377+
owner._canSelectItem = true;
368378
}
369-
379+
370380
console.log("test");
371381
//
372382
}
@@ -547,6 +557,7 @@ export class Tabs extends TabsBase {
547557
// public swipeEnabled: boolean;
548558
// public offscreenTabLimit: number;
549559
// public tabsPosition: "top" | "bottom";
560+
public _canSelectItem: boolean;
550561
public isLoaded: boolean;
551562
public viewController: UIPageViewControllerImpl;
552563
public items: TabContentItem[];
@@ -578,6 +589,8 @@ export class Tabs extends TabsBase {
578589
disposeNativeView() {
579590
this._dataSource = null;
580591
this._delegate = null;
592+
this._ios.tabBarDelegate = null;
593+
this._ios.tabBar = null;
581594
// this._moreNavigationControllerDelegate = null;
582595
super.disposeNativeView();
583596
}
@@ -812,7 +825,7 @@ export class Tabs extends TabsBase {
812825

813826
// items.forEach((item, i) => {
814827
// const controller = this.getViewController(item);
815-
828+
816829
// let icon = null;
817830
// let title = "";
818831

@@ -950,6 +963,7 @@ export class Tabs extends TabsBase {
950963
// if (traceEnabled()) {
951964
// traceWrite("TabView._onSelectedIndexPropertyChangedSetNativeValue(" + value + ")", traceCategories.Debug);
952965
// }
966+
const that = this;
953967

954968
if (value > -1) {
955969
const item = this.items[value];
@@ -970,8 +984,11 @@ export class Tabs extends TabsBase {
970984
}
971985

972986
this._currentNativeSelectedIndex = value;
973-
974-
this.viewController.setViewControllersDirectionAnimatedCompletion(controllers, navigationDirection, true, null);
987+
this.viewController.setViewControllersDirectionAnimatedCompletion(controllers, navigationDirection, true, (finished: boolean) => {
988+
if (finished) {
989+
that._canSelectItem = true;
990+
}
991+
});
975992

976993
if (this.tabBarItems && this.tabBarItems.length && this.viewController && this.viewController.tabBar) {
977994
this.viewController.tabBar.setSelectedItemAnimated(this.tabBarItems[value], true);

0 commit comments

Comments
 (0)