@nativescript-community/ui-material-core-tabs 7.2.18 → 7.2.20

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 (33) hide show
  1. package/package.json +3 -3
  2. package/react/index.d.ts +60 -0
  3. package/react/index.js +124 -0
  4. package/react/index.js.map +1 -0
  5. package/tab-content-item/index.android.d.ts +15 -0
  6. package/tab-content-item/index.android.js +55 -0
  7. package/tab-content-item/index.android.js.map +1 -0
  8. package/tab-content-item/index.d.ts +13 -0
  9. package/tab-content-item/index.ios.d.ts +7 -0
  10. package/tab-content-item/index.ios.js +14 -0
  11. package/tab-content-item/index.ios.js.map +1 -0
  12. package/tab-content-item/tab-content-item-common.d.ts +7 -0
  13. package/tab-content-item/tab-content-item-common.js +21 -0
  14. package/tab-content-item/tab-content-item-common.js.map +1 -0
  15. package/tab-navigation/index-common.d.ts +27 -0
  16. package/tab-navigation/index-common.js +95 -0
  17. package/tab-navigation/index-common.js.map +1 -0
  18. package/tab-navigation/index.android.d.ts +75 -0
  19. package/tab-navigation/index.android.js +607 -0
  20. package/tab-navigation/index.android.js.map +1 -0
  21. package/tab-navigation/index.d.ts +80 -0
  22. package/tab-navigation/index.ios.d.ts +95 -0
  23. package/tab-navigation/index.ios.js +890 -0
  24. package/tab-navigation/index.ios.js.map +1 -0
  25. package/tab-navigation-base/index.d.ts +87 -0
  26. package/tab-navigation-base/index.js +302 -0
  27. package/tab-navigation-base/index.js.map +1 -0
  28. package/tab-strip/index.d.ts +29 -0
  29. package/tab-strip/index.js +164 -0
  30. package/tab-strip/index.js.map +1 -0
  31. package/tab-strip-item/index.d.ts +39 -0
  32. package/tab-strip-item/index.js +230 -0
  33. package/tab-strip-item/index.js.map +1 -0
