@nativescript-community/ui-material-bottom-navigation 7.2.1 → 7.2.4

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,722 @@
1
+ // Types
2
+ import { TabContentItem } from '@nativescript-community/ui-material-core-tabs/tab-content-item';
3
+ import { TabNavigationBase, getIconSpecSize, itemsProperty, selectedIndexProperty, tabStripProperty } from '@nativescript-community/ui-material-core-tabs/tab-navigation-base';
4
+ import { TabsPosition } from '@nativescript-community/ui-material-core-tabs/tab-navigation/index-common';
5
+ import { TabStrip } from '@nativescript-community/ui-material-core-tabs/tab-strip';
6
+ import { TabStripItem } from '@nativescript-community/ui-material-core-tabs/tab-strip-item';
7
+ // Types
8
+ // Requires
9
+ import { CSSType, Color, CoreTypes, Device, Font, Frame, IOSHelper, ImageSource, ImageAsset, Property, Utils, View, booleanConverter } from '@nativescript/core';
10
+ import { getTransformedText } from '@nativescript/core/ui/text-base';
11
+ import { iOSNativeHelper } from '@nativescript/core/utils';
12
+ export { TabContentItem, TabStrip, TabStripItem };
13
+ // TODO:
14
+ // import { profile } from "../../profiling";
15
+ const maxTabsCount = 5;
16
+ const majorVersion = iOSNativeHelper.MajorVersion;
17
+ const isPhone = Device.deviceType === 'Phone';
18
+ var MDTabBarControllerImpl = /** @class */ (function (_super) {
19
+ __extends(MDTabBarControllerImpl, _super);
20
+ function MDTabBarControllerImpl() {
21
+ return _super !== null && _super.apply(this, arguments) || this;
22
+ }
23
+ MDTabBarControllerImpl.initWithOwner = function (owner) {
24
+ var handler = MDTabBarControllerImpl.alloc().init();
25
+ handler._owner = owner;
26
+ return handler;
27
+ };
28
+ // TODO
29
+ // @profile
30
+ MDTabBarControllerImpl.prototype.viewWillAppear = function (animated) {
31
+ _super.prototype.viewWillAppear.call(this, animated);
32
+ var owner = this._owner.get();
33
+ if (!owner) {
34
+ return;
35
+ }
36
+ // Unify translucent and opaque bars layout
37
+ this.extendedLayoutIncludesOpaqueBars = true;
38
+ IOSHelper.updateAutoAdjustScrollInsets(this, owner);
39
+ if (!owner.parent) {
40
+ owner.callLoaded();
41
+ }
42
+ };
43
+ // TODO
44
+ // @profile
45
+ MDTabBarControllerImpl.prototype.viewDidDisappear = function (animated) {
46
+ var _a;
47
+ _super.prototype.viewDidDisappear.call(this, animated);
48
+ var owner = (_a = this._owner) === null || _a === void 0 ? void 0 : _a.get();
49
+ if (owner && !owner.parent && owner.isLoaded && !this.presentedViewController) {
50
+ owner.callUnloaded();
51
+ }
52
+ };
53
+ MDTabBarControllerImpl.prototype.viewWillTransitionToSizeWithTransitionCoordinator = function (size, coordinator) {
54
+ var _this = this;
55
+ _super.prototype.viewWillTransitionToSizeWithTransitionCoordinator.call(this, size, coordinator);
56
+ coordinator.animateAlongsideTransitionCompletion(function () {
57
+ var owner = _this._owner.get();
58
+ if (owner && owner.tabStrip && owner.tabStrip.items) {
59
+ var tabStrip_1 = owner.tabStrip;
60
+ tabStrip_1.items.forEach(function (tabStripItem) {
61
+ updateBackgroundPositions(tabStrip_1, tabStripItem);
62
+ var index = tabStripItem.index;
63
+ var tabBarItemController = _this.viewControllers[index];
64
+ updateTitleAndIconPositions(tabStripItem, tabBarItemController.tabBarItem, tabBarItemController);
65
+ });
66
+ }
67
+ }, null);
68
+ };
69
+ // Mind implementation for other controllers
70
+ MDTabBarControllerImpl.prototype.traitCollectionDidChange = function (previousTraitCollection) {
71
+ _super.prototype.traitCollectionDidChange.call(this, previousTraitCollection);
72
+ if (majorVersion >= 13) {
73
+ var owner = this._owner.get();
74
+ if (owner &&
75
+ this.traitCollection.hasDifferentColorAppearanceComparedToTraitCollection &&
76
+ this.traitCollection.hasDifferentColorAppearanceComparedToTraitCollection(previousTraitCollection)) {
77
+ owner.notify({
78
+ eventName: IOSHelper.traitCollectionColorAppearanceChangedEvent,
79
+ object: owner
80
+ });
81
+ }
82
+ }
83
+ };
84
+ return MDTabBarControllerImpl;
85
+ }(UITabBarController));
86
+ var BNTabBarControllerDelegateImpl = /** @class */ (function (_super) {
87
+ __extends(BNTabBarControllerDelegateImpl, _super);
88
+ function BNTabBarControllerDelegateImpl() {
89
+ return _super !== null && _super.apply(this, arguments) || this;
90
+ }
91
+ BNTabBarControllerDelegateImpl.initWithOwner = function (owner) {
92
+ var delegate = BNTabBarControllerDelegateImpl.alloc().init();
93
+ delegate._owner = owner;
94
+ return delegate;
95
+ };
96
+ BNTabBarControllerDelegateImpl.prototype.tabBarControllerShouldSelectViewController = function (tabBarController, viewController) {
97
+ // TODO
98
+ // if (Trace.isEnabled()) {
99
+ // Trace.write("TabView.delegate.SHOULD_select(" + tabBarController + ", " + viewController + ");", Trace.categories.Debug);
100
+ // }
101
+ var owner = this._owner.get();
102
+ if (owner) {
103
+ // "< More" cannot be visible after clicking on the main tab bar buttons.
104
+ var backToMoreWillBeVisible = false;
105
+ owner._handleTwoNavigationBars(backToMoreWillBeVisible);
106
+ if (tabBarController.viewControllers) {
107
+ var position = tabBarController.viewControllers.indexOfObject(viewController);
108
+ if (position !== NSNotFound) {
109
+ var tabStrip = owner.tabStrip;
110
+ var tabStripItems = tabStrip && tabStrip.items;
111
+ if (tabStripItems && tabStripItems[position]) {
112
+ tabStripItems[position]._emit(TabStripItem.tapEvent);
113
+ tabStrip.notify({
114
+ eventName: TabStrip.itemTapEvent,
115
+ object: tabStrip,
116
+ index: position
117
+ });
118
+ }
119
+ }
120
+ }
121
+ }
122
+ if (tabBarController.selectedViewController === viewController) {
123
+ return false;
124
+ }
125
+ tabBarController._willSelectViewController = viewController;
126
+ return true;
127
+ };
128
+ BNTabBarControllerDelegateImpl.prototype.tabBarControllerDidSelectViewController = function (tabBarController, viewController) {
129
+ // TODO
130
+ // if (Trace.isEnabled()) {
131
+ // Trace.write("TabView.delegate.DID_select(" + tabBarController + ", " + viewController + ");", Trace.categories.Debug);
132
+ // }
133
+ var owner = this._owner.get();
134
+ if (owner) {
135
+ owner._onViewControllerShown(viewController);
136
+ }
137
+ tabBarController._willSelectViewController = undefined;
138
+ };
139
+ BNTabBarControllerDelegateImpl.ObjCProtocols = [UITabBarControllerDelegate];
140
+ return BNTabBarControllerDelegateImpl;
141
+ }(NSObject));
142
+ var BNNavigationControllerDelegateImpl = /** @class */ (function (_super) {
143
+ __extends(BNNavigationControllerDelegateImpl, _super);
144
+ function BNNavigationControllerDelegateImpl() {
145
+ return _super !== null && _super.apply(this, arguments) || this;
146
+ }
147
+ BNNavigationControllerDelegateImpl.initWithOwner = function (owner) {
148
+ var delegate = BNNavigationControllerDelegateImpl.alloc().init();
149
+ delegate._owner = owner;
150
+ return delegate;
151
+ };
152
+ BNNavigationControllerDelegateImpl.prototype.navigationControllerWillShowViewControllerAnimated = function (navigationController, viewController, animated) {
153
+ // TODO
154
+ // if (Trace.isEnabled()) {
155
+ // Trace.write("TabView.moreNavigationController.WILL_show(" + navigationController + ", " + viewController + ", " + animated + ");", Trace.categories.Debug);
156
+ // }
157
+ var owner = this._owner.get();
158
+ if (owner) {
159
+ // If viewController is one of our tab item controllers, then "< More" will be visible shortly.
160
+ // Otherwise viewController is the UIMoreListController which shows the list of all tabs beyond the 4th tab.
161
+ var backToMoreWillBeVisible = owner.viewController.viewControllers.containsObject(viewController);
162
+ owner._handleTwoNavigationBars(backToMoreWillBeVisible);
163
+ }
164
+ };
165
+ BNNavigationControllerDelegateImpl.prototype.navigationControllerDidShowViewControllerAnimated = function (navigationController, viewController, animated) {
166
+ // TODO
167
+ // if (Trace.isEnabled()) {
168
+ // Trace.write("TabView.moreNavigationController.DID_show(" + navigationController + ", " + viewController + ", " + animated + ");", Trace.categories.Debug);
169
+ // }
170
+ // We don't need Edit button in More screen.
171
+ navigationController.navigationBar.topItem.rightBarButtonItem = null;
172
+ var owner = this._owner.get();
173
+ if (owner) {
174
+ owner._onViewControllerShown(viewController);
175
+ }
176
+ };
177
+ BNNavigationControllerDelegateImpl.ObjCProtocols = [UINavigationControllerDelegate];
178
+ return BNNavigationControllerDelegateImpl;
179
+ }(NSObject));
180
+ function updateBackgroundPositions(tabStrip, tabStripItem) {
181
+ let bgView = tabStripItem.bgView;
182
+ const index = tabStripItem.index;
183
+ const width = tabStrip.nativeView.frame.size.width / tabStrip.items.length;
184
+ const frame = CGRectMake(width * index, 0, width, tabStrip.nativeView.frame.size.width);
185
+ if (!bgView) {
186
+ bgView = UIView.alloc().initWithFrame(frame);
187
+ tabStrip.nativeView.insertSubviewAtIndex(bgView, 0);
188
+ tabStripItem.bgView = bgView;
189
+ }
190
+ else {
191
+ bgView.frame = frame;
192
+ }
193
+ const backgroundColor = tabStripItem.style.backgroundColor;
194
+ if (backgroundColor) {
195
+ bgView.backgroundColor = backgroundColor instanceof Color ? backgroundColor.ios : backgroundColor;
196
+ }
197
+ else {
198
+ // always default to at least a solid white background as fallback
199
+ // building with Xcode 13 causes bgView with no background to be fully transparent unless a css background-color is set - this allows original default behavior to work as it always did
200
+ bgView.backgroundColor = new Color('#fff').ios;
201
+ }
202
+ }
203
+ function updateTitleAndIconPositions(tabStripItem, tabBarItem, controller) {
204
+ if (!tabStripItem || !tabBarItem) {
205
+ return;
206
+ }
207
+ // For iOS <11 icon is *always* above the text.
208
+ // For iOS 11 icon is above the text *only* on phones in portrait mode.
209
+ const orientation = controller.interfaceOrientation;
210
+ const isPortrait = orientation !== 4 /* UIInterfaceOrientation.LandscapeLeft */ && orientation !== 3 /* UIInterfaceOrientation.LandscapeRight */;
211
+ const isIconAboveTitle = majorVersion < 11 || (isPhone && isPortrait);
212
+ if (!tabStripItem.iconSource) {
213
+ if (isIconAboveTitle) {
214
+ tabBarItem.titlePositionAdjustment = {
215
+ horizontal: 0,
216
+ vertical: -20
217
+ };
218
+ }
219
+ else {
220
+ tabBarItem.titlePositionAdjustment = { horizontal: 0, vertical: 0 };
221
+ }
222
+ }
223
+ if (!tabStripItem.title) {
224
+ if (isIconAboveTitle) {
225
+ tabBarItem.imageInsets = new UIEdgeInsets({
226
+ top: 6,
227
+ left: 0,
228
+ bottom: -6,
229
+ right: 0
230
+ });
231
+ }
232
+ else {
233
+ tabBarItem.imageInsets = new UIEdgeInsets({
234
+ top: 0,
235
+ left: 0,
236
+ bottom: 0,
237
+ right: 0
238
+ });
239
+ }
240
+ }
241
+ }
242
+ export const iosCustomPositioningProperty = new Property({
243
+ name: 'iosCustomPositioning',
244
+ defaultValue: false,
245
+ valueConverter: booleanConverter
246
+ });
247
+ let BottomNavigation = class BottomNavigation extends TabNavigationBase {
248
+ constructor() {
249
+ super();
250
+ this.tabsPosition = TabsPosition.Bottom;
251
+ this.mIconsCache = {};
252
+ this.viewController = MDTabBarControllerImpl.initWithOwner(new WeakRef(this));
253
+ }
254
+ createNativeView() {
255
+ return this.viewController.view;
256
+ }
257
+ initNativeView() {
258
+ super.initNativeView();
259
+ this.mDelegate = BNTabBarControllerDelegateImpl.initWithOwner(new WeakRef(this));
260
+ this.mMoreNavigationControllerDelegate = BNNavigationControllerDelegateImpl.initWithOwner(new WeakRef(this));
261
+ if (!this.tabStrip) {
262
+ this.viewController.tabBar.hidden = true;
263
+ }
264
+ }
265
+ disposeNativeView() {
266
+ this.mDelegate = null;
267
+ this.mMoreNavigationControllerDelegate = null;
268
+ super.disposeNativeView();
269
+ }
270
+ onLoaded() {
271
+ super.onLoaded();
272
+ this.setViewControllers(this.items);
273
+ const selectedIndex = this.selectedIndex;
274
+ const selectedView = this.items && this.items[selectedIndex] && this.items[selectedIndex].content;
275
+ if (selectedView instanceof Frame) {
276
+ selectedView._pushInFrameStackRecursive();
277
+ }
278
+ this.viewController.delegate = this.mDelegate;
279
+ this.onSelectedIndexChanged(selectedIndex, selectedIndex);
280
+ }
281
+ onUnloaded() {
282
+ this.viewController.delegate = null;
283
+ this.viewController.moreNavigationController.delegate = null;
284
+ super.onUnloaded();
285
+ this.items.forEach((item, i) => {
286
+ item.unloadView(item.content);
287
+ });
288
+ }
289
+ // @ts-ignore
290
+ get ios() {
291
+ return this.viewController;
292
+ }
293
+ layoutNativeView(left, top, right, bottom) {
294
+ if (this.iosCustomPositioning) {
295
+ super.layoutNativeView(left, top, right, bottom);
296
+ }
297
+ }
298
+ _setNativeViewFrame(nativeView, frame) {
299
+ if (this.iosCustomPositioning) {
300
+ super._setNativeViewFrame(nativeView, frame);
301
+ }
302
+ }
303
+ onSelectedIndexChanged(oldIndex, newIndex) {
304
+ const items = this.items;
305
+ if (!items) {
306
+ return;
307
+ }
308
+ if (this.unloadOnTabChange) {
309
+ const oldItem = items[oldIndex];
310
+ if (oldItem) {
311
+ oldItem.canBeLoaded = false;
312
+ oldItem.unloadView(oldItem.content);
313
+ }
314
+ }
315
+ const newItem = items[newIndex];
316
+ if (newItem && this.isLoaded) {
317
+ const selectedView = items[newIndex].content;
318
+ if (selectedView instanceof Frame) {
319
+ selectedView._pushInFrameStackRecursive();
320
+ }
321
+ newItem.canBeLoaded = true;
322
+ newItem.loadView(newItem.content);
323
+ }
324
+ const tabStripItems = this.tabStrip && this.tabStrip.items;
325
+ if (tabStripItems) {
326
+ if (tabStripItems[newIndex]) {
327
+ tabStripItems[newIndex]._emit(TabStripItem.selectEvent);
328
+ }
329
+ if (oldIndex !== newIndex && tabStripItems[oldIndex]) {
330
+ tabStripItems[oldIndex]._emit(TabStripItem.unselectEvent);
331
+ }
332
+ }
333
+ super.onSelectedIndexChanged(oldIndex, newIndex);
334
+ }
335
+ getTabBarBackgroundColor() {
336
+ return this.viewController.tabBar.barTintColor;
337
+ }
338
+ setTabBarBackgroundColor(value) {
339
+ this.viewController.tabBar.barTintColor = value instanceof Color ? value.ios : value;
340
+ this.updateAllItemsColors();
341
+ }
342
+ setTabBarItemTitle(tabStripItem, value) {
343
+ tabStripItem.nativeView.title = value;
344
+ }
345
+ setTabBarItemBackgroundColor(tabStripItem, value) {
346
+ if (!this.tabStrip || !tabStripItem) {
347
+ return;
348
+ }
349
+ updateBackgroundPositions(this.tabStrip, tabStripItem);
350
+ }
351
+ setTabBarItemColor(tabStripItem, value) {
352
+ this.setViewAttributes(tabStripItem.nativeView, tabStripItem.label);
353
+ }
354
+ setItemColors() {
355
+ if (this.mSelectedItemColor) {
356
+ this.viewController.tabBar.selectedImageTintColor = this.mSelectedItemColor.ios;
357
+ }
358
+ if (this.mUnSelectedItemColor) {
359
+ this.viewController.tabBar.unselectedItemTintColor = this.mUnSelectedItemColor.ios;
360
+ }
361
+ }
362
+ setIconColor(tabStripItem, forceReload = false) {
363
+ if (forceReload || (!this.mUnSelectedItemColor && !this.mSelectedItemColor)) {
364
+ // if selectedItemColor or unSelectedItemColor is set we don't respect the color from the style
365
+ const tabStripColor = this.selectedIndex === tabStripItem.index ? this.mSelectedItemColor : this.mUnSelectedItemColor;
366
+ const image = this.getIcon(tabStripItem, tabStripColor);
367
+ tabStripItem.nativeView.image = image;
368
+ tabStripItem.nativeView.selectedImage = image;
369
+ }
370
+ }
371
+ setTabBarIconColor(tabStripItem, value) {
372
+ this.setIconColor(tabStripItem);
373
+ }
374
+ setTabBarIconSource(tabStripItem, value) {
375
+ this.updateItemColors(tabStripItem);
376
+ }
377
+ setTabBarItemFontInternal(tabStripItem, value) {
378
+ this.setViewAttributes(tabStripItem.nativeView, tabStripItem.label);
379
+ }
380
+ setTabBarItemTextTransform(tabStripItem, value) {
381
+ tabStripItem.nativeView.title = getTransformedText(tabStripItem.label.text, value);
382
+ }
383
+ getTabBarHighlightColor() {
384
+ return this.viewController.tabBar.tintColor;
385
+ }
386
+ setTabBarHighlightColor(value) {
387
+ this.viewController.tabBar.tintColor = value instanceof Color ? value.ios : value;
388
+ }
389
+ getTabBarSelectedItemColor() {
390
+ return this.mSelectedItemColor;
391
+ }
392
+ setTabBarSelectedItemColor(value) {
393
+ this.mSelectedItemColor = value;
394
+ this.updateAllItemsColors();
395
+ }
396
+ getTabBarUnSelectedItemColor() {
397
+ return this.mUnSelectedItemColor;
398
+ }
399
+ setTabBarUnSelectedItemColor(value) {
400
+ this.mUnSelectedItemColor = value;
401
+ this.updateAllItemsColors();
402
+ }
403
+ onMeasure(widthMeasureSpec, heightMeasureSpec) {
404
+ const width = Utils.layout.getMeasureSpecSize(widthMeasureSpec);
405
+ const widthMode = Utils.layout.getMeasureSpecMode(widthMeasureSpec);
406
+ const height = Utils.layout.getMeasureSpecSize(heightMeasureSpec);
407
+ const heightMode = Utils.layout.getMeasureSpecMode(heightMeasureSpec);
408
+ const widthAndState = View.resolveSizeAndState(width, width, widthMode, 0);
409
+ const heightAndState = View.resolveSizeAndState(height, height, heightMode, 0);
410
+ this.setMeasuredDimension(widthAndState, heightAndState);
411
+ }
412
+ _onViewControllerShown(viewController) {
413
+ // This method could be called with the moreNavigationController or its list controller, so we have to check.
414
+ // TODO
415
+ // if (Trace.isEnabled()) {
416
+ // Trace.write("TabView._onViewControllerShown(" + viewController + ");", Trace.categories.Debug);
417
+ // }
418
+ if (this.viewController.viewControllers && this.viewController.viewControllers.containsObject(viewController)) {
419
+ this.selectedIndex = this.viewController.viewControllers.indexOfObject(viewController);
420
+ }
421
+ else {
422
+ // TODO
423
+ // if (Trace.isEnabled()) {
424
+ // Trace.write("TabView._onViewControllerShown: viewController is not one of our viewControllers", Trace.categories.Debug);
425
+ // }
426
+ }
427
+ }
428
+ _handleTwoNavigationBars(backToMoreWillBeVisible) {
429
+ // TODO
430
+ // if (Trace.isEnabled()) {
431
+ // Trace.write(`TabView._handleTwoNavigationBars(backToMoreWillBeVisible: ${backToMoreWillBeVisible})`, Trace.categories.Debug);
432
+ // }
433
+ // The "< Back" and "< More" navigation bars should not be visible simultaneously.
434
+ const page = this.page || this._selectedView.page || this._selectedView.currentPage;
435
+ if (!page || !page.frame) {
436
+ return;
437
+ }
438
+ const actionBarVisible = page.frame._getNavBarVisible(page);
439
+ if (backToMoreWillBeVisible && actionBarVisible) {
440
+ page.frame.ios._disableNavBarAnimation = true;
441
+ page.actionBarHidden = true;
442
+ page.frame.ios._disableNavBarAnimation = false;
443
+ this._actionBarHiddenByTabView = true;
444
+ // TODO
445
+ // if (Trace.isEnabled()) {
446
+ // Trace.write(`TabView hid action bar`, Trace.categories.Debug);
447
+ // }
448
+ return;
449
+ }
450
+ if (!backToMoreWillBeVisible && this._actionBarHiddenByTabView) {
451
+ page.frame.ios._disableNavBarAnimation = true;
452
+ page.actionBarHidden = false;
453
+ page.frame.ios._disableNavBarAnimation = false;
454
+ this._actionBarHiddenByTabView = undefined;
455
+ // TODO
456
+ // if (Trace.isEnabled()) {
457
+ // Trace.write(`TabView restored action bar`, Trace.categories.Debug);
458
+ // }
459
+ return;
460
+ }
461
+ }
462
+ getViewController(item) {
463
+ let newController = item.content ? item.content.viewController : null;
464
+ if (newController) {
465
+ item.setViewController(newController, newController.view);
466
+ return newController;
467
+ }
468
+ if (item.content.ios instanceof UIViewController) {
469
+ newController = item.content.ios;
470
+ item.setViewController(newController, newController.view);
471
+ }
472
+ else if (item.content.ios && item.content.ios.controller instanceof UIViewController) {
473
+ newController = item.content.ios.controller;
474
+ item.setViewController(newController, newController.view);
475
+ }
476
+ else {
477
+ newController = IOSHelper.UILayoutViewController.initWithOwner(new WeakRef(item.content));
478
+ newController.view.addSubview(item.content.nativeViewProtected);
479
+ item.content.viewController = newController;
480
+ item.setViewController(newController, item.content.nativeViewProtected);
481
+ }
482
+ return newController;
483
+ }
484
+ setViewControllers(items) {
485
+ const length = items ? items.length : 0;
486
+ if (length === 0) {
487
+ this.viewController.viewControllers = null;
488
+ return;
489
+ }
490
+ // Limit both tabContentItems and tabStripItems to 5 in order to prevent iOS 'more' button
491
+ items = items.slice(0, maxTabsCount);
492
+ const controllers = NSMutableArray.alloc().initWithCapacity(length);
493
+ if (this.tabStrip) {
494
+ this.tabStrip.setNativeView(this.viewController.tabBar);
495
+ }
496
+ items.forEach((item, i) => {
497
+ const controller = this.getViewController(item);
498
+ if (this.tabStrip && this.tabStrip.items && this.tabStrip.items[i]) {
499
+ const tabStripItem = this.tabStrip.items[i];
500
+ const tabBarItem = this.createTabBarItem(tabStripItem, i);
501
+ updateTitleAndIconPositions(tabStripItem, tabBarItem, controller);
502
+ this.setViewAttributes(tabBarItem, tabStripItem.label);
503
+ controller.tabBarItem = tabBarItem;
504
+ tabStripItem.index = i;
505
+ tabStripItem.setNativeView(tabBarItem);
506
+ }
507
+ controllers.addObject(controller);
508
+ });
509
+ this.setItemImages();
510
+ this.viewController.viewControllers = controllers;
511
+ this.viewController.customizableViewControllers = null;
512
+ // When we set this.viewController.viewControllers, someone is clearing the moreNavigationController.delegate, so we have to reassign it each time here.
513
+ this.viewController.moreNavigationController.delegate = this.mMoreNavigationControllerDelegate;
514
+ }
515
+ setItemImages() {
516
+ if (this.mSelectedItemColor || this.mUnSelectedItemColor) {
517
+ if (this.tabStrip && this.tabStrip.items) {
518
+ this.tabStrip.items.forEach((item) => {
519
+ if (this.mUnSelectedItemColor && item.nativeView) {
520
+ item.nativeView.image = this.getIcon(item, this.mUnSelectedItemColor);
521
+ item.nativeView.tintColor = this.mUnSelectedItemColor;
522
+ }
523
+ if (this.mSelectedItemColor && item.nativeView) {
524
+ item.nativeView.selectedImage = this.getIcon(item, this.mSelectedItemColor);
525
+ item.nativeView.tintColor = this.mSelectedItemColor;
526
+ }
527
+ });
528
+ }
529
+ }
530
+ }
531
+ updateAllItemsColors() {
532
+ this.setItemColors();
533
+ if (this.tabStrip && this.tabStrip.items) {
534
+ this.tabStrip.items.forEach((tabStripItem) => {
535
+ this.updateItemColors(tabStripItem);
536
+ });
537
+ }
538
+ }
539
+ updateItemColors(tabStripItem) {
540
+ updateBackgroundPositions(this.tabStrip, tabStripItem);
541
+ this.setIconColor(tabStripItem, true);
542
+ }
543
+ createTabBarItem(item, index) {
544
+ let image;
545
+ let title;
546
+ if (item.isLoaded) {
547
+ image = this.getIcon(item);
548
+ title = item.label.text;
549
+ const textTransform = item.label.style.textTransform;
550
+ if (textTransform) {
551
+ title = getTransformedText(title, textTransform);
552
+ }
553
+ }
554
+ return UITabBarItem.alloc().initWithTitleImageTag(title, image, index);
555
+ }
556
+ getIconRenderingMode() {
557
+ switch (this.tabStrip && this.tabStrip.iosIconRenderingMode) {
558
+ case 'alwaysOriginal':
559
+ return 1 /* UIImageRenderingMode.AlwaysOriginal */;
560
+ case 'alwaysTemplate':
561
+ return 2 /* UIImageRenderingMode.AlwaysTemplate */;
562
+ case 'automatic':
563
+ default:
564
+ return 0 /* UIImageRenderingMode.Automatic */;
565
+ }
566
+ }
567
+ getIcon(tabStripItem, color) {
568
+ // Image and Label children of TabStripItem
569
+ // take priority over its `iconSource` and `title` properties
570
+ const iconSource = tabStripItem.image && tabStripItem.image.src;
571
+ if (!iconSource) {
572
+ return null;
573
+ }
574
+ const target = tabStripItem.image;
575
+ const font = target.style.fontInternal || Font.default;
576
+ if (!color) {
577
+ color = target.style.color;
578
+ }
579
+ const iconTag = [iconSource, font.fontStyle, font.fontWeight, font.fontSize, font.fontFamily, color].join(';');
580
+ let isFontIcon = false;
581
+ let image = this.mIconsCache[iconTag];
582
+ if (!image) {
583
+ let is;
584
+ if (typeof iconSource === 'string') {
585
+ if (Utils.isFontIconURI(iconSource)) {
586
+ isFontIcon = true;
587
+ const fontIconCode = iconSource.split('//')[1];
588
+ const target = tabStripItem.image ? tabStripItem.image : tabStripItem;
589
+ const font = target.style.fontInternal;
590
+ if (!color) {
591
+ color = target.style.color;
592
+ }
593
+ is = ImageSource.fromFontIconCodeSync(fontIconCode, font, color);
594
+ }
595
+ else {
596
+ is = ImageSource.fromFileOrResourceSync(iconSource);
597
+ }
598
+ }
599
+ else {
600
+ is = iconSource;
601
+ }
602
+ image = is?.ios;
603
+ if (image) {
604
+ image = is.ios;
605
+ if (this.tabStrip && this.tabStrip.isIconSizeFixed) {
606
+ image = this.getFixedSizeIcon(image);
607
+ }
608
+ let renderingMode = 1 /* UIImageRenderingMode.AlwaysOriginal */;
609
+ if (!isFontIcon) {
610
+ renderingMode = this.getIconRenderingMode();
611
+ }
612
+ const originalRenderedImage = image.imageWithRenderingMode(renderingMode);
613
+ this.mIconsCache[iconTag] = originalRenderedImage;
614
+ image = originalRenderedImage;
615
+ }
616
+ else {
617
+ // TODO
618
+ // traceMissingIcon(iconSource);
619
+ }
620
+ }
621
+ return image;
622
+ }
623
+ getFixedSizeIcon(image) {
624
+ const inWidth = image.size.width;
625
+ const inHeight = image.size.height;
626
+ const iconSpecSize = getIconSpecSize({
627
+ width: inWidth,
628
+ height: inHeight
629
+ });
630
+ const widthPts = iconSpecSize.width;
631
+ const heightPts = iconSpecSize.height;
632
+ UIGraphicsBeginImageContextWithOptions({ width: widthPts, height: heightPts }, false, Utils.layout.getDisplayDensity());
633
+ image.drawInRect(CGRectMake(0, 0, widthPts, heightPts));
634
+ const resultImage = UIGraphicsGetImageFromCurrentImageContext();
635
+ UIGraphicsEndImageContext();
636
+ return resultImage;
637
+ }
638
+ // private _updateIOSTabBarColorsAndFonts(): void {
639
+ // if (!this.tabStrip || !this.tabStrip.items || !this.tabStrip.items.length) {
640
+ // return;
641
+ // }
642
+ // const tabBar = <UITabBar>this.ios.tabBar;
643
+ // const states = getTitleAttributesForStates(this);
644
+ // for (let i = 0; i < tabBar.items.count; i++) {
645
+ // applyStatesToItem(tabBar.items[i], states);
646
+ // }
647
+ // }
648
+ // TODO: Move this to TabStripItem
649
+ // [fontInternalProperty.getDefault](): Font {
650
+ // return null;
651
+ // }
652
+ // [fontInternalProperty.setNative](value: Font) {
653
+ // this._updateIOSTabBarColorsAndFonts();
654
+ // }
655
+ [selectedIndexProperty.setNative](value) {
656
+ // TODO
657
+ // if (Trace.isEnabled()) {
658
+ // Trace.write("TabView._onSelectedIndexPropertyChangedSetNativeValue(" + value + ")", Trace.categories.Debug);
659
+ // }
660
+ if (value > -1) {
661
+ this.viewController._willSelectViewController = this.viewController.viewControllers[value];
662
+ this.viewController.selectedIndex = value;
663
+ }
664
+ }
665
+ [itemsProperty.getDefault]() {
666
+ return null;
667
+ }
668
+ [itemsProperty.setNative](value) {
669
+ if (value) {
670
+ value.forEach((item, i) => {
671
+ item.index = i;
672
+ });
673
+ }
674
+ this.setViewControllers(value);
675
+ selectedIndexProperty.coerce(this);
676
+ }
677
+ [tabStripProperty.getDefault]() {
678
+ return null;
679
+ }
680
+ [tabStripProperty.setNative](value) {
681
+ this.setViewControllers(this.items);
682
+ selectedIndexProperty.coerce(this);
683
+ }
684
+ setViewAttributes(item, view) {
685
+ if (!view) {
686
+ return null;
687
+ }
688
+ const defaultTabItemFontSize = 10;
689
+ const tabItemFontSize = view.style.fontSize || defaultTabItemFontSize;
690
+ const font = (view.style.fontInternal || Font.default).getUIFont(UIFont.systemFontOfSize(tabItemFontSize));
691
+ const tabItemTextColor = view.style.color;
692
+ const textColor = tabItemTextColor instanceof Color ? tabItemTextColor.ios : null;
693
+ const attributes = { [NSFontAttributeName]: font };
694
+ // if selectedItemColor or unSelectedItemColor is set we don't respect the color from the style
695
+ if (!this.mSelectedItemColor && !this.mUnSelectedItemColor) {
696
+ if (textColor) {
697
+ attributes[UITextAttributeTextColor] = textColor;
698
+ attributes[NSForegroundColorAttributeName] = textColor;
699
+ }
700
+ }
701
+ else {
702
+ this.viewController.tabBar.unselectedItemTintColor = this.mUnSelectedItemColor && this.mUnSelectedItemColor.ios;
703
+ this.viewController.tabBar.selectedImageTintColor = this.mSelectedItemColor && this.mSelectedItemColor.ios;
704
+ }
705
+ item.setTitleTextAttributesForState(attributes, 4 /* UIControlState.Selected */);
706
+ item.setTitleTextAttributesForState(attributes, 0 /* UIControlState.Normal */);
707
+ // there's a bug when setting the item color on ios 13 if there's no background set to the tabstrip
708
+ // https://books.google.bg/books?id=99_BDwAAQBAJ&q=tabBar.unselectedItemTintColor
709
+ // to fix the above issue we are applying the selected fix only for the case, when there is no background set
710
+ // in that case we have the following known issue:
711
+ // // we will set the color to all unselected items, so you won't be able to set different colors for the different not selected items
712
+ if (!this.viewController.tabBar.barTintColor && attributes[UITextAttributeTextColor] && majorVersion > 9) {
713
+ this.viewController.tabBar.unselectedItemTintColor = attributes[UITextAttributeTextColor];
714
+ }
715
+ }
716
+ };
717
+ BottomNavigation = __decorate([
718
+ CSSType('BottomNavigation')
719
+ ], BottomNavigation);
720
+ export { BottomNavigation };
721
+ iosCustomPositioningProperty.register(BottomNavigation);
722
+ //# sourceMappingURL=index.ios.js.map