Skip to content

Commit b3d9624

Browse files
committed
fix(tabs): ios allow custom positioning with iosCustomPositioning
1 parent d47fffd commit b3d9624

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
lines changed

src/bottom-navigation/index.d.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ export class BottomNavigation extends TabNavigationBase {
4444
*/
4545
selectedIndex: number;
4646

47+
/**
48+
* Allow custom positioning of Tabs within another view
49+
*/
50+
public iosCustomPositioning: boolean;
51+
4752
/**
4853
* Gets the native [android widget](http://developer.android.com/reference/android/support/v4/view/ViewPager.html) that represents the user interface for this component. Valid only when running on Android OS.
4954
*/
@@ -59,7 +64,7 @@ export class BottomNavigation extends TabNavigationBase {
5964
*/
6065
public static selectedIndexChangedEvent: string;
6166

62-
/**
67+
/**
6368
* @hidden
6469
* A basic method signature to hook an event listener (shortcut alias to the addEventListener method).
6570
* @param eventNames - String corresponding to events (e.g. "propertyChange"). Optionally could be used more events separated by `,` (e.g. "propertyChange", "change").
@@ -73,7 +78,6 @@ export class BottomNavigation extends TabNavigationBase {
7378
*/
7479
on(event: 'selectedIndexChanged', callback: (args: SelectedIndexChangedEventData) => void, thisArg?: any);
7580

76-
7781
// parameter to allow the bottom-navigation to be positioned correcly within layouts and thus not be full size
7882
// be careful it will then be influenced by safeArea. Default is false
7983
iosCustomPositioning: boolean;

src/tabs/tabs.d.ts

+5
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ export class Tabs extends TabNavigationBase {
4444
*/
4545
tabsPosition: 'top' | 'bottom';
4646

47+
/**
48+
* Allow custom positioning of Tabs within another view
49+
*/
50+
public iosCustomPositioning: boolean;
51+
4752
/**
4853
* Gets or set the MDCTabBarAlignment of the tab bar icons in iOS. Defaults to "justified"
4954
* Valid values are:

src/tabs/tabs.ios.ts

+16-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { themer } from '@nativescript-community/ui-material-core';
2-
import { Color, Device, Font, Frame, IOSHelper, ImageSource, Trace, Utils, View, ViewBase } from '@nativescript/core';
2+
import { Color, Device, Font, Frame, IOSHelper, ImageSource, Property, Trace, Utils, View, ViewBase, booleanConverter } from '@nativescript/core';
33
import { TabsBase, swipeEnabledProperty } from './tabs-common';
44

55
import { getIconSpecSize, itemsProperty, selectedIndexProperty, tabStripProperty } from '@nativescript-community/ui-material-core/tab-navigation-base/tab-navigation-base';
@@ -424,7 +424,7 @@ function updateBackgroundPositions(tabStrip: TabStrip, tabStripItem: TabStripIte
424424
}
425425
let bgView = (tabStripItem as any).bgView;
426426
const index = tabStripItem._index;
427-
const width = tabStrip.nativeView.frame.size.width / (tabStrip.items.filter(s=>s._index!== undefined).length);
427+
const width = tabStrip.nativeView.frame.size.width / tabStrip.items.filter((s) => s._index !== undefined).length;
428428
const frame = CGRectMake(width * index, 0, width, tabStrip.nativeView.frame.size.width);
429429
if (!bgView) {
430430
bgView = UIView.alloc().initWithFrame(frame);
@@ -466,6 +466,12 @@ function updateTitleAndIconPositions(tabStripItem: TabStripItem, tabBarItem: UIT
466466
}
467467
}
468468

469+
export const iosCustomPositioningProperty = new Property<Tabs, boolean>({
470+
name: 'iosCustomPositioning',
471+
defaultValue: false,
472+
473+
valueConverter: booleanConverter
474+
});
469475
export class Tabs extends TabsBase {
470476
public nativeViewProtected: UIView;
471477
public selectedIndex: number;
@@ -494,6 +500,7 @@ export class Tabs extends TabsBase {
494500
public _animateNextChange = true;
495501
private _selectionIndicatorColor: Color;
496502
private _rippleColor: Color;
503+
public iosCustomPositioning: boolean;
497504

498505
constructor() {
499506
super();
@@ -548,11 +555,15 @@ export class Tabs extends TabsBase {
548555
}
549556

550557
public layoutNativeView(left: number, top: number, right: number, bottom: number): void {
551-
//
558+
if (this.iosCustomPositioning) {
559+
super.layoutNativeView(left, top, right, bottom);
560+
}
552561
}
553562

554563
public _setNativeViewFrame(nativeView: UIView, frame: CGRect) {
555-
//
564+
if (this.iosCustomPositioning) {
565+
super._setNativeViewFrame(nativeView, frame);
566+
}
556567
}
557568

558569
public onSelectedIndexChanged(oldIndex: number, newIndex: number): void {
@@ -1295,3 +1306,4 @@ export class Tabs extends TabsBase {
12951306
}
12961307
}
12971308
}
1309+
iosCustomPositioningProperty.register(Tabs);

0 commit comments

Comments
 (0)