@nativescript-community/ui-material-core 6.2.14 → 6.2.17

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.
Files changed (39) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/android/utils.js +1 -1
  3. package/android/utils.js.map +1 -1
  4. package/cssproperties.js +1 -1
  5. package/cssproperties.js.map +1 -1
  6. package/index.android.js +2 -2
  7. package/index.android.js.map +1 -1
  8. package/index.ios.js +1 -1
  9. package/index.ios.js.map +1 -1
  10. package/package.json +5 -4
  11. package/platforms/android/ui_material_core.aar +0 -0
  12. package/pnpm-lock.yaml +83 -0
  13. package/scripts/before-prepare.js +1 -1
  14. package/scripts/before-prepare.js.map +1 -1
  15. package/tab-navigation-base/react/index.js +2 -5
  16. package/tab-navigation-base/react/index.js.map +1 -1
  17. package/tab-navigation-base/tab-content-item/index.android.js +3 -1
  18. package/tab-navigation-base/tab-content-item/index.android.js.map +1 -1
  19. package/tab-navigation-base/tab-content-item/tab-content-item-common.js +3 -1
  20. package/tab-navigation-base/tab-content-item/tab-content-item-common.js.map +1 -1
  21. package/tab-navigation-base/tab-navigation/index-common.d.ts +22 -0
  22. package/tab-navigation-base/tab-navigation/index-common.js +36 -0
  23. package/tab-navigation-base/tab-navigation/index-common.js.map +1 -0
  24. package/tab-navigation-base/tab-navigation/index.android.d.ts +81 -0
  25. package/tab-navigation-base/tab-navigation/index.android.js +869 -0
  26. package/tab-navigation-base/tab-navigation/index.android.js.map +1 -0
  27. package/tab-navigation-base/tab-navigation/index.d.ts +80 -0
  28. package/tab-navigation-base/tab-navigation/index.ios.d.ts +91 -0
  29. package/tab-navigation-base/tab-navigation/index.ios.js +794 -0
  30. package/tab-navigation-base/tab-navigation/index.ios.js.map +1 -0
  31. package/tab-navigation-base/tab-navigation-base/index.js +3 -1
  32. package/tab-navigation-base/tab-navigation-base/index.js.map +1 -1
  33. package/tab-navigation-base/tab-strip/index.js +3 -1
  34. package/tab-navigation-base/tab-strip/index.js.map +1 -1
  35. package/tab-navigation-base/tab-strip-item/index.js +4 -1
  36. package/tab-navigation-base/tab-strip-item/index.js.map +1 -1
  37. package/textbase/cssproperties.js +1 -1
  38. package/textbase/cssproperties.js.map +1 -1
  39. package/tsconfig.hooks.json +1 -3
