Skip to content

Commit d420159

Browse files
committed
feat(bottom-navigation): iosCustomPositioning to allow positioning within layouts
1 parent a3cced3 commit d420159

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

src/bottom-navigation/index.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ export class BottomNavigation extends TabNavigationBase {
6666
* Raised when the selected index changes.
6767
*/
6868
on(event: 'selectedIndexChanged', callback: (args: SelectedIndexChangedEventData) => void, thisArg?: any);
69+
70+
71+
// parameter to allow the bottom-navigation to be positioned correcly within layouts and thus not be full size
72+
// be careful it will then be influenced by safeArea. Default is false
73+
iosCustomPositioning: boolean;
6974
}
7075

7176
export const itemsProperty: Property<BottomNavigation, TabContentItem[]>;

src/bottom-navigation/index.ios.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { TabStrip } from '@nativescript-community/ui-material-core/tab-navigatio
55
import { TabStripItem } from '@nativescript-community/ui-material-core/tab-navigation-base/tab-strip-item';
66
// Types
77
// Requires
8-
import { CSSType, Color, Device, Font, Frame, IOSHelper, ImageSource, Utils, View, getIconSpecSize } from '@nativescript/core';
8+
import { CSSType, Color, Device, Font, Frame, IOSHelper, ImageSource, Property, Utils, View, booleanConverter, getIconSpecSize } from '@nativescript/core';
99
import { TextTransform, getTransformedText } from '@nativescript/core/ui/text-base';
1010
import { iOSNativeHelper } from '@nativescript/core/utils';
1111
export { TabContentItem, TabStrip, TabStripItem };
@@ -261,6 +261,13 @@ function updateTitleAndIconPositions(tabStripItem: TabStripItem, tabBarItem: UIT
261261
}
262262
}
263263

264+
export const iosCustomPositioningProperty = new Property<BottomNavigation, boolean>({
265+
name: 'iosCustomPositioning',
266+
defaultValue: false,
267+
268+
valueConverter: booleanConverter
269+
});
270+
264271
@CSSType('BottomNavigation')
265272
export class BottomNavigation extends TabNavigationBase {
266273
public viewController: UITabBarControllerImpl;
@@ -271,10 +278,10 @@ export class BottomNavigation extends TabNavigationBase {
271278
private _iconsCache = {};
272279
private _selectedItemColor: Color;
273280
private _unSelectedItemColor: Color;
281+
public iosCustomPositioning: boolean;
274282

275283
constructor() {
276284
super();
277-
278285
this.viewController = this._ios = UITabBarControllerImpl.initWithOwner(new WeakRef(this));
279286
this.nativeViewProtected = this._ios.view;
280287
}
@@ -326,11 +333,15 @@ export class BottomNavigation extends TabNavigationBase {
326333
}
327334

328335
public layoutNativeView(left: number, top: number, right: number, bottom: number): void {
329-
//
336+
if (this.iosCustomPositioning) {
337+
super.layoutNativeView(left, top, right, bottom);
338+
}
330339
}
331340

332341
public _setNativeViewFrame(nativeView: UIView, frame: CGRect) {
333-
//
342+
if (this.iosCustomPositioning) {
343+
super._setNativeViewFrame(nativeView, frame);
344+
}
334345
}
335346

336347
public onSelectedIndexChanged(oldIndex: number, newIndex: number): void {
@@ -819,3 +830,4 @@ export class BottomNavigation extends TabNavigationBase {
819830
}
820831
}
821832
}
833+
iosCustomPositioningProperty.register(BottomNavigation);

0 commit comments

Comments
 (0)