@@ -0,0 +1,890 @@
1
+ /**
2
+ * @module @nativescript-community/ui-material-core-tabs/tab-navigation
3
+ */
4
+ import { Color, CoreTypes, Device, Font, Frame, IOSHelper, ImageAsset, ImageSource, Property, Utils, View, ViewBase, booleanConverter, getTransformedText } from '@nativescript/core';
5
+ import { TabContentItem } from '../tab-content-item';
6
+ import { getIconSpecSize, itemsProperty, selectedIndexProperty, tabStripProperty } from '../tab-navigation-base';
7
+ import { TabStrip } from '../tab-strip';
8
+ import { TabStripItem } from '../tab-strip-item';
9
+ import { TabNavigationBase, swipeEnabledProperty } from './index-common';
10
+ import { getRippleColor } from '@nativescript-community/ui-material-core';
11
+ export { TabContentItem, TabStrip, TabStripItem };
12
+ // import { profile } from "../../profiling";
13
+ const majorVersion = Utils.ios.MajorVersion;
14
+ const isPhone = Device.deviceType === 'Phone';
15
+ // Equivalent to dispatch_async(dispatch_get_main_queue(...)) call
16
+ const invokeOnRunLoop = (function () {
17
+ const runloop = CFRunLoopGetMain();
18
+ return (action) => {
19
+ CFRunLoopPerformBlock(runloop, kCFRunLoopDefaultMode, action);
20
+ CFRunLoopWakeUp(runloop);
21
+ };
22
+ })();
23
+ var BackgroundIndicatorTemplate = /** @class */ (function (_super) {
24
+ __extends(BackgroundIndicatorTemplate, _super);
25
+ function BackgroundIndicatorTemplate() {
26
+ return _super !== null && _super.apply(this, arguments) || this;
27
+ }
28
+ BackgroundIndicatorTemplate.prototype.indicatorAttributesForContext = function (context) {
29
+ var attributes = new MDCTabBarViewIndicatorAttributes();
30
+ attributes.path = UIBezierPath.bezierPathWithRect(context.bounds);
31
+ return attributes;
32
+ };
33
+ BackgroundIndicatorTemplate.ObjCProtocols = [MDCTabBarViewIndicatorTemplate];
34
+ return BackgroundIndicatorTemplate;
35
+ }(NSObject));
36
+ var UIPageViewControllerDataSourceImpl = /** @class */ (function (_super) {
37
+ __extends(UIPageViewControllerDataSourceImpl, _super);
38
+ function UIPageViewControllerDataSourceImpl() {
39
+ return _super !== null && _super.apply(this, arguments) || this;
40
+ }
41
+ UIPageViewControllerDataSourceImpl.initWithOwner = function (owner) {
42
+ var dataSource = UIPageViewControllerDataSourceImpl.new();
43
+ dataSource._owner = owner;
44
+ return dataSource;
45
+ };
46
+ UIPageViewControllerDataSourceImpl.prototype.pageViewControllerViewControllerBeforeViewController = function (pageViewController, viewController) {
47
+ // if (traceEnabled()) {
48
+ // traceWrite("TabView.delegate.SHOULD_select(" + tabBarController + ", " + viewController + ");", traceCategories.Debug);
49
+ // }
50
+ var owner = this._owner.get();
51
+ var selectedIndex = owner.selectedIndex;
52
+ if (selectedIndex === 0) {
53
+ return null;
54
+ }
55
+ selectedIndex--;
56
+ var prevItem = owner.items[selectedIndex];
57
+ var prevViewController = prevItem.__controller;
58
+ // if (!prevViewController) {
59
+ // prevViewController = owner.getViewController(prevItem);
60
+ // }
61
+ owner._setCanBeLoaded(selectedIndex);
62
+ owner._loadUnloadTabItems(selectedIndex);
63
+ return prevViewController;
64
+ };
65
+ UIPageViewControllerDataSourceImpl.prototype.pageViewControllerViewControllerAfterViewController = function (pageViewController, viewController) {
66
+ // if (Trace.isEnabled()) {
67
+ // traceWrite('TabView.delegate.SHOULD_select(' + tabBarController + ', ' + viewController + ');', traceCategories.Debug);
68
+ // }
69
+ var owner = this._owner.get();
70
+ var selectedIndex = owner.selectedIndex;
71
+ if (selectedIndex === owner.items.length - 1) {
72
+ return null;
73
+ }
74
+ selectedIndex++;
75
+ var nextItem = owner.items[selectedIndex];
76
+ var nextViewController = nextItem.__controller;
77
+ // if (!nextViewController) {
78
+ // nextViewController = owner.getViewController(nextItem);
79
+ // }
80
+ owner._setCanBeLoaded(selectedIndex);
81
+ owner._loadUnloadTabItems(selectedIndex);
82
+ // nextItem.loadView(nextItem.view);
83
+ return nextViewController;
84
+ };
85
+ UIPageViewControllerDataSourceImpl.prototype.presentationCountForPageViewController = function (pageViewController) {
86
+ // TODO
87
+ // if (traceEnabled()) {
88
+ // traceWrite("TabView.delegate.SHOULD_select(" + tabBarController + ", " + viewController + ");", traceCategories.Debug);
89
+ // }
90
+ return 0;
91
+ };
92
+ UIPageViewControllerDataSourceImpl.prototype.presentationIndexForPageViewController = function (pageViewController) {
93
+ // TODO
94
+ // if (traceEnabled()) {
95
+ // traceWrite("TabView.delegate.SHOULD_select(" + tabBarController + ", " + viewController + ");", traceCategories.Debug);
96
+ // }
97
+ return 0;
98
+ };
99
+ UIPageViewControllerDataSourceImpl.ObjCProtocols = [UIPageViewControllerDataSource];
100
+ return UIPageViewControllerDataSourceImpl;
101
+ }(NSObject));
102
+ var UIPageViewControllerDelegateImpl = /** @class */ (function (_super) {
103
+ __extends(UIPageViewControllerDelegateImpl, _super);
104
+ function UIPageViewControllerDelegateImpl() {
105
+ return _super !== null && _super.apply(this, arguments) || this;
106
+ }
107
+ UIPageViewControllerDelegateImpl.initWithOwner = function (owner) {
108
+ var delegate = UIPageViewControllerDelegateImpl.new();
109
+ delegate._owner = owner;
110
+ return delegate;
111
+ };
112
+ UIPageViewControllerDelegateImpl.prototype.pageViewControllerWillTransitionToViewControllers = function (pageViewController, viewControllers) {
113
+ // const owner = this._owner.get();
114
+ // const ownerViewControllers = owner.viewControllers;
115
+ // const selectedIndex = owner.selectedIndex;
116
+ // const nextViewController = viewControllers[0];
117
+ // const nextViewControllerIndex = ownerViewControllers.indexOf(nextViewController);
118
+ // if (selectedIndex > nextViewControllerIndex) {
119
+ // owner.selectedIndex--;
120
+ // } else {
121
+ // owner.selectedIndex++;
122
+ // }
123
+ };
124
+ UIPageViewControllerDelegateImpl.prototype.pageViewControllerDidFinishAnimatingPreviousViewControllersTransitionCompleted = function (pageViewController, didFinishAnimating, previousViewControllers, transitionCompleted) {
125
+ if (!transitionCompleted) {
126
+ return;
127
+ }
128
+ var owner = this._owner.get();
129
+ var ownerViewControllers = owner.viewControllers;
130
+ var selectedIndex = owner.selectedIndex;
131
+ var nextViewController = pageViewController.viewControllers[0];
132
+ var nextViewControllerIndex = ownerViewControllers.indexOf(nextViewController);
133
+ if (selectedIndex !== nextViewControllerIndex) {
134
+ // let s not animate again on selectedIndex change
135
+ // or it will create weird behaviors
136
+ owner.mAnimateNextChange = false;
137
+ owner.selectedIndex = nextViewControllerIndex;
138
+ owner.finishTabTransition();
139
+ }
140
+ // HACK: UIPageViewController fix; see https://stackoverflow.com/questions/15325891
141
+ if (owner.mNeedsCacheUpdate) {
142
+ invokeOnRunLoop(function () {
143
+ owner.mNeedsCacheUpdate = false;
144
+ var viewController = owner.viewController;
145
+ viewController.dataSource = null;
146
+ viewController.dataSource = owner._dataSource;
147
+ });
148
+ }
149
+ };
150
+ UIPageViewControllerDelegateImpl.ObjCProtocols = [UIPageViewControllerDelegate];
151
+ return UIPageViewControllerDelegateImpl;
152
+ }(NSObject));
153
+ function iterateIndexRange(index, eps, lastIndex, callback) {
154
+ const rangeStart = Math.max(0, index - eps);
155
+ const rangeEnd = Math.min(index + eps, lastIndex);
156
+ for (let i = rangeStart; i <= rangeEnd; i++) {
157
+ callback(i);
158
+ }
159
+ }
160
+ export function updateBackgroundPositions(tabStrip, tabStripItem, color = null) {
161
+ if (!tabStrip.nativeView || tabStripItem.index === undefined) {
162
+ return;
163
+ }
164
+ let bgView = tabStripItem.bgView;
165
+ const index = tabStripItem.index;
166
+ const width = tabStrip.nativeView.frame.size.width / tabStrip.items.filter((s) => s.index !== undefined).length;
167
+ const frame = CGRectMake(width * index, 0, width, tabStrip.nativeView.frame.size.width);
168
+ if (!bgView) {
169
+ bgView = UIView.alloc().initWithFrame(frame);
170
+ tabStrip.nativeView.insertSubviewAtIndex(bgView, 0);
171
+ tabStripItem.bgView = bgView;
172
+ }
173
+ else {
174
+ bgView.frame = frame;
175
+ }
176
+ const backgroundColor = tabStripItem.style.backgroundColor;
177
+ bgView.backgroundColor = color || (backgroundColor instanceof Color ? backgroundColor.ios : backgroundColor);
178
+ }
179
+ export function updateTitleAndIconPositions(tabStripItem, tabBarItem, controller) {
180
+ if (!tabStripItem || !tabBarItem) {
181
+ return;
182
+ }
183
+ // For iOS <11 icon is *always* above the text.
184
+ // For iOS 11 icon is above the text *only* on phones in portrait mode.
185
+ const orientation = controller.interfaceOrientation;
186
+ const isPortrait = orientation !== 4 /* UIInterfaceOrientation.LandscapeLeft */ && orientation !== 3 /* UIInterfaceOrientation.LandscapeRight */;
187
+ const isIconAboveTitle = majorVersion < 11 || (isPhone && isPortrait);
188
+ if (!tabStripItem.iconSource) {
189
+ if (isIconAboveTitle) {
190
+ tabBarItem.titlePositionAdjustment = { horizontal: 0, vertical: -20 };
191
+ }
192
+ else {
193
+ tabBarItem.titlePositionAdjustment = { horizontal: 0, vertical: 0 };
194
+ }
195
+ }
196
+ if (!tabStripItem.title) {
197
+ if (isIconAboveTitle) {
198
+ tabBarItem.imageInsets = new UIEdgeInsets({ top: 6, left: 0, bottom: -6, right: 0 });
199
+ }
200
+ else {
201
+ tabBarItem.imageInsets = new UIEdgeInsets({ top: 0, left: 0, bottom: 0, right: 0 });
202
+ }
203
+ }
204
+ }
205
+ export const iosCustomPositioningProperty = new Property({
206
+ name: 'iosCustomPositioning',
207
+ defaultValue: false,
208
+ valueConverter: booleanConverter
209
+ });
210
+ export class TabNavigation extends TabNavigationBase {
211
+ constructor() {
212
+ super();
213
+ // private _moreNavigationControllerDelegate: UINavigationControllerDelegateImpl;
214
+ this.mIconsCache = {};
215
+ this.mNeedsCacheUpdate = false;
216
+ this.mAnimateNextChange = true;
217
+ this.mLayoutPending = false;
218
+ this.viewController = this.createViewController();
219
+ }
220
+ createNativeView() {
221
+ return this.viewController.view;
222
+ }
223
+ initNativeView() {
224
+ super.initNativeView();
225
+ this.mDataSource = UIPageViewControllerDataSourceImpl.initWithOwner(new WeakRef(this));
226
+ this.mDelegate = UIPageViewControllerDelegateImpl.initWithOwner(new WeakRef(this));
227
+ }
228
+ disposeNativeView() {
229
+ this.mDataSource = null;
230
+ this.mDelegate = null;
231
+ super.disposeNativeView();
232
+ }
233
+ requestLayout() {
234
+ if (!this.mCanSelectItem) {
235
+ this.mLayoutPending = true;
236
+ }
237
+ else {
238
+ this.mLayoutPending = false;
239
+ super.requestLayout();
240
+ }
241
+ }
242
+ beginTabTransition() {
243
+ this.mCanSelectItem = false;
244
+ }
245
+ finishTabTransition() {
246
+ this.mCanSelectItem = true;
247
+ if (this.mLayoutPending) {
248
+ this.requestLayout();
249
+ }
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.viewController.dataSource = this.mDataSource;
260
+ this.viewController.delegate = this.mDelegate;
261
+ }
262
+ onUnloaded() {
263
+ this.viewController.dataSource = null;
264
+ this.viewController.delegate = null;
265
+ super.onUnloaded();
266
+ this.items.forEach((item, i) => {
267
+ item.unloadView(item.content);
268
+ });
269
+ }
270
+ //@ts-ignore
271
+ get ios() {
272
+ return this.viewController;
273
+ }
274
+ layoutNativeView(left, top, right, bottom) {
275
+ if (this.iosCustomPositioning) {
276
+ super.layoutNativeView(left, top, right, bottom);
277
+ }
278
+ }
279
+ _setNativeViewFrame(nativeView, frame) {
280
+ if (this.iosCustomPositioning) {
281
+ super._setNativeViewFrame(nativeView, frame);
282
+ }
283
+ }
284
+ onSelectedIndexChanged(oldIndex, newIndex) {
285
+ const items = this.items;
286
+ if (!items) {
287
+ return;
288
+ }
289
+ const oldItem = items[oldIndex];
290
+ if (this.unloadOnTabChange && oldItem) {
291
+ oldItem.canBeLoaded = false;
292
+ oldItem.unloadView(oldItem.content);
293
+ }
294
+ const newItem = items[newIndex];
295
+ if (newItem && this.isLoaded) {
296
+ const selectedView = items[newIndex].content;
297
+ if (selectedView instanceof Frame) {
298
+ selectedView._pushInFrameStackRecursive();
299
+ }
300
+ newItem.canBeLoaded = true;
301
+ newItem.loadView(newItem.content);
302
+ }
303
+ const tabStripItems = this.tabStrip && this.tabStrip.items;
304
+ if (tabStripItems) {
305
+ const newItem = tabStripItems[newIndex];
306
+ if (newItem) {
307
+ newItem._emit(TabStripItem.selectEvent);
308
+ this.updateItemColors(newItem);
309
+ }
310
+ const oldItem = tabStripItems[oldIndex];
311
+ if (oldItem) {
312
+ oldItem._emit(TabStripItem.unselectEvent);
313
+ this.updateItemColors(oldItem);
314
+ }
315
+ }
316
+ this._loadUnloadTabItems(newIndex);
317
+ super.onSelectedIndexChanged(oldIndex, newIndex);
318
+ }
319
+ onMeasure(widthMeasureSpec, heightMeasureSpec) {
320
+ const width = Utils.layout.getMeasureSpecSize(widthMeasureSpec);
321
+ const widthMode = Utils.layout.getMeasureSpecMode(widthMeasureSpec);
322
+ const height = Utils.layout.getMeasureSpecSize(heightMeasureSpec);
323
+ const heightMode = Utils.layout.getMeasureSpecMode(heightMeasureSpec);
324
+ const widthAndState = View.resolveSizeAndState(width, width, widthMode, 0);
325
+ const heightAndState = View.resolveSizeAndState(height, height, heightMode, 0);
326
+ this.setMeasuredDimension(widthAndState, heightAndState);
327
+ }
328
+ _onViewControllerShown(viewController) {
329
+ if (this.viewController.viewControllers && this.viewController.viewControllers.containsObject(viewController)) {
330
+ this.selectedIndex = this.viewController.viewControllers.indexOfObject(viewController);
331
+ }
332
+ }
333
+ getViewController(item) {
334
+ let newController = item.content ? item.content.viewController : null;
335
+ if (newController) {
336
+ item.setViewController(newController, newController.view);
337
+ return newController;
338
+ }
339
+ if (item.content.ios instanceof UIViewController) {
340
+ newController = item.content.ios;
341
+ item.setViewController(newController, newController.view);
342
+ }
343
+ else if (item.content.ios && item.content.ios.controller instanceof UIViewController) {
344
+ newController = item.content.ios.controller;
345
+ item.setViewController(newController, newController.view);
346
+ }
347
+ else {
348
+ newController = IOSHelper.UILayoutViewController.initWithOwner(new WeakRef(item.content));
349
+ newController.view.addSubview(item.content.nativeViewProtected);
350
+ item.content.viewController = newController;
351
+ item.setViewController(newController, item.content.nativeViewProtected);
352
+ }
353
+ return newController;
354
+ }
355
+ _setCanBeLoaded(index) {
356
+ const items = this.items;
357
+ if (!this.items) {
358
+ return;
359
+ }
360
+ const lastIndex = items.length - 1;
361
+ const offsideItems = this.offscreenTabLimit;
362
+ iterateIndexRange(index, offsideItems, lastIndex, (i) => {
363
+ if (items[i]) {
364
+ items[i].canBeLoaded = true;
365
+ }
366
+ });
367
+ }
368
+ setViewControllers(items) {
369
+ const length = items ? items.length : 0;
370
+ if (length === 0) {
371
+ this.viewControllers = null;
372
+ return;
373
+ }
374
+ const viewControllers = [];
375
+ const tabBarItems = [];
376
+ if (this.tabStrip) {
377
+ this.tabStrip.setNativeView(this.viewController.tabBar);
378
+ }
379
+ const tabStripItems = this.tabStrip && this.tabStrip.items;
380
+ if (tabStripItems) {
381
+ if (tabStripItems[this.selectedIndex]) {
382
+ tabStripItems[this.selectedIndex]._emit(TabStripItem.selectEvent);
383
+ }
384
+ }
385
+ items.forEach((item, i) => {
386
+ const controller = this.getViewController(item);
387
+ if (this.tabStrip && this.tabStrip.items && this.tabStrip.items[i]) {
388
+ const tabStripItem = this.tabStrip.items[i];
389
+ const tabBarItem = this.createTabBarItem(tabStripItem, i);
390
+ updateTitleAndIconPositions(tabStripItem, tabBarItem, controller);
391
+ this.setViewTextAttributes(tabStripItem.label, i === this.selectedIndex);
392
+ controller.tabBarItem = tabBarItem;
393
+ tabStripItem.index = i;
394
+ tabBarItems.push(tabBarItem);
395
+ tabStripItem.setNativeView(tabBarItem);
396
+ }
397
+ item.canBeLoaded = true;
398
+ viewControllers.push(controller);
399
+ });
400
+ this.setItemImages();
401
+ this.viewControllers = viewControllers;
402
+ this.tabBarItems = tabBarItems;
403
+ if (this.viewController && this.viewController.tabBar) {
404
+ // this.viewController.tabBar.itemAppearance = this.getTabBarItemAppearance();
405
+ this.viewController.tabBar.items = NSArray.arrayWithArray(this.tabBarItems);
406
+ // TODO: investigate why this call is necessary to actually toggle item appearance
407
+ this.viewController.tabBar.sizeToFit();
408
+ // if (this.selectedIndex) {
409
+ this.viewController.tabBar.setSelectedItemAnimated(this.tabBarItems[this.selectedIndex], false);
410
+ // }
411
+ }
412
+ }
413
+ onItemsChanged(oldItems, newItems) {
414
+ if (this.isLoaded) {
415
+ this.mNeedsCacheUpdate = true;
416
+ }
417
+ super.onItemsChanged(oldItems, newItems);
418
+ if (oldItems) {
419
+ if (!this.mCanSelectItem) {
420
+ this.finishTabTransition();
421
+ }
422
+ this._setCanBeLoaded(this.selectedIndex);
423
+ this._loadUnloadTabItems(this.selectedIndex);
424
+ }
425
+ }
426
+ setItemImages() {
427
+ if (this.mSelectedItemColor || this.mUnSelectedItemColor) {
428
+ if (this.tabStrip && this.tabStrip.items) {
429
+ this.tabStrip.items.forEach((item) => {
430
+ if (this.mUnSelectedItemColor && item.nativeView) {
431
+ item.nativeView.image = this.getIcon(item, this.mUnSelectedItemColor);
432
+ }
433
+ if (this.mSelectedItemColor && item.nativeView) {
434
+ if (this.selectedIndex === item.index) {
435
+ item.nativeView.image = this.getIcon(item, this.mSelectedItemColor);
436
+ }
437
+ }
438
+ });
439
+ }
440
+ }
441
+ }
442
+ updateAllItemsColors() {
443
+ this.mDefaultItemBackgroundColor = null;
444
+ this.setItemColors();
445
+ if (this.tabStrip && this.tabStrip.items) {
446
+ this.tabStrip.items.forEach((tabStripItem) => {
447
+ this.updateItemColors(tabStripItem);
448
+ });
449
+ }
450
+ }
451
+ updateItemColors(tabStripItem) {
452
+ updateBackgroundPositions(this.tabStrip, tabStripItem);
453
+ this.setIconColor(tabStripItem, true);
454
+ }
455
+ createTabBarItem(item, index) {
456
+ let image;
457
+ let title;
458
+ if (item.isLoaded) {
459
+ image = this.getIcon(item);
460
+ title = item.label.text;
461
+ if (!this.tabStrip._hasImage) {
462
+ this.tabStrip._hasImage = !!image;
463
+ }
464
+ if (!this.tabStrip._hasTitle) {
465
+ // TEXT-TRANSFORM
466
+ const textTransform = this.getItemLabelTextTransform(item);
467
+ title = getTransformedText(title, textTransform);
468
+ this.tabStrip._hasTitle = !!title;
469
+ }
470
+ }
471
+ const tabBarItem = UITabBarItem.alloc().initWithTitleImageTag(title, image, index);
472
+ return tabBarItem;
473
+ }
474
+ // private getTabBarItemAppearance(): MDCTabBarViewItemAppearance {
475
+ // let itemAppearance;
476
+ // if (this.tabStrip && this.tabStrip._hasImage && this.tabStrip._hasTitle) {
477
+ // itemAppearance = MDCTabBarViewItemAppearance.TitledImages;
478
+ // } else if (this.tabStrip && this.tabStrip._hasImage) {
479
+ // itemAppearance = MDCTabBarViewItemAppearance.Images;
480
+ // } else {
481
+ // itemAppearance = MDCTabBarViewItemAppearance.Titles;
482
+ // }
483
+ // return itemAppearance;
484
+ // }
485
+ getIconRenderingMode() {
486
+ switch (this.tabStrip && this.tabStrip.iosIconRenderingMode) {
487
+ case 'alwaysOriginal':
488
+ return 1 /* UIImageRenderingMode.AlwaysOriginal */;
489
+ case 'alwaysTemplate':
490
+ return 2 /* UIImageRenderingMode.AlwaysTemplate */;
491
+ case 'automatic':
492
+ default:
493
+ const hasItemColor = this.mSelectedItemColor || this.mUnSelectedItemColor;
494
+ return hasItemColor ? 2 /* UIImageRenderingMode.AlwaysTemplate */ : 1 /* UIImageRenderingMode.AlwaysOriginal */;
495
+ }
496
+ }
497
+ getIcon(tabStripItem, color) {
498
+ // Image and Label children of TabStripItem
499
+ // take priority over its `iconSource` and `title` properties
500
+ const iconSource = tabStripItem.image && tabStripItem.image.src;
501
+ if (!iconSource) {
502
+ return null;
503
+ }
504
+ const target = tabStripItem.image;
505
+ const font = target.style.fontInternal || Font.default;
506
+ if (!color) {
507
+ color = target.style.color;
508
+ }
509
+ const iconTag = [iconSource, font.fontStyle, font.fontWeight, font.fontSize, font.fontFamily, color].join(';');
510
+ const isFontIcon = false;
511
+ let image = this.mIconsCache[iconTag];
512
+ if (!image) {
513
+ let is;
514
+ if (typeof iconSource === 'string') {
515
+ if (Utils.isFontIconURI(iconSource)) {
516
+ const fontIconCode = iconSource.split('//')[1];
517
+ const target = tabStripItem.image ? tabStripItem.image : tabStripItem;
518
+ const font = target.style.fontInternal;
519
+ if (!color) {
520
+ color = target.style.color;
521
+ }
522
+ is = ImageSource.fromFontIconCodeSync(fontIconCode, font, color);
523
+ }
524
+ else {
525
+ is = ImageSource.fromFileOrResourceSync(iconSource);
526
+ }
527
+ }
528
+ else {
529
+ is = iconSource;
530
+ }
531
+ image = is?.ios;
532
+ if (image) {
533
+ if (this.tabStrip && this.tabStrip.isIconSizeFixed) {
534
+ image = this.getFixedSizeIcon(image);
535
+ }
536
+ let renderingMode = 0 /* UIImageRenderingMode.Automatic */;
537
+ if (!isFontIcon) {
538
+ renderingMode = this.getIconRenderingMode();
539
+ }
540
+ const originalRenderedImage = image.imageWithRenderingMode(renderingMode);
541
+ this.mIconsCache[iconTag] = originalRenderedImage;
542
+ image = originalRenderedImage;
543
+ }
544
+ }
545
+ return image;
546
+ }
547
+ getFixedSizeIcon(image) {
548
+ const inWidth = image.size.width;
549
+ const inHeight = image.size.height;
550
+ const iconSpecSize = getIconSpecSize({ width: inWidth, height: inHeight });
551
+ const widthPts = iconSpecSize.width;
552
+ const heightPts = iconSpecSize.height;
553
+ UIGraphicsBeginImageContextWithOptions({ width: widthPts, height: heightPts }, false, Utils.layout.getDisplayDensity());
554
+ image.drawInRect(CGRectMake(0, 0, widthPts, heightPts));
555
+ const resultImage = UIGraphicsGetImageFromCurrentImageContext();
556
+ UIGraphicsEndImageContext();
557
+ return resultImage;
558
+ }
559
+ getTabBarBackgroundColor() {
560
+ return this.viewController.tabBar.barTintColor;
561
+ }
562
+ setTabBarBackgroundColor(value) {
563
+ this.viewController.tabBar.barTintColor = value instanceof Color ? value.ios : value;
564
+ this.updateAllItemsColors();
565
+ }
566
+ setTabBarItemTitle(tabStripItem, value) {
567
+ const nativeView = tabStripItem.nativeView;
568
+ if (!nativeView) {
569
+ return;
570
+ }
571
+ const textTransform = this.getItemLabelTextTransform(tabStripItem);
572
+ nativeView.title = getTransformedText(value, textTransform);
573
+ }
574
+ setTabBarItemTextTransform(tabStripItem, value) {
575
+ const nativeView = tabStripItem.nativeView;
576
+ if (!nativeView) {
577
+ return;
578
+ }
579
+ const nestedLabel = tabStripItem.label;
580
+ const title = getTransformedText(nestedLabel.text, value);
581
+ nativeView.title = title;
582
+ }
583
+ setTabBarTextTransform(value) {
584
+ const items = this.tabStrip && this.tabStrip.items;
585
+ if (items) {
586
+ items.forEach((tabStripItem) => {
587
+ if (tabStripItem.label && tabStripItem.nativeViewProtected) {
588
+ const nestedLabel = tabStripItem.label;
589
+ const title = getTransformedText(nestedLabel.text, value);
590
+ tabStripItem.nativeViewProtected.title = title;
591
+ }
592
+ });
593
+ }
594
+ this.mTextTransform = value;
595
+ }
596
+ equalUIColor(first, second) {
597
+ if (!first && !second) {
598
+ return true;
599
+ }
600
+ if (!first || !second) {
601
+ return false;
602
+ }
603
+ const firstComponents = CGColorGetComponents(first.CGColor);
604
+ const secondComponents = CGColorGetComponents(second.CGColor);
605
+ return firstComponents[0] === secondComponents[0] && firstComponents[1] === secondComponents[1] && firstComponents[2] === secondComponents[2] && firstComponents[3] === secondComponents[3];
606
+ }
607
+ isSelectedAndHightlightedItem(tabStripItem) {
608
+ // to find out whether the current tab strip item is active (has style with :active selector applied)
609
+ // we need to check whether its _visualState is equal to "highlighted" as when changing tabs
610
+ // we first go through setTabBarItemBackgroundColor thice, once before setting the "highlighted" state
611
+ // and once after that, but if the "highlighted" state is not set we cannot get the backgroundColor
612
+ // set using :active selector
613
+ return tabStripItem.index === this.selectedIndex && tabStripItem['_visualState'] === 'highlighted';
614
+ }
615
+ setTabBarItemBackgroundColor(tabStripItem, value) {
616
+ if (!this.tabStrip || !tabStripItem || !tabStripItem.nativeView) {
617
+ return;
618
+ }
619
+ const newColor = value instanceof Color ? value.ios : value;
620
+ const itemSelectedAndHighlighted = this.isSelectedAndHightlightedItem(tabStripItem);
621
+ // As we cannot implement selected item background color in Tabs we are using the Indicator for this
622
+ // To be able to detect that there are two different background colors (one for selected and one for not selected item)
623
+ // we are checking whether the current item is not selected and higlighted and we store the value of its
624
+ // background color to _defaultItemBackgroundColor and later if we need to process a selected and highlighted item
625
+ // we are comparing it's backgroun color to the default one and if there's a difference
626
+ // we are changing the selectionIndicatorTemplate from underline to the whole item
627
+ // in that mode we are not able to show the indicator as it is used for the background of the selected item
628
+ if (!this.mDefaultItemBackgroundColor && !itemSelectedAndHighlighted) {
629
+ this.mDefaultItemBackgroundColor = newColor;
630
+ }
631
+ if (itemSelectedAndHighlighted && !this.equalUIColor(this.mDefaultItemBackgroundColor, newColor)) {
632
+ if (!this.mBackgroundIndicatorColor) {
633
+ this.mBackgroundIndicatorColor = newColor;
634
+ this.viewController.tabBar.selectionIndicatorTemplate = new BackgroundIndicatorTemplate();
635
+ this.viewController.tabBar.tintColor = newColor;
636
+ }
637
+ }
638
+ else {
639
+ updateBackgroundPositions(this.tabStrip, tabStripItem, newColor);
640
+ }
641
+ }
642
+ setTabBarItemColor(tabStripItem, value) {
643
+ this.setViewTextAttributes(tabStripItem.label);
644
+ }
645
+ setItemColors() {
646
+ if (this.mSelectedItemColor) {
647
+ this.viewController.tabBar.setImageTintColorForState(this.mSelectedItemColor.ios, 4 /* UIControlState.Selected */);
648
+ this.viewController.tabBar.setTitleColorForState(this.mSelectedItemColor.ios, 4 /* UIControlState.Selected */);
649
+ }
650
+ if (this.mUnSelectedItemColor) {
651
+ this.viewController.tabBar.setImageTintColorForState(this.mUnSelectedItemColor.ios, 0 /* UIControlState.Normal */);
652
+ this.viewController.tabBar.setTitleColorForState(this.mUnSelectedItemColor.ios, 0 /* UIControlState.Normal */);
653
+ }
654
+ }
655
+ setIconColor(tabStripItem, forceReload = false) {
656
+ const nativeView = tabStripItem.nativeView;
657
+ if (nativeView && (forceReload || (!this.mUnSelectedItemColor && !this.mSelectedItemColor))) {
658
+ // if selectedItemColor or unSelectedItemColor is set we don't respect the color from the style
659
+ const tabStripColor = this.selectedIndex === tabStripItem.index ? this.mSelectedItemColor : this.mUnSelectedItemColor;
660
+ const image = this.getIcon(tabStripItem, tabStripColor);
661
+ nativeView.image = image;
662
+ nativeView.selectedImage = image;
663
+ }
664
+ }
665
+ setTabBarIconColor(tabStripItem, value) {
666
+ this.setIconColor(tabStripItem, true);
667
+ }
668
+ setTabBarIconSource(tabStripItem, value) {
669
+ this.updateItemColors(tabStripItem);
670
+ }
671
+ setTabBarItemFontInternal(tabStripItem, value) {
672
+ this.setViewTextAttributes(tabStripItem.label);
673
+ }
674
+ getTabBarFontInternal() {
675
+ return this.viewController.tabBar.titleFontForState(0 /* UIControlState.Normal */);
676
+ }
677
+ setTabBarFontInternal() {
678
+ const defaultTabItemFontSize = 10;
679
+ const tabItemFontSize = this.tabStrip.style.fontSize || defaultTabItemFontSize;
680
+ const font = (this.tabStrip.style.fontInternal || Font.default).getUIFont(UIFont.systemFontOfSize(tabItemFontSize));
681
+ this.viewController.tabBar.setTitleFontForState(font, 0 /* UIControlState.Normal */);
682
+ this.viewController.tabBar.setTitleFontForState(font, 4 /* UIControlState.Selected */);
683
+ }
684
+ // public getTabBarTextTransform(): TextTransform {
685
+ // switch (this.viewController.tabBar.titleTextTransform) {
686
+ // case MDCTabBarViewTextTransform.None:
687
+ // return 'none';
688
+ // case MDCTabBarViewTextTransform.Automatic:
689
+ // return 'initial';
690
+ // case MDCTabBarViewTextTransform.Uppercase:
691
+ // default:
692
+ // return 'uppercase';
693
+ // }
694
+ // }
695
+ // public setTabBarTextTransform(value: TextTransform): void {
696
+ // if (value === 'none') {
697
+ // this.viewController.tabBar.titleTextTransform = MDCTabBarViewTextTransform.None;
698
+ // } else if (value === 'uppercase') {
699
+ // this.viewController.tabBar.titleTextTransform = MDCTabBarViewTextTransform.Uppercase;
700
+ // } else if (value === 'initial') {
701
+ // this.viewController.tabBar.titleTextTransform = MDCTabBarViewTextTransform.Automatic;
702
+ // }
703
+ // }
704
+ getTabBarColor() {
705
+ return this.viewController.tabBar.titleColorForState(0 /* UIControlState.Normal */);
706
+ }
707
+ setTabBarColor(value) {
708
+ const nativeColor = value instanceof Color ? value.ios : value;
709
+ // this.viewController.tabBar.setTitleColorForState(nativeColor, UIControlState.Normal);
710
+ this.viewController.tabBar.setTitleColorForState(nativeColor, 4 /* UIControlState.Selected */);
711
+ this.viewController.tabBar.setImageTintColorForState(nativeColor, 4 /* UIControlState.Selected */);
712
+ }
713
+ getTabBarHighlightColor() {
714
+ return this.mSelectionIndicatorColor;
715
+ }
716
+ setTabBarHighlightColor(value) {
717
+ this.mSelectionIndicatorColor = value;
718
+ this.viewController.tabBar.selectionIndicatorStrokeColor = value.ios;
719
+ }
720
+ getTabBarSelectedItemColor() {
721
+ return this.mSelectedItemColor;
722
+ }
723
+ setTabBarSelectedItemColor(value) {
724
+ this.mSelectedItemColor = value;
725
+ this.updateAllItemsColors();
726
+ }
727
+ getTabBarUnSelectedItemColor() {
728
+ return this.mUnSelectedItemColor;
729
+ }
730
+ setTabBarUnSelectedItemColor(value) {
731
+ this.mUnSelectedItemColor = value;
732
+ this.updateAllItemsColors();
733
+ }
734
+ visitFrames(view, operation) {
735
+ if (view instanceof Frame) {
736
+ operation(view);
737
+ }
738
+ view.eachChild((child) => {
739
+ this.visitFrames(child, operation);
740
+ return true;
741
+ });
742
+ }
743
+ setTabBarRippleColor(value, alpha) {
744
+ this.mRippleColor = value;
745
+ this.viewController.tabBar.rippleColor = getRippleColor(value, alpha);
746
+ }
747
+ getTabBarRippleColor() {
748
+ return this.mRippleColor;
749
+ }
750
+ [selectedIndexProperty.setNative](value) {
751
+ // TODO
752
+ // if (traceEnabled()) {
753
+ // traceWrite("TabView._onSelectedIndexPropertyChangedSetNativeValue(" + value + ")", traceCategories.Debug);
754
+ // }
755
+ if (value > -1) {
756
+ const item = this.items[value];
757
+ const controllers = NSMutableArray.alloc().initWithCapacity(1);
758
+ const itemController = item.__controller;
759
+ // if (!itemController) {
760
+ // itemController = this.getViewController(item);
761
+ // }
762
+ controllers.addObject(itemController);
763
+ let navigationDirection = 0 /* UIPageViewControllerNavigationDirection.Forward */;
764
+ if (this.mCurrentNativeSelectedIndex && this.mCurrentNativeSelectedIndex > value) {
765
+ navigationDirection = 1 /* UIPageViewControllerNavigationDirection.Reverse */;
766
+ }
767
+ this.mCurrentNativeSelectedIndex = value;
768
+ // do not make layout changes while the animation is in progress https://stackoverflow.com/a/47031524/613113
769
+ this.visitFrames(item, (frame) => (frame._animationInProgress = true));
770
+ const doneAnimating = () => {
771
+ this.visitFrames(item, (frame) => (frame._animationInProgress = false));
772
+ this.finishTabTransition();
773
+ this._setCanBeLoaded(value);
774
+ this._loadUnloadTabItems(value);
775
+ };
776
+ if (this.mAnimateNextChange) {
777
+ invokeOnRunLoop(() => {
778
+ this.viewController.setViewControllersDirectionAnimatedCompletion(controllers, navigationDirection, this.animationEnabled, (finished) => {
779
+ if (finished) {
780
+ if (this.animationEnabled) {
781
+ // HACK: UIPageViewController fix; see https://stackoverflow.com/a/17330606
782
+ // Prior Hack fails on iOS 10.3 during tests with v8 engine...
783
+ // Leaving the above link in case we need to special case this for only iOS > 10.3?
784
+ // HACK: UIPageViewController fix; see https://stackoverflow.com/questions/15325891
785
+ invokeOnRunLoop(() => {
786
+ doneAnimating();
787
+ });
788
+ }
789
+ else {
790
+ doneAnimating();
791
+ }
792
+ }
793
+ });
794
+ });
795
+ }
796
+ else {
797
+ this.mAnimateNextChange = true;
798
+ doneAnimating();
799
+ }
800
+ if (this.tabBarItems && this.tabBarItems.length && this.viewController && this.viewController.tabBar) {
801
+ this.viewController.tabBar.setSelectedItemAnimated(this.tabBarItems[value], this.animationEnabled);
802
+ }
803
+ // TODO:
804
+ // (<any>this.viewController)._willSelectViewController = this.viewController.viewControllers[value];
805
+ // this.viewController.selectedIndex = value;
806
+ }
807
+ }
808
+ [itemsProperty.getDefault]() {
809
+ return null;
810
+ }
811
+ [itemsProperty.setNative](value) {
812
+ if (value) {
813
+ value.forEach((item, i) => {
814
+ item.index = i;
815
+ });
816
+ }
817
+ this.setViewControllers(value);
818
+ selectedIndexProperty.coerce(this);
819
+ }
820
+ [tabStripProperty.getDefault]() {
821
+ return null;
822
+ }
823
+ [tabStripProperty.setNative](value) {
824
+ this.setViewControllers(this.items);
825
+ selectedIndexProperty.coerce(this);
826
+ }
827
+ [swipeEnabledProperty.getDefault]() {
828
+ return true;
829
+ }
830
+ [swipeEnabledProperty.setNative](value) {
831
+ if (this.viewController && this.viewController.scrollView) {
832
+ this.viewController.scrollView.scrollEnabled = value;
833
+ }
834
+ }
835
+ // [iOSTabBarItemsAlignmentProperty.getDefault](): IOSTabBarItemsAlignment {
836
+ // if (!this.viewController || !this.viewController.tabBar) {
837
+ // return 'justified';
838
+ // }
839
+ // const alignment = this.viewController.tabBar.alignment.toString();
840
+ // return <any>(alignment.charAt(0).toLowerCase() + alignment.substring(1));
841
+ // }
842
+ // [iOSTabBarItemsAlignmentProperty.setNative](value: IOSTabBarItemsAlignment) {
843
+ // if (!this.viewController || !this.viewController.tabBar) {
844
+ // return;
845
+ // }
846
+ // let alignment = MDCTabBarViewAlignment.Justified;
847
+ // switch (value) {
848
+ // case 'leading':
849
+ // alignment = MDCTabBarViewAlignment.Leading;
850
+ // break;
851
+ // case 'center':
852
+ // alignment = MDCTabBarView.Alignment.Center;
853
+ // break;
854
+ // case 'centerSelected':
855
+ // alignment = MDCTabBarViewAlignment.CenterSelected;
856
+ // break;
857
+ // }
858
+ // this.viewController.tabBar.alignment = alignment;
859
+ // }
860
+ setViewTextAttributes(view, setSelected = false) {
861
+ if (!view) {
862
+ return null;
863
+ }
864
+ const defaultTabItemFontSize = 10;
865
+ const tabItemFontSize = view.style.fontSize || defaultTabItemFontSize;
866
+ const font = (view.style.fontInternal || Font.default).getUIFont(UIFont.systemFontOfSize(tabItemFontSize));
867
+ this.viewController.tabBar.setTitleFontForState(font, 0 /* UIControlState.Normal */);
868
+ this.viewController.tabBar.setTitleFontForState(font, 4 /* UIControlState.Selected */);
869
+ const tabItemTextColor = view.style.color;
870
+ const textColor = tabItemTextColor instanceof Color ? tabItemTextColor.ios : null;
871
+ if (textColor) {
872
+ this.viewController.tabBar.setTitleColorForState(textColor, 0 /* UIControlState.Normal */);
873
+ this.viewController.tabBar.setImageTintColorForState(textColor, 0 /* UIControlState.Normal */);
874
+ if (setSelected) {
875
+ this.viewController.tabBar.setTitleColorForState(textColor, 4 /* UIControlState.Selected */);
876
+ this.viewController.tabBar.setImageTintColorForState(textColor, 4 /* UIControlState.Selected */);
877
+ }
878
+ }
879
+ if (this.mSelectedItemColor) {
880
+ this.viewController.tabBar.setTitleColorForState(this.mSelectedItemColor.ios, 4 /* UIControlState.Selected */);
881
+ this.viewController.tabBar.setImageTintColorForState(this.mSelectedItemColor.ios, 4 /* UIControlState.Selected */);
882
+ }
883
+ if (this.mUnSelectedItemColor) {
884
+ this.viewController.tabBar.setTitleColorForState(this.mUnSelectedItemColor.ios, 0 /* UIControlState.Normal */);
885
+ this.viewController.tabBar.setImageTintColorForState(this.mUnSelectedItemColor.ios, 4 /* UIControlState.Selected */);
886
+ }
887
+ }
888
+ }
889
+ iosCustomPositioningProperty.register(TabNavigation);
890
+ //# sourceMappingURL=index.ios.js.map