@@ -0,0 +1,794 @@
1
+ import { Color, Device, Font, Frame, IOSHelper, ImageSource, Property, Utils, View, ViewBase, booleanConverter } from '@nativescript/core';
2
+ import { TabContentItem } from '../tab-content-item';
3
+ import { getIconSpecSize, itemsProperty, selectedIndexProperty, tabStripProperty } from '../tab-navigation-base';
4
+ import { TabStrip } from '../tab-strip';
5
+ import { TabStripItem } from '../tab-strip-item';
6
+ import { TabNavigationBase, swipeEnabledProperty } from './index-common';
7
+ export { TabContentItem, TabStrip, TabStripItem };
8
+ const majorVersion = Utils.ios.MajorVersion;
9
+ const isPhone = Device.deviceType === 'Phone';
10
+ const invokeOnRunLoop = (function () {
11
+ const runloop = CFRunLoopGetMain();
12
+ return (action) => {
13
+ CFRunLoopPerformBlock(runloop, kCFRunLoopDefaultMode, action);
14
+ CFRunLoopWakeUp(runloop);
15
+ };
16
+ })();
17
+ var BackgroundIndicatorTemplate = /** @class */ (function (_super) {
18
+ __extends(BackgroundIndicatorTemplate, _super);
19
+ function BackgroundIndicatorTemplate() {
20
+ return _super !== null && _super.apply(this, arguments) || this;
21
+ }
22
+ BackgroundIndicatorTemplate.prototype.indicatorAttributesForContext = function (context) {
23
+ var attributes = new MDCTabBarViewIndicatorAttributes();
24
+ attributes.path = UIBezierPath.bezierPathWithRect(context.bounds);
25
+ return attributes;
26
+ };
27
+ BackgroundIndicatorTemplate.ObjCProtocols = [MDCTabBarViewIndicatorTemplate];
28
+ return BackgroundIndicatorTemplate;
29
+ }(NSObject));
30
+ var UIPageViewControllerDataSourceImpl = /** @class */ (function (_super) {
31
+ __extends(UIPageViewControllerDataSourceImpl, _super);
32
+ function UIPageViewControllerDataSourceImpl() {
33
+ return _super !== null && _super.apply(this, arguments) || this;
34
+ }
35
+ UIPageViewControllerDataSourceImpl.initWithOwner = function (owner) {
36
+ var dataSource = UIPageViewControllerDataSourceImpl.new();
37
+ dataSource._owner = owner;
38
+ return dataSource;
39
+ };
40
+ UIPageViewControllerDataSourceImpl.prototype.pageViewControllerViewControllerBeforeViewController = function (pageViewController, viewController) {
41
+ // if (traceEnabled()) {
42
+ // traceWrite("TabView.delegate.SHOULD_select(" + tabBarController + ", " + viewController + ");", traceCategories.Debug);
43
+ // }
44
+ var owner = this._owner.get();
45
+ var selectedIndex = owner.selectedIndex;
46
+ if (selectedIndex === 0) {
47
+ return null;
48
+ }
49
+ selectedIndex--;
50
+ var prevItem = owner.items[selectedIndex];
51
+ var prevViewController = prevItem.__controller;
52
+ // if (!prevViewController) {
53
+ // prevViewController = owner.getViewController(prevItem);
54
+ // }
55
+ owner._setCanBeLoaded(selectedIndex);
56
+ owner._loadUnloadTabItems(selectedIndex);
57
+ return prevViewController;
58
+ };
59
+ UIPageViewControllerDataSourceImpl.prototype.pageViewControllerViewControllerAfterViewController = function (pageViewController, viewController) {
60
+ // if (Trace.isEnabled()) {
61
+ // traceWrite('TabView.delegate.SHOULD_select(' + tabBarController + ', ' + viewController + ');', traceCategories.Debug);
62
+ // }
63
+ var owner = this._owner.get();
64
+ var selectedIndex = owner.selectedIndex;
65
+ if (selectedIndex === owner.items.length - 1) {
66
+ return null;
67
+ }
68
+ selectedIndex++;
69
+ var nextItem = owner.items[selectedIndex];
70
+ var nextViewController = nextItem.__controller;
71
+ // if (!nextViewController) {
72
+ // nextViewController = owner.getViewController(nextItem);
73
+ // }
74
+ owner._setCanBeLoaded(selectedIndex);
75
+ owner._loadUnloadTabItems(selectedIndex);
76
+ // nextItem.loadView(nextItem.view);
77
+ return nextViewController;
78
+ };
79
+ UIPageViewControllerDataSourceImpl.prototype.presentationCountForPageViewController = function (pageViewController) {
80
+ // TODO
81
+ // if (traceEnabled()) {
82
+ // traceWrite("TabView.delegate.SHOULD_select(" + tabBarController + ", " + viewController + ");", traceCategories.Debug);
83
+ // }
84
+ return 0;
85
+ };
86
+ UIPageViewControllerDataSourceImpl.prototype.presentationIndexForPageViewController = function (pageViewController) {
87
+ // TODO
88
+ // if (traceEnabled()) {
89
+ // traceWrite("TabView.delegate.SHOULD_select(" + tabBarController + ", " + viewController + ");", traceCategories.Debug);
90
+ // }
91
+ return 0;
92
+ };
93
+ UIPageViewControllerDataSourceImpl.ObjCProtocols = [UIPageViewControllerDataSource];
94
+ return UIPageViewControllerDataSourceImpl;
95
+ }(NSObject));
96
+ var UIPageViewControllerDelegateImpl = /** @class */ (function (_super) {
97
+ __extends(UIPageViewControllerDelegateImpl, _super);
98
+ function UIPageViewControllerDelegateImpl() {
99
+ return _super !== null && _super.apply(this, arguments) || this;
100
+ }
101
+ UIPageViewControllerDelegateImpl.initWithOwner = function (owner) {
102
+ var delegate = UIPageViewControllerDelegateImpl.new();
103
+ delegate._owner = owner;
104
+ return delegate;
105
+ };
106
+ UIPageViewControllerDelegateImpl.prototype.pageViewControllerWillTransitionToViewControllers = function (pageViewController, viewControllers) {
107
+ // const owner = this._owner.get();
108
+ // const ownerViewControllers = owner.viewControllers;
109
+ // const selectedIndex = owner.selectedIndex;
110
+ // const nextViewController = viewControllers[0];
111
+ // const nextViewControllerIndex = ownerViewControllers.indexOf(nextViewController);
112
+ // if (selectedIndex > nextViewControllerIndex) {
113
+ // owner.selectedIndex--;
114
+ // } else {
115
+ // owner.selectedIndex++;
116
+ // }
117
+ };
118
+ UIPageViewControllerDelegateImpl.prototype.pageViewControllerDidFinishAnimatingPreviousViewControllersTransitionCompleted = function (pageViewController, didFinishAnimating, previousViewControllers, transitionCompleted) {
119
+ if (!transitionCompleted) {
120
+ return;
121
+ }
122
+ var owner = this._owner.get();
123
+ var ownerViewControllers = owner.viewControllers;
124
+ var selectedIndex = owner.selectedIndex;
125
+ var nextViewController = pageViewController.viewControllers[0];
126
+ var nextViewControllerIndex = ownerViewControllers.indexOf(nextViewController);
127
+ if (selectedIndex !== nextViewControllerIndex) {
128
+ // let s not animate again on selectedIndex change
129
+ // or it will create weird behaviors
130
+ owner.mAnimateNextChange = false;
131
+ owner.selectedIndex = nextViewControllerIndex;
132
+ owner.finishTabTransition();
133
+ }
134
+ // HACK: UIPageViewController fix; see https://stackoverflow.com/questions/15325891
135
+ if (owner.mNeedsCacheUpdate) {
136
+ invokeOnRunLoop(function () {
137
+ owner.mNeedsCacheUpdate = false;
138
+ var viewController = owner.viewController;
139
+ viewController.dataSource = null;
140
+ viewController.dataSource = owner._dataSource;
141
+ });
142
+ }
143
+ };
144
+ UIPageViewControllerDelegateImpl.ObjCProtocols = [UIPageViewControllerDelegate];
145
+ return UIPageViewControllerDelegateImpl;
146
+ }(NSObject));
147
+ function iterateIndexRange(index, eps, lastIndex, callback) {
148
+ const rangeStart = Math.max(0, index - eps);
149
+ const rangeEnd = Math.min(index + eps, lastIndex);
150
+ for (let i = rangeStart; i <= rangeEnd; i++) {
151
+ callback(i);
152
+ }
153
+ }
154
+ export function updateBackgroundPositions(tabStrip, tabStripItem, color = null) {
155
+ if (!tabStrip.nativeView || tabStripItem._index === undefined) {
156
+ return;
157
+ }
158
+ let bgView = tabStripItem.bgView;
159
+ const index = tabStripItem._index;
160
+ const width = tabStrip.nativeView.frame.size.width / tabStrip.items.filter((s) => s._index !== undefined).length;
161
+ const frame = CGRectMake(width * index, 0, width, tabStrip.nativeView.frame.size.width);
162
+ if (!bgView) {
163
+ bgView = UIView.alloc().initWithFrame(frame);
164
+ tabStrip.nativeView.insertSubviewAtIndex(bgView, 0);
165
+ tabStripItem.bgView = bgView;
166
+ }
167
+ else {
168
+ bgView.frame = frame;
169
+ }
170
+ const backgroundColor = tabStripItem.style.backgroundColor;
171
+ bgView.backgroundColor = color || (backgroundColor instanceof Color ? backgroundColor.ios : backgroundColor);
172
+ }
173
+ export function updateTitleAndIconPositions(tabStripItem, tabBarItem, controller) {
174
+ if (!tabStripItem || !tabBarItem) {
175
+ return;
176
+ }
177
+ const orientation = controller.interfaceOrientation;
178
+ const isPortrait = orientation !== 4 && orientation !== 3;
179
+ const isIconAboveTitle = majorVersion < 11 || (isPhone && isPortrait);
180
+ if (!tabStripItem.iconSource) {
181
+ if (isIconAboveTitle) {
182
+ tabBarItem.titlePositionAdjustment = { horizontal: 0, vertical: -20 };
183
+ }
184
+ else {
185
+ tabBarItem.titlePositionAdjustment = { horizontal: 0, vertical: 0 };
186
+ }
187
+ }
188
+ if (!tabStripItem.title) {
189
+ if (isIconAboveTitle) {
190
+ tabBarItem.imageInsets = new UIEdgeInsets({ top: 6, left: 0, bottom: -6, right: 0 });
191
+ }
192
+ else {
193
+ tabBarItem.imageInsets = new UIEdgeInsets({ top: 0, left: 0, bottom: 0, right: 0 });
194
+ }
195
+ }
196
+ }
197
+ export const iosCustomPositioningProperty = new Property({
198
+ name: 'iosCustomPositioning',
199
+ defaultValue: false,
200
+ valueConverter: booleanConverter
201
+ });
202
+ export class TabNavigation extends TabNavigationBase {
203
+ constructor() {
204
+ super();
205
+ this.mIconsCache = {};
206
+ this.mNeedsCacheUpdate = false;
207
+ this.mAnimateNextChange = true;
208
+ this.mLayoutPending = false;
209
+ this.viewController = this.createViewController();
210
+ }
211
+ createNativeView() {
212
+ return this.viewController.view;
213
+ }
214
+ initNativeView() {
215
+ super.initNativeView();
216
+ this.mDataSource = UIPageViewControllerDataSourceImpl.initWithOwner(new WeakRef(this));
217
+ this.mDelegate = UIPageViewControllerDelegateImpl.initWithOwner(new WeakRef(this));
218
+ }
219
+ disposeNativeView() {
220
+ this.mDataSource = null;
221
+ this.mDelegate = null;
222
+ super.disposeNativeView();
223
+ }
224
+ requestLayout() {
225
+ if (!this.mCanSelectItem) {
226
+ this.mLayoutPending = true;
227
+ }
228
+ else {
229
+ this.mLayoutPending = false;
230
+ super.requestLayout();
231
+ }
232
+ }
233
+ beginTabTransition() {
234
+ this.mCanSelectItem = false;
235
+ }
236
+ finishTabTransition() {
237
+ this.mCanSelectItem = true;
238
+ if (this.mLayoutPending) {
239
+ this.requestLayout();
240
+ }
241
+ }
242
+ onLoaded() {
243
+ super.onLoaded();
244
+ this.setViewControllers(this.items);
245
+ const selectedIndex = this.selectedIndex;
246
+ const selectedView = this.items && this.items[selectedIndex] && this.items[selectedIndex].content;
247
+ if (selectedView instanceof Frame) {
248
+ selectedView._pushInFrameStackRecursive();
249
+ }
250
+ this.viewController.dataSource = this.mDataSource;
251
+ this.viewController.delegate = this.mDelegate;
252
+ }
253
+ onUnloaded() {
254
+ this.viewController.dataSource = null;
255
+ this.viewController.delegate = null;
256
+ super.onUnloaded();
257
+ this.items.forEach((item, i) => {
258
+ item.unloadView(item.content);
259
+ });
260
+ }
261
+ get ios() {
262
+ return this.viewController;
263
+ }
264
+ layoutNativeView(left, top, right, bottom) {
265
+ if (this.iosCustomPositioning) {
266
+ super.layoutNativeView(left, top, right, bottom);
267
+ }
268
+ }
269
+ _setNativeViewFrame(nativeView, frame) {
270
+ if (this.iosCustomPositioning) {
271
+ super._setNativeViewFrame(nativeView, frame);
272
+ }
273
+ }
274
+ onSelectedIndexChanged(oldIndex, newIndex) {
275
+ const items = this.items;
276
+ if (!items) {
277
+ return;
278
+ }
279
+ const oldItem = items[oldIndex];
280
+ if (this.unloadOnTabChange && oldItem) {
281
+ oldItem.canBeLoaded = false;
282
+ oldItem.unloadView(oldItem.content);
283
+ }
284
+ const newItem = items[newIndex];
285
+ if (newItem && this.isLoaded) {
286
+ const selectedView = items[newIndex].content;
287
+ if (selectedView instanceof Frame) {
288
+ selectedView._pushInFrameStackRecursive();
289
+ }
290
+ newItem.canBeLoaded = true;
291
+ newItem.loadView(newItem.content);
292
+ }
293
+ const tabStripItems = this.tabStrip && this.tabStrip.items;
294
+ if (tabStripItems) {
295
+ if (tabStripItems[newIndex]) {
296
+ tabStripItems[newIndex]._emit(TabStripItem.selectEvent);
297
+ this.updateItemColors(tabStripItems[newIndex]);
298
+ }
299
+ if (tabStripItems[oldIndex]) {
300
+ tabStripItems[oldIndex]._emit(TabStripItem.unselectEvent);
301
+ this.updateItemColors(tabStripItems[oldIndex]);
302
+ }
303
+ }
304
+ this._loadUnloadTabItems(newIndex);
305
+ super.onSelectedIndexChanged(oldIndex, newIndex);
306
+ }
307
+ _loadUnloadTabItems(newIndex) {
308
+ const items = this.items;
309
+ if (!items) {
310
+ return;
311
+ }
312
+ const lastIndex = items.length - 1;
313
+ const offsideItems = this.offscreenTabLimit;
314
+ const toUnload = [];
315
+ const toLoad = [];
316
+ iterateIndexRange(newIndex, offsideItems, lastIndex, (i) => toLoad.push(i));
317
+ if (this.unloadOnTabChange) {
318
+ items.forEach((item, i) => {
319
+ const indexOfI = toLoad.indexOf(i);
320
+ if (indexOfI < 0) {
321
+ toUnload.push(i);
322
+ }
323
+ });
324
+ toUnload.forEach((index) => {
325
+ const item = items[index];
326
+ if (items[index]) {
327
+ item.unloadView(item.content);
328
+ }
329
+ });
330
+ }
331
+ const newItem = items[newIndex];
332
+ const selectedView = newItem && newItem.content;
333
+ if (selectedView instanceof Frame) {
334
+ selectedView._pushInFrameStackRecursive();
335
+ }
336
+ toLoad.forEach((index) => {
337
+ const item = items[index];
338
+ if (this.isLoaded && items[index]) {
339
+ item.loadView(item.content);
340
+ }
341
+ });
342
+ }
343
+ onMeasure(widthMeasureSpec, heightMeasureSpec) {
344
+ const width = Utils.layout.getMeasureSpecSize(widthMeasureSpec);
345
+ const widthMode = Utils.layout.getMeasureSpecMode(widthMeasureSpec);
346
+ const height = Utils.layout.getMeasureSpecSize(heightMeasureSpec);
347
+ const heightMode = Utils.layout.getMeasureSpecMode(heightMeasureSpec);
348
+ const widthAndState = View.resolveSizeAndState(width, width, widthMode, 0);
349
+ const heightAndState = View.resolveSizeAndState(height, height, heightMode, 0);
350
+ this.setMeasuredDimension(widthAndState, heightAndState);
351
+ }
352
+ _onViewControllerShown(viewController) {
353
+ if (this.viewController.viewControllers && this.viewController.viewControllers.containsObject(viewController)) {
354
+ this.selectedIndex = this.viewController.viewControllers.indexOfObject(viewController);
355
+ }
356
+ else {
357
+ }
358
+ }
359
+ getViewController(item) {
360
+ let newController = item.content ? item.content.viewController : null;
361
+ if (newController) {
362
+ item.setViewController(newController, newController.view);
363
+ return newController;
364
+ }
365
+ if (item.content.ios instanceof UIViewController) {
366
+ newController = item.content.ios;
367
+ item.setViewController(newController, newController.view);
368
+ }
369
+ else if (item.content.ios && item.content.ios.controller instanceof UIViewController) {
370
+ newController = item.content.ios.controller;
371
+ item.setViewController(newController, newController.view);
372
+ }
373
+ else {
374
+ newController = IOSHelper.UILayoutViewController.initWithOwner(new WeakRef(item.content));
375
+ newController.view.addSubview(item.content.nativeViewProtected);
376
+ item.content.viewController = newController;
377
+ item.setViewController(newController, item.content.nativeViewProtected);
378
+ }
379
+ return newController;
380
+ }
381
+ _setCanBeLoaded(index) {
382
+ const items = this.items;
383
+ if (!this.items) {
384
+ return;
385
+ }
386
+ const lastIndex = items.length - 1;
387
+ const offsideItems = this.offscreenTabLimit;
388
+ iterateIndexRange(index, offsideItems, lastIndex, (i) => {
389
+ if (items[i]) {
390
+ items[i].canBeLoaded = true;
391
+ }
392
+ });
393
+ }
394
+ setViewControllers(items) {
395
+ const length = items ? items.length : 0;
396
+ if (length === 0) {
397
+ this.viewControllers = null;
398
+ return;
399
+ }
400
+ const viewControllers = [];
401
+ const tabBarItems = [];
402
+ if (this.tabStrip) {
403
+ this.tabStrip.setNativeView(this.viewController.tabBar);
404
+ }
405
+ const tabStripItems = this.tabStrip && this.tabStrip.items;
406
+ if (tabStripItems) {
407
+ if (tabStripItems[this.selectedIndex]) {
408
+ tabStripItems[this.selectedIndex]._emit(TabStripItem.selectEvent);
409
+ }
410
+ }
411
+ items.forEach((item, i) => {
412
+ const controller = this.getViewController(item);
413
+ if (this.tabStrip && this.tabStrip.items && this.tabStrip.items[i]) {
414
+ const tabStripItem = this.tabStrip.items[i];
415
+ const tabBarItem = this.createTabBarItem(tabStripItem, i);
416
+ updateTitleAndIconPositions(tabStripItem, tabBarItem, controller);
417
+ this.setViewTextAttributes(tabStripItem.label, i === this.selectedIndex);
418
+ controller.tabBarItem = tabBarItem;
419
+ tabStripItem._index = i;
420
+ tabBarItems.push(tabBarItem);
421
+ tabStripItem.setNativeView(tabBarItem);
422
+ }
423
+ item.canBeLoaded = true;
424
+ viewControllers.push(controller);
425
+ });
426
+ this.setItemImages();
427
+ this.viewControllers = viewControllers;
428
+ this.tabBarItems = tabBarItems;
429
+ if (this.viewController && this.viewController.tabBar) {
430
+ this.viewController.tabBar.items = NSArray.arrayWithArray(this.tabBarItems);
431
+ this.viewController.tabBar.sizeToFit();
432
+ this.viewController.tabBar.setSelectedItemAnimated(this.tabBarItems[this.selectedIndex], false);
433
+ }
434
+ }
435
+ onItemsChanged(oldItems, newItems) {
436
+ this.mNeedsCacheUpdate = true;
437
+ super.onItemsChanged(oldItems, newItems);
438
+ if (oldItems) {
439
+ if (!this.mCanSelectItem) {
440
+ this.finishTabTransition();
441
+ }
442
+ this._setCanBeLoaded(this.selectedIndex);
443
+ this._loadUnloadTabItems(this.selectedIndex);
444
+ }
445
+ }
446
+ setItemImages() {
447
+ if (this.mSelectedItemColor || this.mUnSelectedItemColor) {
448
+ if (this.tabStrip && this.tabStrip.items) {
449
+ this.tabStrip.items.forEach((item) => {
450
+ if (this.mUnSelectedItemColor && item.nativeView) {
451
+ item.nativeView.image = this.getIcon(item, this.mUnSelectedItemColor);
452
+ }
453
+ if (this.mSelectedItemColor && item.nativeView) {
454
+ if (this.selectedIndex === item._index) {
455
+ item.nativeView.image = this.getIcon(item, this.mSelectedItemColor);
456
+ }
457
+ }
458
+ });
459
+ }
460
+ }
461
+ }
462
+ updateAllItemsColors() {
463
+ this.mDefaultItemBackgroundColor = null;
464
+ this.setItemColors();
465
+ if (this.tabStrip && this.tabStrip.items) {
466
+ this.tabStrip.items.forEach((tabStripItem) => {
467
+ this.updateItemColors(tabStripItem);
468
+ });
469
+ }
470
+ }
471
+ updateItemColors(tabStripItem) {
472
+ updateBackgroundPositions(this.tabStrip, tabStripItem);
473
+ this.setIconColor(tabStripItem, true);
474
+ }
475
+ createTabBarItem(item, index) {
476
+ let image;
477
+ let title;
478
+ if (item.isLoaded) {
479
+ image = this.getIcon(item);
480
+ title = item.label.text;
481
+ if (!this.tabStrip._hasImage) {
482
+ this.tabStrip._hasImage = !!image;
483
+ }
484
+ if (!this.tabStrip._hasTitle) {
485
+ this.tabStrip._hasTitle = !!title;
486
+ }
487
+ }
488
+ const tabBarItem = UITabBarItem.alloc().initWithTitleImageTag(title, image, index);
489
+ return tabBarItem;
490
+ }
491
+ getIconRenderingMode() {
492
+ switch (this.tabStrip && this.tabStrip.iosIconRenderingMode) {
493
+ case 'alwaysOriginal':
494
+ return 1;
495
+ case 'alwaysTemplate':
496
+ return 2;
497
+ case 'automatic':
498
+ default:
499
+ const hasItemColor = this.mSelectedItemColor || this.mUnSelectedItemColor;
500
+ return hasItemColor ? 2 : 1;
501
+ }
502
+ }
503
+ getIcon(tabStripItem, color) {
504
+ const iconSource = tabStripItem.image && tabStripItem.image.src;
505
+ if (!iconSource) {
506
+ return null;
507
+ }
508
+ const target = tabStripItem.image;
509
+ const font = target.style.fontInternal || Font.default;
510
+ if (!color) {
511
+ color = target.style.color;
512
+ }
513
+ const iconTag = [iconSource, font.fontStyle, font.fontWeight, font.fontSize, font.fontFamily, color].join(';');
514
+ let isFontIcon = false;
515
+ let image = this.mIconsCache[iconTag];
516
+ if (!image) {
517
+ let is;
518
+ if (Utils.isFontIconURI(iconSource)) {
519
+ isFontIcon = true;
520
+ const fontIconCode = iconSource.split('//')[1];
521
+ is = ImageSource.fromFontIconCodeSync(fontIconCode, font, color);
522
+ }
523
+ else {
524
+ is = ImageSource.fromFileOrResourceSync(iconSource);
525
+ }
526
+ if (is && is.ios) {
527
+ image = is.ios;
528
+ if (this.tabStrip && this.tabStrip.isIconSizeFixed) {
529
+ image = this.getFixedSizeIcon(image);
530
+ }
531
+ let renderingMode = 0;
532
+ if (!isFontIcon) {
533
+ renderingMode = this.getIconRenderingMode();
534
+ }
535
+ const originalRenderedImage = image.imageWithRenderingMode(renderingMode);
536
+ this.mIconsCache[iconTag] = originalRenderedImage;
537
+ image = originalRenderedImage;
538
+ }
539
+ }
540
+ return image;
541
+ }
542
+ getFixedSizeIcon(image) {
543
+ const inWidth = image.size.width;
544
+ const inHeight = image.size.height;
545
+ const iconSpecSize = getIconSpecSize({ width: inWidth, height: inHeight });
546
+ const widthPts = iconSpecSize.width;
547
+ const heightPts = iconSpecSize.height;
548
+ UIGraphicsBeginImageContextWithOptions({ width: widthPts, height: heightPts }, false, Utils.layout.getDisplayDensity());
549
+ image.drawInRect(CGRectMake(0, 0, widthPts, heightPts));
550
+ const resultImage = UIGraphicsGetImageFromCurrentImageContext();
551
+ UIGraphicsEndImageContext();
552
+ return resultImage;
553
+ }
554
+ getTabBarBackgroundColor() {
555
+ return this.viewController.tabBar.barTintColor;
556
+ }
557
+ setTabBarBackgroundColor(value) {
558
+ this.viewController.tabBar.barTintColor = value instanceof Color ? value.ios : value;
559
+ this.updateAllItemsColors();
560
+ }
561
+ setTabBarItemTitle(tabStripItem, value) {
562
+ const nativeView = tabStripItem.nativeView;
563
+ if (!nativeView) {
564
+ return;
565
+ }
566
+ nativeView.title = value;
567
+ }
568
+ equalUIColor(first, second) {
569
+ if (!first && !second) {
570
+ return true;
571
+ }
572
+ if (!first || !second) {
573
+ return false;
574
+ }
575
+ const firstComponents = CGColorGetComponents(first.CGColor);
576
+ const secondComponents = CGColorGetComponents(second.CGColor);
577
+ return firstComponents[0] === secondComponents[0] && firstComponents[1] === secondComponents[1] && firstComponents[2] === secondComponents[2] && firstComponents[3] === secondComponents[3];
578
+ }
579
+ isSelectedAndHightlightedItem(tabStripItem) {
580
+ return tabStripItem._index === this.selectedIndex && tabStripItem['_visualState'] === 'highlighted';
581
+ }
582
+ setTabBarItemBackgroundColor(tabStripItem, value) {
583
+ if (!this.tabStrip || !tabStripItem || !tabStripItem.nativeView) {
584
+ return;
585
+ }
586
+ const newColor = value instanceof Color ? value.ios : value;
587
+ const itemSelectedAndHighlighted = this.isSelectedAndHightlightedItem(tabStripItem);
588
+ if (!this.mDefaultItemBackgroundColor && !itemSelectedAndHighlighted) {
589
+ this.mDefaultItemBackgroundColor = newColor;
590
+ }
591
+ if (itemSelectedAndHighlighted && !this.equalUIColor(this.mDefaultItemBackgroundColor, newColor)) {
592
+ if (!this.mBackgroundIndicatorColor) {
593
+ this.mBackgroundIndicatorColor = newColor;
594
+ this.viewController.tabBar.selectionIndicatorTemplate = new BackgroundIndicatorTemplate();
595
+ this.viewController.tabBar.tintColor = newColor;
596
+ }
597
+ }
598
+ else {
599
+ updateBackgroundPositions(this.tabStrip, tabStripItem, newColor);
600
+ }
601
+ }
602
+ setTabBarItemColor(tabStripItem, value) {
603
+ this.setViewTextAttributes(tabStripItem.label);
604
+ }
605
+ setItemColors() {
606
+ if (this.mSelectedItemColor) {
607
+ this.viewController.tabBar.setTitleColorForState(this.mSelectedItemColor.ios, 4);
608
+ }
609
+ if (this.mUnSelectedItemColor) {
610
+ this.viewController.tabBar.setTitleColorForState(this.mUnSelectedItemColor.ios, 0);
611
+ }
612
+ }
613
+ setIconColor(tabStripItem, forceReload = false) {
614
+ const nativeView = tabStripItem.nativeView;
615
+ if (!nativeView) {
616
+ return;
617
+ }
618
+ if (!forceReload && !this.mSelectedItemColor && !this.mUnSelectedItemColor) {
619
+ return;
620
+ }
621
+ if (this.mSelectedItemColor) {
622
+ const image = this.getIcon(tabStripItem, this.mSelectedItemColor);
623
+ nativeView.selectedImage = image;
624
+ }
625
+ if (this.mUnSelectedItemColor) {
626
+ const image = this.getIcon(tabStripItem, this.mUnSelectedItemColor);
627
+ nativeView.image = image;
628
+ }
629
+ }
630
+ setTabBarIconColor(tabStripItem, value) {
631
+ this.setIconColor(tabStripItem, true);
632
+ }
633
+ setTabBarIconSource(tabStripItem, value) {
634
+ this.updateItemColors(tabStripItem);
635
+ }
636
+ setTabBarItemFontInternal(tabStripItem, value) {
637
+ this.setViewTextAttributes(tabStripItem.label);
638
+ }
639
+ getTabBarFontInternal() {
640
+ return this.viewController.tabBar.titleFontForState(0);
641
+ }
642
+ setTabBarFontInternal() {
643
+ const defaultTabItemFontSize = 10;
644
+ const tabItemFontSize = this.tabStrip.style.fontSize || defaultTabItemFontSize;
645
+ const font = (this.tabStrip.style.fontInternal || Font.default).getUIFont(UIFont.systemFontOfSize(tabItemFontSize));
646
+ this.viewController.tabBar.setTitleFontForState(font, 0);
647
+ this.viewController.tabBar.setTitleFontForState(font, 4);
648
+ }
649
+ getTabBarColor() {
650
+ return this.viewController.tabBar.titleColorForState(0);
651
+ }
652
+ setTabBarColor(value) {
653
+ const nativeColor = value instanceof Color ? value.ios : value;
654
+ this.viewController.tabBar.setTitleColorForState(nativeColor, 4);
655
+ this.viewController.tabBar.setImageTintColorForState(nativeColor, 4);
656
+ }
657
+ getTabBarHighlightColor() {
658
+ return this.mSelectionIndicatorColor;
659
+ }
660
+ setTabBarHighlightColor(value) {
661
+ this.mSelectionIndicatorColor = value;
662
+ this.viewController.tabBar.selectionIndicatorStrokeColor = value.ios;
663
+ }
664
+ getTabBarSelectedItemColor() {
665
+ return this.mSelectedItemColor;
666
+ }
667
+ setTabBarSelectedItemColor(value) {
668
+ this.mSelectedItemColor = value;
669
+ this.updateAllItemsColors();
670
+ }
671
+ getTabBarUnSelectedItemColor() {
672
+ return this.mUnSelectedItemColor;
673
+ }
674
+ setTabBarUnSelectedItemColor(value) {
675
+ this.mUnSelectedItemColor = value;
676
+ this.updateAllItemsColors();
677
+ }
678
+ visitFrames(view, operation) {
679
+ if (view instanceof Frame) {
680
+ operation(view);
681
+ }
682
+ view.eachChild((child) => {
683
+ this.visitFrames(child, operation);
684
+ return true;
685
+ });
686
+ }
687
+ setTabBarRippleColor(value) {
688
+ this.mRippleColor = value;
689
+ this.viewController.tabBar.rippleColor = value.ios;
690
+ }
691
+ getTabBarRippleColor() {
692
+ return this.mRippleColor;
693
+ }
694
+ [selectedIndexProperty.setNative](value) {
695
+ if (value > -1) {
696
+ const item = this.items[value];
697
+ const controllers = NSMutableArray.alloc().initWithCapacity(1);
698
+ const itemController = item.__controller;
699
+ controllers.addObject(itemController);
700
+ let navigationDirection = 0;
701
+ if (this.mCurrentNativeSelectedIndex && this.mCurrentNativeSelectedIndex > value) {
702
+ navigationDirection = 1;
703
+ }
704
+ this.mCurrentNativeSelectedIndex = value;
705
+ this.visitFrames(item, (frame) => (frame._animationInProgress = true));
706
+ const doneAnimating = () => {
707
+ this.visitFrames(item, (frame) => (frame._animationInProgress = false));
708
+ this.finishTabTransition();
709
+ this._setCanBeLoaded(value);
710
+ this._loadUnloadTabItems(value);
711
+ };
712
+ if (this.mAnimateNextChange) {
713
+ invokeOnRunLoop(() => {
714
+ this.viewController.setViewControllersDirectionAnimatedCompletion(controllers, navigationDirection, this.animationEnabled, (finished) => {
715
+ if (finished) {
716
+ if (this.animationEnabled) {
717
+ invokeOnRunLoop(() => {
718
+ doneAnimating();
719
+ });
720
+ }
721
+ else {
722
+ doneAnimating();
723
+ }
724
+ }
725
+ });
726
+ });
727
+ }
728
+ else {
729
+ this.mAnimateNextChange = true;
730
+ doneAnimating();
731
+ }
732
+ if (this.tabBarItems && this.tabBarItems.length && this.viewController && this.viewController.tabBar) {
733
+ this.viewController.tabBar.setSelectedItemAnimated(this.tabBarItems[value], this.animationEnabled);
734
+ }
735
+ }
736
+ }
737
+ [itemsProperty.getDefault]() {
738
+ return null;
739
+ }
740
+ [itemsProperty.setNative](value) {
741
+ if (value) {
742
+ value.forEach((item, i) => {
743
+ item.index = i;
744
+ });
745
+ }
746
+ this.setViewControllers(value);
747
+ selectedIndexProperty.coerce(this);
748
+ }
749
+ [tabStripProperty.getDefault]() {
750
+ return null;
751
+ }
752
+ [tabStripProperty.setNative](value) {
753
+ this.setViewControllers(this.items);
754
+ selectedIndexProperty.coerce(this);
755
+ }
756
+ [swipeEnabledProperty.getDefault]() {
757
+ return true;
758
+ }
759
+ [swipeEnabledProperty.setNative](value) {
760
+ if (this.viewController && this.viewController.scrollView) {
761
+ this.viewController.scrollView.scrollEnabled = value;
762
+ }
763
+ }
764
+ setViewTextAttributes(view, setSelected = false) {
765
+ if (!view) {
766
+ return null;
767
+ }
768
+ const defaultTabItemFontSize = 10;
769
+ const tabItemFontSize = view.style.fontSize || defaultTabItemFontSize;
770
+ const font = (view.style.fontInternal || Font.default).getUIFont(UIFont.systemFontOfSize(tabItemFontSize));
771
+ this.viewController.tabBar.setTitleFontForState(font, 0);
772
+ this.viewController.tabBar.setTitleFontForState(font, 4);
773
+ const tabItemTextColor = view.style.color;
774
+ const textColor = tabItemTextColor instanceof Color ? tabItemTextColor.ios : null;
775
+ if (textColor) {
776
+ this.viewController.tabBar.setTitleColorForState(textColor, 0);
777
+ this.viewController.tabBar.setImageTintColorForState(textColor, 0);
778
+ if (setSelected) {
779
+ this.viewController.tabBar.setTitleColorForState(textColor, 4);
780
+ this.viewController.tabBar.setImageTintColorForState(textColor, 4);
781
+ }
782
+ }
783
+ if (this.mSelectedItemColor) {
784
+ this.viewController.tabBar.setTitleColorForState(this.mSelectedItemColor.ios, 4);
785
+ this.viewController.tabBar.setImageTintColorForState(this.mSelectedItemColor.ios, 4);
786
+ }
787
+ if (this.mUnSelectedItemColor) {
788
+ this.viewController.tabBar.setTitleColorForState(this.mUnSelectedItemColor.ios, 0);
789
+ this.viewController.tabBar.setImageTintColorForState(this.mUnSelectedItemColor.ios, 4);
790
+ }
791
+ }
792
+ }
793
+ iosCustomPositioningProperty.register(TabNavigation);
794
+ //# sourceMappingURL=index.ios.js.map