@nativescript-community/ui-material-bottom-navigation 6.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.ios.js ADDED
@@ -0,0 +1,636 @@
1
+ import { TabContentItem } from '@nativescript-community/ui-material-core/tab-navigation-base/tab-content-item';
2
+ import { TabNavigationBase, getIconSpecSize, itemsProperty, selectedIndexProperty, tabStripProperty } from '@nativescript-community/ui-material-core/tab-navigation-base/tab-navigation-base';
3
+ import { TabStrip } from '@nativescript-community/ui-material-core/tab-navigation-base/tab-strip';
4
+ import { TabStripItem } from '@nativescript-community/ui-material-core/tab-navigation-base/tab-strip-item';
5
+ import { CSSType, Color, Device, Font, Frame, IOSHelper, ImageSource, Property, Utils, View, booleanConverter } from '@nativescript/core';
6
+ import { getTransformedText } from '@nativescript/core/ui/text-base';
7
+ import { iOSNativeHelper } from '@nativescript/core/utils';
8
+ export { TabContentItem, TabStrip, TabStripItem };
9
+ const maxTabsCount = 5;
10
+ const majorVersion = iOSNativeHelper.MajorVersion;
11
+ const isPhone = Device.deviceType === 'Phone';
12
+ var UITabBarControllerImpl = /** @class */ (function (_super) {
13
+ __extends(UITabBarControllerImpl, _super);
14
+ function UITabBarControllerImpl() {
15
+ return _super !== null && _super.apply(this, arguments) || this;
16
+ }
17
+ UITabBarControllerImpl.initWithOwner = function (owner) {
18
+ var handler = UITabBarControllerImpl.alloc().init();
19
+ handler._owner = owner;
20
+ return handler;
21
+ };
22
+ // TODO
23
+ // @profile
24
+ UITabBarControllerImpl.prototype.viewWillAppear = function (animated) {
25
+ _super.prototype.viewWillAppear.call(this, animated);
26
+ var owner = this._owner.get();
27
+ if (!owner) {
28
+ return;
29
+ }
30
+ // Unify translucent and opaque bars layout
31
+ this.extendedLayoutIncludesOpaqueBars = true;
32
+ IOSHelper.updateAutoAdjustScrollInsets(this, owner);
33
+ if (!owner.parent) {
34
+ owner.callLoaded();
35
+ }
36
+ };
37
+ // TODO
38
+ // @profile
39
+ UITabBarControllerImpl.prototype.viewDidDisappear = function (animated) {
40
+ _super.prototype.viewDidDisappear.call(this, animated);
41
+ var owner = this._owner.get();
42
+ if (owner && !owner.parent && owner.isLoaded && !this.presentedViewController) {
43
+ owner.callUnloaded();
44
+ }
45
+ };
46
+ UITabBarControllerImpl.prototype.viewWillTransitionToSizeWithTransitionCoordinator = function (size, coordinator) {
47
+ var _this = this;
48
+ _super.prototype.viewWillTransitionToSizeWithTransitionCoordinator.call(this, size, coordinator);
49
+ coordinator.animateAlongsideTransitionCompletion(function () {
50
+ var owner = _this._owner.get();
51
+ if (owner && owner.tabStrip && owner.tabStrip.items) {
52
+ var tabStrip_1 = owner.tabStrip;
53
+ tabStrip_1.items.forEach(function (tabStripItem) {
54
+ updateBackgroundPositions(tabStrip_1, tabStripItem);
55
+ var index = tabStripItem._index;
56
+ var tabBarItemController = _this.viewControllers[index];
57
+ updateTitleAndIconPositions(tabStripItem, tabBarItemController.tabBarItem, tabBarItemController);
58
+ });
59
+ }
60
+ }, null);
61
+ };
62
+ // Mind implementation for other controllers
63
+ UITabBarControllerImpl.prototype.traitCollectionDidChange = function (previousTraitCollection) {
64
+ _super.prototype.traitCollectionDidChange.call(this, previousTraitCollection);
65
+ if (majorVersion >= 13) {
66
+ var owner = this._owner.get();
67
+ if (owner &&
68
+ this.traitCollection.hasDifferentColorAppearanceComparedToTraitCollection &&
69
+ this.traitCollection.hasDifferentColorAppearanceComparedToTraitCollection(previousTraitCollection)) {
70
+ owner.notify({
71
+ eventName: IOSHelper.traitCollectionColorAppearanceChangedEvent,
72
+ object: owner
73
+ });
74
+ }
75
+ }
76
+ };
77
+ return UITabBarControllerImpl;
78
+ }(UITabBarController));
79
+ var UITabBarControllerDelegateImpl = /** @class */ (function (_super) {
80
+ __extends(UITabBarControllerDelegateImpl, _super);
81
+ function UITabBarControllerDelegateImpl() {
82
+ return _super !== null && _super.apply(this, arguments) || this;
83
+ }
84
+ UITabBarControllerDelegateImpl.initWithOwner = function (owner) {
85
+ var delegate = UITabBarControllerDelegateImpl.alloc().init();
86
+ delegate._owner = owner;
87
+ return delegate;
88
+ };
89
+ UITabBarControllerDelegateImpl.prototype.tabBarControllerShouldSelectViewController = function (tabBarController, viewController) {
90
+ // TODO
91
+ // if (Trace.isEnabled()) {
92
+ // Trace.write("TabView.delegate.SHOULD_select(" + tabBarController + ", " + viewController + ");", Trace.categories.Debug);
93
+ // }
94
+ var owner = this._owner.get();
95
+ if (owner) {
96
+ // "< More" cannot be visible after clicking on the main tab bar buttons.
97
+ var backToMoreWillBeVisible = false;
98
+ owner._handleTwoNavigationBars(backToMoreWillBeVisible);
99
+ if (tabBarController.viewControllers) {
100
+ var position = tabBarController.viewControllers.indexOfObject(viewController);
101
+ if (position !== NSNotFound) {
102
+ var tabStrip = owner.tabStrip;
103
+ var tabStripItems = tabStrip && tabStrip.items;
104
+ if (tabStripItems && tabStripItems[position]) {
105
+ tabStripItems[position]._emit(TabStripItem.tapEvent);
106
+ tabStrip.notify({
107
+ eventName: TabStrip.itemTapEvent,
108
+ object: tabStrip,
109
+ index: position
110
+ });
111
+ }
112
+ }
113
+ }
114
+ }
115
+ if (tabBarController.selectedViewController === viewController) {
116
+ return false;
117
+ }
118
+ tabBarController._willSelectViewController = viewController;
119
+ return true;
120
+ };
121
+ UITabBarControllerDelegateImpl.prototype.tabBarControllerDidSelectViewController = function (tabBarController, viewController) {
122
+ // TODO
123
+ // if (Trace.isEnabled()) {
124
+ // Trace.write("TabView.delegate.DID_select(" + tabBarController + ", " + viewController + ");", Trace.categories.Debug);
125
+ // }
126
+ var owner = this._owner.get();
127
+ if (owner) {
128
+ owner._onViewControllerShown(viewController);
129
+ }
130
+ tabBarController._willSelectViewController = undefined;
131
+ };
132
+ UITabBarControllerDelegateImpl.ObjCProtocols = [UITabBarControllerDelegate];
133
+ return UITabBarControllerDelegateImpl;
134
+ }(NSObject));
135
+ var UINavigationControllerDelegateImpl = /** @class */ (function (_super) {
136
+ __extends(UINavigationControllerDelegateImpl, _super);
137
+ function UINavigationControllerDelegateImpl() {
138
+ return _super !== null && _super.apply(this, arguments) || this;
139
+ }
140
+ UINavigationControllerDelegateImpl.initWithOwner = function (owner) {
141
+ var delegate = UINavigationControllerDelegateImpl.alloc().init();
142
+ delegate._owner = owner;
143
+ return delegate;
144
+ };
145
+ UINavigationControllerDelegateImpl.prototype.navigationControllerWillShowViewControllerAnimated = function (navigationController, viewController, animated) {
146
+ // TODO
147
+ // if (Trace.isEnabled()) {
148
+ // Trace.write("TabView.moreNavigationController.WILL_show(" + navigationController + ", " + viewController + ", " + animated + ");", Trace.categories.Debug);
149
+ // }
150
+ var owner = this._owner.get();
151
+ if (owner) {
152
+ // If viewController is one of our tab item controllers, then "< More" will be visible shortly.
153
+ // Otherwise viewController is the UIMoreListController which shows the list of all tabs beyond the 4th tab.
154
+ var backToMoreWillBeVisible = owner._ios.viewControllers.containsObject(viewController);
155
+ owner._handleTwoNavigationBars(backToMoreWillBeVisible);
156
+ }
157
+ };
158
+ UINavigationControllerDelegateImpl.prototype.navigationControllerDidShowViewControllerAnimated = function (navigationController, viewController, animated) {
159
+ // TODO
160
+ // if (Trace.isEnabled()) {
161
+ // Trace.write("TabView.moreNavigationController.DID_show(" + navigationController + ", " + viewController + ", " + animated + ");", Trace.categories.Debug);
162
+ // }
163
+ // We don't need Edit button in More screen.
164
+ navigationController.navigationBar.topItem.rightBarButtonItem = null;
165
+ var owner = this._owner.get();
166
+ if (owner) {
167
+ owner._onViewControllerShown(viewController);
168
+ }
169
+ };
170
+ UINavigationControllerDelegateImpl.ObjCProtocols = [UINavigationControllerDelegate];
171
+ return UINavigationControllerDelegateImpl;
172
+ }(NSObject));
173
+ function updateBackgroundPositions(tabStrip, tabStripItem) {
174
+ let bgView = tabStripItem.bgView;
175
+ const index = tabStripItem._index;
176
+ const width = tabStrip.nativeView.frame.size.width / tabStrip.items.length;
177
+ const frame = CGRectMake(width * index, 0, width, tabStrip.nativeView.frame.size.width);
178
+ if (!bgView) {
179
+ bgView = UIView.alloc().initWithFrame(frame);
180
+ tabStrip.nativeView.insertSubviewAtIndex(bgView, 0);
181
+ tabStripItem.bgView = bgView;
182
+ }
183
+ else {
184
+ bgView.frame = frame;
185
+ }
186
+ const backgroundColor = tabStripItem.style.backgroundColor;
187
+ bgView.backgroundColor = backgroundColor instanceof Color ? backgroundColor.ios : backgroundColor;
188
+ }
189
+ function updateTitleAndIconPositions(tabStripItem, tabBarItem, controller) {
190
+ if (!tabStripItem || !tabBarItem) {
191
+ return;
192
+ }
193
+ const orientation = controller.interfaceOrientation;
194
+ const isPortrait = orientation !== 4 && orientation !== 3;
195
+ const isIconAboveTitle = majorVersion < 11 || (isPhone && isPortrait);
196
+ if (!tabStripItem.iconSource) {
197
+ if (isIconAboveTitle) {
198
+ tabBarItem.titlePositionAdjustment = {
199
+ horizontal: 0,
200
+ vertical: -20
201
+ };
202
+ }
203
+ else {
204
+ tabBarItem.titlePositionAdjustment = { horizontal: 0, vertical: 0 };
205
+ }
206
+ }
207
+ if (!tabStripItem.title) {
208
+ if (isIconAboveTitle) {
209
+ tabBarItem.imageInsets = new UIEdgeInsets({
210
+ top: 6,
211
+ left: 0,
212
+ bottom: -6,
213
+ right: 0
214
+ });
215
+ }
216
+ else {
217
+ tabBarItem.imageInsets = new UIEdgeInsets({
218
+ top: 0,
219
+ left: 0,
220
+ bottom: 0,
221
+ right: 0
222
+ });
223
+ }
224
+ }
225
+ }
226
+ export const iosCustomPositioningProperty = new Property({
227
+ name: 'iosCustomPositioning',
228
+ defaultValue: false,
229
+ valueConverter: booleanConverter
230
+ });
231
+ let BottomNavigation = class BottomNavigation extends TabNavigationBase {
232
+ constructor() {
233
+ super();
234
+ this._iconsCache = {};
235
+ this.viewController = this._ios = UITabBarControllerImpl.initWithOwner(new WeakRef(this));
236
+ this.nativeViewProtected = this._ios.view;
237
+ }
238
+ initNativeView() {
239
+ super.initNativeView();
240
+ this._delegate = UITabBarControllerDelegateImpl.initWithOwner(new WeakRef(this));
241
+ this._moreNavigationControllerDelegate = UINavigationControllerDelegateImpl.initWithOwner(new WeakRef(this));
242
+ if (!this.tabStrip) {
243
+ this.viewController.tabBar.hidden = true;
244
+ }
245
+ }
246
+ disposeNativeView() {
247
+ this._delegate = null;
248
+ this._moreNavigationControllerDelegate = null;
249
+ super.disposeNativeView();
250
+ }
251
+ onLoaded() {
252
+ super.onLoaded();
253
+ this.setViewControllers(this.items);
254
+ const selectedIndex = this.selectedIndex;
255
+ const selectedView = this.items && this.items[selectedIndex] && this.items[selectedIndex].content;
256
+ if (selectedView instanceof Frame) {
257
+ selectedView._pushInFrameStackRecursive();
258
+ }
259
+ this._ios.delegate = this._delegate;
260
+ this.onSelectedIndexChanged(selectedIndex, selectedIndex);
261
+ }
262
+ onUnloaded() {
263
+ this._ios.delegate = null;
264
+ this._ios.moreNavigationController.delegate = null;
265
+ super.onUnloaded();
266
+ this.items.forEach((item, i) => {
267
+ item.unloadView(item.content);
268
+ });
269
+ }
270
+ get ios() {
271
+ return this._ios;
272
+ }
273
+ layoutNativeView(left, top, right, bottom) {
274
+ if (this.iosCustomPositioning) {
275
+ super.layoutNativeView(left, top, right, bottom);
276
+ }
277
+ }
278
+ _setNativeViewFrame(nativeView, frame) {
279
+ if (this.iosCustomPositioning) {
280
+ super._setNativeViewFrame(nativeView, frame);
281
+ }
282
+ }
283
+ onSelectedIndexChanged(oldIndex, newIndex) {
284
+ const items = this.items;
285
+ if (!items) {
286
+ return;
287
+ }
288
+ if (this.unloadOnTabChange) {
289
+ const oldItem = items[oldIndex];
290
+ if (oldItem) {
291
+ oldItem.canBeLoaded = false;
292
+ oldItem.unloadView(oldItem.content);
293
+ }
294
+ }
295
+ const newItem = items[newIndex];
296
+ if (newItem && this.isLoaded) {
297
+ const selectedView = items[newIndex].content;
298
+ if (selectedView instanceof Frame) {
299
+ selectedView._pushInFrameStackRecursive();
300
+ }
301
+ newItem.canBeLoaded = true;
302
+ newItem.loadView(newItem.content);
303
+ }
304
+ const tabStripItems = this.tabStrip && this.tabStrip.items;
305
+ if (tabStripItems) {
306
+ if (tabStripItems[newIndex]) {
307
+ tabStripItems[newIndex]._emit(TabStripItem.selectEvent);
308
+ }
309
+ if (oldIndex !== newIndex && tabStripItems[oldIndex]) {
310
+ tabStripItems[oldIndex]._emit(TabStripItem.unselectEvent);
311
+ }
312
+ }
313
+ super.onSelectedIndexChanged(oldIndex, newIndex);
314
+ }
315
+ getTabBarBackgroundColor() {
316
+ return this._ios.tabBar.barTintColor;
317
+ }
318
+ setTabBarBackgroundColor(value) {
319
+ this._ios.tabBar.barTintColor = value instanceof Color ? value.ios : value;
320
+ this.updateAllItemsColors();
321
+ }
322
+ setTabBarItemTitle(tabStripItem, value) {
323
+ tabStripItem.nativeView.title = value;
324
+ }
325
+ setTabBarItemBackgroundColor(tabStripItem, value) {
326
+ if (!this.tabStrip || !tabStripItem) {
327
+ return;
328
+ }
329
+ updateBackgroundPositions(this.tabStrip, tabStripItem);
330
+ }
331
+ setTabBarItemColor(tabStripItem, value) {
332
+ this.setViewAttributes(tabStripItem.nativeView, tabStripItem.label);
333
+ }
334
+ setItemColors() {
335
+ if (this._selectedItemColor) {
336
+ this.viewController.tabBar.selectedImageTintColor = this._selectedItemColor.ios;
337
+ }
338
+ if (this._unSelectedItemColor) {
339
+ this.viewController.tabBar.unselectedItemTintColor = this._unSelectedItemColor.ios;
340
+ }
341
+ }
342
+ setIconColor(tabStripItem, forceReload = false) {
343
+ if (forceReload || (!this._unSelectedItemColor && !this._selectedItemColor)) {
344
+ const tabStripColor = this.selectedIndex === tabStripItem._index ? this._selectedItemColor : this._unSelectedItemColor;
345
+ const image = this.getIcon(tabStripItem, tabStripColor);
346
+ tabStripItem.nativeView.image = image;
347
+ tabStripItem.nativeView.selectedImage = image;
348
+ }
349
+ }
350
+ setTabBarIconColor(tabStripItem, value) {
351
+ this.setIconColor(tabStripItem);
352
+ }
353
+ setTabBarIconSource(tabStripItem, value) {
354
+ this.updateItemColors(tabStripItem);
355
+ }
356
+ setTabBarItemFontInternal(tabStripItem, value) {
357
+ this.setViewAttributes(tabStripItem.nativeView, tabStripItem.label);
358
+ }
359
+ setTabBarItemTextTransform(tabStripItem, value) {
360
+ tabStripItem.nativeView.title = getTransformedText(tabStripItem.label.text, value);
361
+ }
362
+ getTabBarHighlightColor() {
363
+ return this._ios.tabBar.tintColor;
364
+ }
365
+ setTabBarHighlightColor(value) {
366
+ this._ios.tabBar.tintColor = value instanceof Color ? value.ios : value;
367
+ }
368
+ getTabBarSelectedItemColor() {
369
+ return this._selectedItemColor;
370
+ }
371
+ setTabBarSelectedItemColor(value) {
372
+ this._selectedItemColor = value;
373
+ this.updateAllItemsColors();
374
+ }
375
+ getTabBarUnSelectedItemColor() {
376
+ return this._unSelectedItemColor;
377
+ }
378
+ setTabBarUnSelectedItemColor(value) {
379
+ this._unSelectedItemColor = value;
380
+ this.updateAllItemsColors();
381
+ }
382
+ onMeasure(widthMeasureSpec, heightMeasureSpec) {
383
+ const width = Utils.layout.getMeasureSpecSize(widthMeasureSpec);
384
+ const widthMode = Utils.layout.getMeasureSpecMode(widthMeasureSpec);
385
+ const height = Utils.layout.getMeasureSpecSize(heightMeasureSpec);
386
+ const heightMode = Utils.layout.getMeasureSpecMode(heightMeasureSpec);
387
+ const widthAndState = View.resolveSizeAndState(width, width, widthMode, 0);
388
+ const heightAndState = View.resolveSizeAndState(height, height, heightMode, 0);
389
+ this.setMeasuredDimension(widthAndState, heightAndState);
390
+ }
391
+ _onViewControllerShown(viewController) {
392
+ if (this._ios.viewControllers && this._ios.viewControllers.containsObject(viewController)) {
393
+ this.selectedIndex = this._ios.viewControllers.indexOfObject(viewController);
394
+ }
395
+ else {
396
+ }
397
+ }
398
+ _handleTwoNavigationBars(backToMoreWillBeVisible) {
399
+ const page = this.page || this._selectedView.page || this._selectedView.currentPage;
400
+ if (!page || !page.frame) {
401
+ return;
402
+ }
403
+ const actionBarVisible = page.frame._getNavBarVisible(page);
404
+ if (backToMoreWillBeVisible && actionBarVisible) {
405
+ page.frame.ios._disableNavBarAnimation = true;
406
+ page.actionBarHidden = true;
407
+ page.frame.ios._disableNavBarAnimation = false;
408
+ this._actionBarHiddenByTabView = true;
409
+ return;
410
+ }
411
+ if (!backToMoreWillBeVisible && this._actionBarHiddenByTabView) {
412
+ page.frame.ios._disableNavBarAnimation = true;
413
+ page.actionBarHidden = false;
414
+ page.frame.ios._disableNavBarAnimation = false;
415
+ this._actionBarHiddenByTabView = undefined;
416
+ return;
417
+ }
418
+ }
419
+ getViewController(item) {
420
+ let newController = item.content ? item.content.viewController : null;
421
+ if (newController) {
422
+ item.setViewController(newController, newController.view);
423
+ return newController;
424
+ }
425
+ if (item.content.ios instanceof UIViewController) {
426
+ newController = item.content.ios;
427
+ item.setViewController(newController, newController.view);
428
+ }
429
+ else if (item.content.ios && item.content.ios.controller instanceof UIViewController) {
430
+ newController = item.content.ios.controller;
431
+ item.setViewController(newController, newController.view);
432
+ }
433
+ else {
434
+ newController = IOSHelper.UILayoutViewController.initWithOwner(new WeakRef(item.content));
435
+ newController.view.addSubview(item.content.nativeViewProtected);
436
+ item.content.viewController = newController;
437
+ item.setViewController(newController, item.content.nativeViewProtected);
438
+ }
439
+ return newController;
440
+ }
441
+ setViewControllers(items) {
442
+ const length = items ? items.length : 0;
443
+ if (length === 0) {
444
+ this._ios.viewControllers = null;
445
+ return;
446
+ }
447
+ items = items.slice(0, maxTabsCount);
448
+ const controllers = NSMutableArray.alloc().initWithCapacity(length);
449
+ if (this.tabStrip) {
450
+ this.tabStrip.setNativeView(this._ios.tabBar);
451
+ }
452
+ items.forEach((item, i) => {
453
+ const controller = this.getViewController(item);
454
+ if (this.tabStrip && this.tabStrip.items && this.tabStrip.items[i]) {
455
+ const tabStripItem = this.tabStrip.items[i];
456
+ const tabBarItem = this.createTabBarItem(tabStripItem, i);
457
+ updateTitleAndIconPositions(tabStripItem, tabBarItem, controller);
458
+ this.setViewAttributes(tabBarItem, tabStripItem.label);
459
+ controller.tabBarItem = tabBarItem;
460
+ tabStripItem._index = i;
461
+ tabStripItem.setNativeView(tabBarItem);
462
+ }
463
+ controllers.addObject(controller);
464
+ });
465
+ this.setItemImages();
466
+ this._ios.viewControllers = controllers;
467
+ this._ios.customizableViewControllers = null;
468
+ this._ios.moreNavigationController.delegate = this._moreNavigationControllerDelegate;
469
+ }
470
+ setItemImages() {
471
+ if (this._selectedItemColor || this._unSelectedItemColor) {
472
+ if (this.tabStrip && this.tabStrip.items) {
473
+ this.tabStrip.items.forEach((item) => {
474
+ if (this._unSelectedItemColor && item.nativeView) {
475
+ item.nativeView.image = this.getIcon(item, this._unSelectedItemColor);
476
+ item.nativeView.tintColor = this._unSelectedItemColor;
477
+ }
478
+ if (this._selectedItemColor && item.nativeView) {
479
+ item.nativeView.selectedImage = this.getIcon(item, this._selectedItemColor);
480
+ item.nativeView.tintColor = this._selectedItemColor;
481
+ }
482
+ });
483
+ }
484
+ }
485
+ }
486
+ updateAllItemsColors() {
487
+ this.setItemColors();
488
+ if (this.tabStrip && this.tabStrip.items) {
489
+ this.tabStrip.items.forEach((tabStripItem) => {
490
+ this.updateItemColors(tabStripItem);
491
+ });
492
+ }
493
+ }
494
+ updateItemColors(tabStripItem) {
495
+ updateBackgroundPositions(this.tabStrip, tabStripItem);
496
+ this.setIconColor(tabStripItem, true);
497
+ }
498
+ createTabBarItem(item, index) {
499
+ let image;
500
+ let title;
501
+ if (item.isLoaded) {
502
+ image = this.getIcon(item);
503
+ title = item.label.text;
504
+ const textTransform = item.label.style.textTransform;
505
+ if (textTransform) {
506
+ title = getTransformedText(title, textTransform);
507
+ }
508
+ }
509
+ return UITabBarItem.alloc().initWithTitleImageTag(title, image, index);
510
+ }
511
+ getIconRenderingMode() {
512
+ switch (this.tabStrip && this.tabStrip.iosIconRenderingMode) {
513
+ case 'alwaysOriginal':
514
+ return 1;
515
+ case 'alwaysTemplate':
516
+ return 2;
517
+ case 'automatic':
518
+ default:
519
+ return 0;
520
+ }
521
+ }
522
+ getIcon(tabStripItem, color) {
523
+ const iconSource = tabStripItem.image && tabStripItem.image.src;
524
+ if (!iconSource) {
525
+ return null;
526
+ }
527
+ const target = tabStripItem.image;
528
+ const font = target.style.fontInternal || Font.default;
529
+ if (!color) {
530
+ color = target.style.color;
531
+ }
532
+ const iconTag = [iconSource, font.fontStyle, font.fontWeight, font.fontSize, font.fontFamily, color].join(';');
533
+ let isFontIcon = false;
534
+ let image = this._iconsCache[iconTag];
535
+ if (!image) {
536
+ let is;
537
+ if (Utils.isFontIconURI(iconSource)) {
538
+ isFontIcon = true;
539
+ const fontIconCode = iconSource.split('//')[1];
540
+ is = ImageSource.fromFontIconCodeSync(fontIconCode, font, color);
541
+ }
542
+ else {
543
+ is = ImageSource.fromFileOrResourceSync(iconSource);
544
+ }
545
+ if (is && is.ios) {
546
+ image = is.ios;
547
+ if (this.tabStrip && this.tabStrip.isIconSizeFixed) {
548
+ image = this.getFixedSizeIcon(image);
549
+ }
550
+ let renderingMode = 1;
551
+ if (!isFontIcon) {
552
+ renderingMode = this.getIconRenderingMode();
553
+ }
554
+ const originalRenderedImage = image.imageWithRenderingMode(renderingMode);
555
+ this._iconsCache[iconTag] = originalRenderedImage;
556
+ image = originalRenderedImage;
557
+ }
558
+ else {
559
+ }
560
+ }
561
+ return image;
562
+ }
563
+ getFixedSizeIcon(image) {
564
+ const inWidth = image.size.width;
565
+ const inHeight = image.size.height;
566
+ const iconSpecSize = getIconSpecSize({
567
+ width: inWidth,
568
+ height: inHeight
569
+ });
570
+ const widthPts = iconSpecSize.width;
571
+ const heightPts = iconSpecSize.height;
572
+ UIGraphicsBeginImageContextWithOptions({ width: widthPts, height: heightPts }, false, Utils.layout.getDisplayDensity());
573
+ image.drawInRect(CGRectMake(0, 0, widthPts, heightPts));
574
+ const resultImage = UIGraphicsGetImageFromCurrentImageContext();
575
+ UIGraphicsEndImageContext();
576
+ return resultImage;
577
+ }
578
+ [selectedIndexProperty.setNative](value) {
579
+ if (value > -1) {
580
+ this._ios._willSelectViewController = this._ios.viewControllers[value];
581
+ this._ios.selectedIndex = value;
582
+ }
583
+ }
584
+ [itemsProperty.getDefault]() {
585
+ return null;
586
+ }
587
+ [itemsProperty.setNative](value) {
588
+ if (value) {
589
+ value.forEach((item, i) => {
590
+ item.index = i;
591
+ });
592
+ }
593
+ this.setViewControllers(value);
594
+ selectedIndexProperty.coerce(this);
595
+ }
596
+ [tabStripProperty.getDefault]() {
597
+ return null;
598
+ }
599
+ [tabStripProperty.setNative](value) {
600
+ this.setViewControllers(this.items);
601
+ selectedIndexProperty.coerce(this);
602
+ }
603
+ setViewAttributes(item, view) {
604
+ if (!view) {
605
+ return null;
606
+ }
607
+ const defaultTabItemFontSize = 10;
608
+ const tabItemFontSize = view.style.fontSize || defaultTabItemFontSize;
609
+ const font = (view.style.fontInternal || Font.default).getUIFont(UIFont.systemFontOfSize(tabItemFontSize));
610
+ const tabItemTextColor = view.style.color;
611
+ const textColor = tabItemTextColor instanceof Color ? tabItemTextColor.ios : null;
612
+ const attributes = { [NSFontAttributeName]: font };
613
+ if (!this._selectedItemColor && !this._unSelectedItemColor) {
614
+ if (textColor) {
615
+ attributes[UITextAttributeTextColor] = textColor;
616
+ attributes[NSForegroundColorAttributeName] = textColor;
617
+ }
618
+ }
619
+ else {
620
+ this.viewController.tabBar.unselectedItemTintColor = this._unSelectedItemColor && this._unSelectedItemColor.ios;
621
+ this.viewController.tabBar.selectedImageTintColor = this._selectedItemColor && this._selectedItemColor.ios;
622
+ }
623
+ item.setTitleTextAttributesForState(attributes, 4);
624
+ item.setTitleTextAttributesForState(attributes, 0);
625
+ if (!this.viewController.tabBar.barTintColor && attributes[UITextAttributeTextColor] && majorVersion > 9) {
626
+ this.viewController.tabBar.unselectedItemTintColor = attributes[UITextAttributeTextColor];
627
+ }
628
+ }
629
+ };
630
+ BottomNavigation = __decorate([
631
+ CSSType('BottomNavigation'),
632
+ __metadata("design:paramtypes", [])
633
+ ], BottomNavigation);
634
+ export { BottomNavigation };
635
+ iosCustomPositioningProperty.register(BottomNavigation);
636
+ //# sourceMappingURL=index.ios.js.map
package/package.json ADDED
@@ -0,0 +1,56 @@
1
+ {
2
+ "name": "@nativescript-community/ui-material-bottom-navigation",
3
+ "version": "6.0.0",
4
+ "description": "Material Design Bottom Navigation bars allow movement between primary destinations in an app. Tapping on a bottom navigation icon takes you directly to the associated view or refreshes the currently active view.",
5
+ "main": "bottomnavigation",
6
+ "sideEffects": false,
7
+ "typings": "bottomnavigation.d.ts",
8
+ "nativescript": {
9
+ "platforms": {
10
+ "android": "6.2.0",
11
+ "ios": "6.2.0"
12
+ }
13
+ },
14
+ "scripts": {
15
+ "tsc": "../../node_modules/.bin/cpy ../../src/bottom-navigation/index.d.ts ./ && ../../node_modules/.bin/tsc --skipLibCheck -d",
16
+ "tsc-win": "..\\..\\node_modules\\.bin\\cpy ..\\..\\src\\bottom-navigation\\index.d.ts .\\ && ..\\..\\node_modules\\.bin\\tsc --skipLibCheck -d",
17
+ "build": "npm run tsc",
18
+ "build.win": "npm run tsc-win",
19
+ "build.all": "npm run build && npm run build.angular",
20
+ "build.all.win": "npm run build.win && npm run build.angular.win",
21
+ "build.angular": "../../node_modules/.bin/ng-packagr -p ../../src/bottom-navigation/angular/package.json -c ../../src/bottom-navigation/angular/tsconfig.json",
22
+ "build.angular.win": "..\\..\\node_modules\\.bin\\ng-packagr -p ..\\..\\src\\bottom-navigation\\angular\\package.json -c ..\\..\\src\\bottom-navigation\\angular\\tsconfig.json",
23
+ "clean": "../../node_modules/.bin/rimraf ./*.d.ts ./*.js ./*.js.map"
24
+ },
25
+ "keywords": [
26
+ "NativeScript",
27
+ "JavaScript",
28
+ "Typescript",
29
+ "Android",
30
+ "iOS",
31
+ "Henry Chavez",
32
+ "Bytpher",
33
+ "Bottom Navigation",
34
+ "Material Design",
35
+ "Vue",
36
+ "Angular",
37
+ "preview|https://raw.githubusercontent.com/nativescript-community/ui-material-components/master/images/demo-bottom-navigation.png"
38
+ ],
39
+ "author": {
40
+ "name": "Henry Chavez",
41
+ "email": "henry19.chavez@gmail.com"
42
+ },
43
+ "bugs": {
44
+ "url": "https://github.com/nativescript-community/ui-material-components/issues"
45
+ },
46
+ "license": "Apache-2.0",
47
+ "repository": {
48
+ "type": "git",
49
+ "url": "https://github.com/nativescript-community/ui-material-components/tree/master/packages/bottom-navigation"
50
+ },
51
+ "readmeFilename": "README.md",
52
+ "dependencies": {
53
+ "@nativescript-community/ui-material-core": "^6.0.0"
54
+ },
55
+ "gitHead": "f4a17600487dd826a4a581f2ebde8cf6457710ca"
56
+ }
@@ -0,0 +1 @@
1
+ pod 'MaterialComponents/BottomNavigation+Theming'