@nativescript-community/ui-material-core 7.0.26 → 7.0.27

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 (35) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/package.json +2 -2
  3. package/pnpm-lock.yaml +0 -83
  4. package/tab-navigation-base/react/index.d.ts +0 -60
  5. package/tab-navigation-base/react/index.js +0 -114
  6. package/tab-navigation-base/react/index.js.map +0 -1
  7. package/tab-navigation-base/tab-content-item/index.android.d.ts +0 -14
  8. package/tab-navigation-base/tab-content-item/index.android.js +0 -48
  9. package/tab-navigation-base/tab-content-item/index.android.js.map +0 -1
  10. package/tab-navigation-base/tab-content-item/index.d.ts +0 -11
  11. package/tab-navigation-base/tab-content-item/index.ios.d.ts +0 -7
  12. package/tab-navigation-base/tab-content-item/index.ios.js +0 -13
  13. package/tab-navigation-base/tab-content-item/index.ios.js.map +0 -1
  14. package/tab-navigation-base/tab-content-item/tab-content-item-common.d.ts +0 -7
  15. package/tab-navigation-base/tab-content-item/tab-content-item-common.js +0 -24
  16. package/tab-navigation-base/tab-content-item/tab-content-item-common.js.map +0 -1
  17. package/tab-navigation-base/tab-navigation/index-common.d.ts +0 -27
  18. package/tab-navigation-base/tab-navigation/index-common.js +0 -58
  19. package/tab-navigation-base/tab-navigation/index-common.js.map +0 -1
  20. package/tab-navigation-base/tab-navigation/index.android.d.ts +0 -80
  21. package/tab-navigation-base/tab-navigation/index.android.js +0 -860
  22. package/tab-navigation-base/tab-navigation/index.android.js.map +0 -1
  23. package/tab-navigation-base/tab-navigation/index.d.ts +0 -80
  24. package/tab-navigation-base/tab-navigation/index.ios.d.ts +0 -93
  25. package/tab-navigation-base/tab-navigation/index.ios.js +0 -819
  26. package/tab-navigation-base/tab-navigation/index.ios.js.map +0 -1
  27. package/tab-navigation-base/tab-navigation-base/index.d.ts +0 -68
  28. package/tab-navigation-base/tab-navigation-base/index.js +0 -247
  29. package/tab-navigation-base/tab-navigation-base/index.js.map +0 -1
  30. package/tab-navigation-base/tab-strip/index.d.ts +0 -24
  31. package/tab-navigation-base/tab-strip/index.js +0 -153
  32. package/tab-navigation-base/tab-strip/index.js.map +0 -1
  33. package/tab-navigation-base/tab-strip-item/index.d.ts +0 -34
  34. package/tab-navigation-base/tab-strip-item/index.js +0 -215
  35. package/tab-navigation-base/tab-strip-item/index.js.map +0 -1
@@ -1,860 +0,0 @@
1
- import { Application, Color, CoreTypes, Font, Frame, ImageSource, Utils, View, getTransformedText } 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, TabsPosition, animationEnabledProperty, offscreenTabLimitProperty, swipeEnabledProperty } from './index-common';
7
- export * from './index-common';
8
- export { TabContentItem, TabStrip, TabStripItem };
9
- const ACCENT_COLOR = 'colorAccent';
10
- export const PRIMARY_COLOR = 'colorPrimary';
11
- const DEFAULT_ELEVATION = 4;
12
- const TABID = '_tabId';
13
- const INDEX = '_index';
14
- const ownerSymbol = Symbol('_owner');
15
- class IconInfo {
16
- }
17
- let PagerAdapter;
18
- let TabsBar;
19
- let appResources;
20
- let AttachStateChangeListener;
21
- function makeFragmentName(viewId, id) {
22
- return 'android:viewpager:' + viewId + ':' + id;
23
- }
24
- function _getParentFragmentManagerFromFragment(fragment) {
25
- if (!fragment) {
26
- return null;
27
- }
28
- try {
29
- return fragment.getParentFragmentManager();
30
- }
31
- catch (e) {
32
- return null;
33
- }
34
- }
35
- function getTabById(id) {
36
- const ref = tabs.find((ref) => {
37
- const tab = ref.get();
38
- return tab && tab._domId === id;
39
- });
40
- return ref && ref.get();
41
- }
42
- function initializeNativeClasses() {
43
- if (PagerAdapter) {
44
- return;
45
- }
46
- var TabFragmentImplementation = /** @class */ (function (_super) {
47
- __extends(TabFragmentImplementation, _super);
48
- function TabFragmentImplementation() {
49
- var _this = _super.call(this) || this;
50
- _this.backgroundBitmap = null;
51
- return global.__native(_this);
52
- }
53
- TabFragmentImplementation.newInstance = function (tabId, index) {
54
- var args = new android.os.Bundle();
55
- args.putInt(TABID, tabId);
56
- args.putInt(INDEX, index);
57
- var fragment = new TabFragmentImplementation();
58
- fragment.setArguments(args);
59
- return fragment;
60
- };
61
- TabFragmentImplementation.prototype.onCreate = function (savedInstanceState) {
62
- _super.prototype.onCreate.call(this, savedInstanceState);
63
- var args = this.getArguments();
64
- this.owner = getTabById(args.getInt(TABID));
65
- this.index = args.getInt(INDEX);
66
- if (!this.owner) {
67
- throw new Error('Cannot find TabView');
68
- }
69
- };
70
- TabFragmentImplementation.prototype.onCreateView = function (inflater, container, savedInstanceState) {
71
- var tabItem = this.owner.items[this.index];
72
- return tabItem.nativeViewProtected;
73
- };
74
- TabFragmentImplementation.prototype.onDestroyView = function () {
75
- var hasRemovingParent = this.getRemovingParentFragment();
76
- // Get view as bitmap and set it as background. This is workaround for the disapearing nested fragments.
77
- // TODO: Consider removing it when update to androidx.fragment:1.2.0
78
- if (hasRemovingParent && this.owner.selectedIndex === this.index && this.owner.nativeViewProtected) {
79
- var bitmapDrawable = new android.graphics.drawable.BitmapDrawable(appResources, this.backgroundBitmap);
80
- this.owner._originalBackground = this.owner.backgroundColor || new Color('White');
81
- this.owner.nativeViewProtected.setBackground(bitmapDrawable);
82
- this.backgroundBitmap = null;
83
- }
84
- _super.prototype.onDestroyView.call(this);
85
- };
86
- TabFragmentImplementation.prototype.onPause = function () {
87
- var hasRemovingParent = this.getRemovingParentFragment();
88
- // Get view as bitmap and set it as background. This is workaround for the disapearing nested fragments.
89
- // TODO: Consider removing it when update to androidx.fragment:1.2.0
90
- if (hasRemovingParent && this.owner.selectedIndex === this.index && this.owner.nativeViewProtected) {
91
- this.backgroundBitmap = this.loadBitmapFromView(this.owner.nativeViewProtected);
92
- }
93
- _super.prototype.onPause.call(this);
94
- };
95
- TabFragmentImplementation.prototype.loadBitmapFromView = function (view) {
96
- // Another way to get view bitmap. Test performance vs setDrawingCacheEnabled
97
- // const width = view.getWidth();
98
- // const height = view.getHeight();
99
- // const bitmap = android.graphics.Bitmap.createBitmap(width, height, android.graphics.Bitmap.Config.ARGB_8888);
100
- // const canvas = new android.graphics.Canvas(bitmap);
101
- // view.layout(0, 0, width, height);
102
- // view.draw(canvas);
103
- view.setDrawingCacheEnabled(true);
104
- var bitmap = android.graphics.Bitmap.createBitmap(view.getDrawingCache());
105
- view.setDrawingCacheEnabled(false);
106
- return bitmap;
107
- };
108
- return TabFragmentImplementation;
109
- }(org.nativescript.widgets.FragmentBase));
110
- const POSITION_UNCHANGED = -1;
111
- const POSITION_NONE = -2;
112
- var FragmentPagerAdapter = /** @class */ (function (_super) {
113
- __extends(FragmentPagerAdapter, _super);
114
- function FragmentPagerAdapter(owner) {
115
- var _this = _super.call(this) || this;
116
- _this.owner = owner;
117
- return global.__native(_this);
118
- }
119
- FragmentPagerAdapter.prototype.getCount = function () {
120
- var items = this.items;
121
- return items ? items.length : 0;
122
- };
123
- FragmentPagerAdapter.prototype.getPageTitle = function (index) {
124
- var items = this.items;
125
- if (index < 0 || index >= items.length) {
126
- return '';
127
- }
128
- return ''; // items[index].title;
129
- };
130
- FragmentPagerAdapter.prototype.startUpdate = function (container) {
131
- if (container.getId() === android.view.View.NO_ID) {
132
- throw new Error("ViewPager with adapter ".concat(this, " requires a view containerId"));
133
- }
134
- };
135
- FragmentPagerAdapter.prototype.instantiateItem = function (container, position) {
136
- var _a;
137
- var owner = (_a = this.owner) === null || _a === void 0 ? void 0 : _a.get();
138
- if (!owner) {
139
- return null;
140
- }
141
- var fragmentManager = owner._getFragmentManager();
142
- if (!this.mCurTransaction) {
143
- this.mCurTransaction = fragmentManager.beginTransaction();
144
- }
145
- var itemId = this.getItemId(position);
146
- var name = makeFragmentName(container.getId(), itemId);
147
- var fragment = fragmentManager.findFragmentByTag(name);
148
- if (fragment != null) {
149
- this.mCurTransaction.attach(fragment);
150
- }
151
- else {
152
- fragment = TabFragmentImplementation.newInstance(owner._domId, position);
153
- owner.fragments.push(fragment);
154
- this.mCurTransaction.add(container.getId(), fragment, name);
155
- }
156
- if (fragment !== this.mCurrentPrimaryItem) {
157
- fragment.setMenuVisibility(false);
158
- fragment.setUserVisibleHint(false);
159
- }
160
- var tabItems = owner.items;
161
- var tabItem = tabItems ? tabItems[position] : null;
162
- if (tabItem) {
163
- tabItem.canBeLoaded = true;
164
- }
165
- return fragment;
166
- };
167
- FragmentPagerAdapter.prototype.getItemPosition = function (object) {
168
- return this.items ? POSITION_UNCHANGED : POSITION_NONE;
169
- };
170
- FragmentPagerAdapter.prototype.destroyItem = function (container, position, object) {
171
- var _a, _b;
172
- var owner = (_a = this.owner) === null || _a === void 0 ? void 0 : _a.get();
173
- if (!owner) {
174
- return;
175
- }
176
- var fragment = object;
177
- if (!this.mCurTransaction) {
178
- var fragmentManager = _getParentFragmentManagerFromFragment(fragment);
179
- this.mCurTransaction = fragmentManager === null || fragmentManager === void 0 ? void 0 : fragmentManager.beginTransaction();
180
- }
181
- var index = owner.fragments.indexOf(fragment);
182
- // if (index !== -1) {
183
- // this.owner.fragments.splice(index, 1);
184
- // }
185
- (_b = this.mCurTransaction) === null || _b === void 0 ? void 0 : _b.detach(fragment);
186
- if (this.mCurrentPrimaryItem === fragment) {
187
- this.mCurrentPrimaryItem = null;
188
- }
189
- var tabItems = owner.items;
190
- var tabItem = tabItems ? tabItems[position] : null;
191
- if (tabItem) {
192
- tabItem.canBeLoaded = false;
193
- }
194
- };
195
- FragmentPagerAdapter.prototype.setPrimaryItem = function (container, position, object) {
196
- var _a;
197
- var owner = (_a = this.owner) === null || _a === void 0 ? void 0 : _a.get();
198
- if (!owner) {
199
- return;
200
- }
201
- var fragment = object;
202
- if (fragment !== this.mCurrentPrimaryItem) {
203
- if (this.mCurrentPrimaryItem != null) {
204
- this.mCurrentPrimaryItem.setMenuVisibility(false);
205
- this.mCurrentPrimaryItem.setUserVisibleHint(false);
206
- }
207
- if (fragment != null) {
208
- fragment.setMenuVisibility(true);
209
- fragment.setUserVisibleHint(true);
210
- }
211
- var tab = owner;
212
- this.mCurrentPrimaryItem = fragment;
213
- tab.selectedIndex = position;
214
- var tabItems = tab.items;
215
- var newTabItem = tabItems ? tabItems[position] : null;
216
- if (newTabItem) {
217
- tab._loadUnloadTabItems(tab.selectedIndex);
218
- }
219
- }
220
- };
221
- FragmentPagerAdapter.prototype.finishUpdate = function (container) {
222
- this._commitCurrentTransaction();
223
- };
224
- FragmentPagerAdapter.prototype.isViewFromObject = function (view, object) {
225
- return object.getView() === view;
226
- };
227
- FragmentPagerAdapter.prototype.saveState = function () {
228
- // Commit the current transaction on save to prevent "No view found for id 0xa" exception on restore.
229
- // Related to: https://github.com/NativeScript/NativeScript/issues/6466
230
- this._commitCurrentTransaction();
231
- return null;
232
- };
233
- FragmentPagerAdapter.prototype.restoreState = function (state, loader) {
234
- //
235
- };
236
- FragmentPagerAdapter.prototype.getItemId = function (position) {
237
- return position;
238
- };
239
- FragmentPagerAdapter.prototype._commitCurrentTransaction = function () {
240
- if (this.mCurTransaction != null) {
241
- this.mCurTransaction.commitNowAllowingStateLoss();
242
- this.mCurTransaction = null;
243
- }
244
- };
245
- return FragmentPagerAdapter;
246
- }(androidx.viewpager.widget.PagerAdapter));
247
- var TabsBarImplementation = /** @class */ (function (_super) {
248
- __extends(TabsBarImplementation, _super);
249
- function TabsBarImplementation(context, owner) {
250
- var _this = _super.call(this, context) || this;
251
- _this.owner = owner;
252
- return global.__native(_this);
253
- }
254
- TabsBarImplementation.prototype.onSelectedPositionChange = function (position, prevPosition) {
255
- var owner = this.owner;
256
- if (!owner) {
257
- return;
258
- }
259
- owner.onTabsBarSelectedPositionChange(position, prevPosition);
260
- };
261
- TabsBarImplementation.prototype.onTap = function (position) {
262
- var owner = this.owner;
263
- if (!owner) {
264
- return false;
265
- }
266
- return owner.onTabsBarTap(position);
267
- };
268
- return TabsBarImplementation;
269
- }(com.nativescript.material.core.TabsBar));
270
- var AttachListener = /** @class */ (function (_super) {
271
- __extends(AttachListener, _super);
272
- function AttachListener() {
273
- var _this = _super.call(this) || this;
274
- return global.__native(_this);
275
- }
276
- AttachListener.prototype.onViewAttachedToWindow = function (view) {
277
- var owner = view[ownerSymbol];
278
- if (owner) {
279
- owner._onAttachedToWindow();
280
- }
281
- };
282
- AttachListener.prototype.onViewDetachedFromWindow = function (view) {
283
- var owner = view[ownerSymbol];
284
- if (owner) {
285
- owner._onDetachedFromWindow();
286
- }
287
- };
288
- AttachListener = __decorate([
289
- Interfaces([android.view.View.OnAttachStateChangeListener])
290
- ], AttachListener);
291
- return AttachListener;
292
- }(java.lang.Object));
293
- PagerAdapter = FragmentPagerAdapter;
294
- TabsBar = TabsBarImplementation;
295
- AttachStateChangeListener = new AttachListener();
296
- appResources = Application.android.context.getResources();
297
- }
298
- let defaultAccentColor;
299
- export function getDefaultAccentColor(context) {
300
- if (defaultAccentColor === undefined) {
301
- defaultAccentColor = Utils.android.resources.getPaletteColor(ACCENT_COLOR, context) || 0xff33b5e5;
302
- }
303
- return defaultAccentColor;
304
- }
305
- function setElevation(grid, tabsBar, tabsPosition) {
306
- const compat = androidx.core.view.ViewCompat;
307
- if (compat.setElevation) {
308
- const val = DEFAULT_ELEVATION * Utils.layout.getDisplayDensity();
309
- if (grid && tabsPosition === 'top') {
310
- compat.setElevation(grid, val);
311
- }
312
- if (tabsBar) {
313
- compat.setElevation(tabsBar, val);
314
- }
315
- }
316
- }
317
- export const tabs = new Array();
318
- function iterateIndexRange(index, eps, lastIndex, callback) {
319
- const rangeStart = Math.max(0, index - eps);
320
- const rangeEnd = Math.min(index + eps, lastIndex);
321
- for (let i = rangeStart; i <= rangeEnd; i++) {
322
- callback(i);
323
- }
324
- }
325
- export class TabNavigation extends TabNavigationBase {
326
- constructor() {
327
- super();
328
- this.mAndroidViewId = -1;
329
- this.mTextTransform = 'none';
330
- this.fragments = [];
331
- tabs.push(new WeakRef(this));
332
- }
333
- get _hasFragments() {
334
- return true;
335
- }
336
- onItemsChanged(oldItems, newItems) {
337
- super.onItemsChanged(oldItems, newItems);
338
- if (oldItems) {
339
- oldItems.forEach((item, i, arr) => {
340
- item.index = 0;
341
- item.tabItemSpec = null;
342
- item.setNativeView(null);
343
- });
344
- }
345
- }
346
- createNativeView() {
347
- initializeNativeClasses();
348
- const context = this._context;
349
- const nativeView = new org.nativescript.widgets.GridLayout(context);
350
- const viewPager = new com.nativescript.material.core.TabViewPager(context);
351
- const lp = new org.nativescript.widgets.CommonLayoutParams();
352
- lp.row = 1;
353
- if (this.tabsPosition === 'top') {
354
- nativeView.addRow(new org.nativescript.widgets.ItemSpec(1, org.nativescript.widgets.GridUnitType.auto));
355
- nativeView.addRow(new org.nativescript.widgets.ItemSpec(1, org.nativescript.widgets.GridUnitType.star));
356
- viewPager.setLayoutParams(lp);
357
- }
358
- else {
359
- nativeView.addRow(new org.nativescript.widgets.ItemSpec(1, org.nativescript.widgets.GridUnitType.star));
360
- nativeView.addRow(new org.nativescript.widgets.ItemSpec(1, org.nativescript.widgets.GridUnitType.auto));
361
- this.tabBarLayoutParams = lp;
362
- }
363
- nativeView.addView(viewPager);
364
- nativeView.viewPager = viewPager;
365
- const adapter = (this.mPagerAdapter = new PagerAdapter(new WeakRef(this)));
366
- viewPager.setAdapter(adapter);
367
- viewPager.adapter = adapter;
368
- this.mViewPager = viewPager;
369
- setElevation(nativeView, null, this.tabsPosition);
370
- if (this.tabStrip) {
371
- this.handleTabStripChanged(nativeView, null, this.tabStrip);
372
- }
373
- return nativeView;
374
- }
375
- createNativeTabBar(context) {
376
- const tabsBar = new TabsBar(context, this);
377
- const primaryColor = Utils.android.resources.getPaletteColor(PRIMARY_COLOR, context);
378
- const accentColor = getDefaultAccentColor(context);
379
- if (accentColor) {
380
- tabsBar.setSelectedIndicatorColors([accentColor]);
381
- }
382
- if (primaryColor) {
383
- tabsBar.setBackgroundColor(primaryColor);
384
- }
385
- return tabsBar;
386
- }
387
- handleTabStripChanged(nativeView, oldTabStrip, newTabStrip) {
388
- if (this.mTabsBar) {
389
- nativeView.removeView(this.mTabsBar);
390
- nativeView['tabsBar'] = null;
391
- this.mTabsBar = null;
392
- }
393
- if (newTabStrip) {
394
- initializeNativeClasses();
395
- const context = this._context;
396
- const tabsBar = (this.mTabsBar = this.createNativeTabBar(context));
397
- setElevation(null, tabsBar, this.tabsPosition);
398
- if (this.tabsPosition !== TabsPosition.Top) {
399
- tabsBar.setLayoutParams(this.tabBarLayoutParams);
400
- }
401
- nativeView.addView(tabsBar);
402
- nativeView['tabsBar'] = tabsBar;
403
- }
404
- }
405
- onTabStripChanged(oldTabStrip, newTabStrip) {
406
- super.onTabStripChanged(oldTabStrip, newTabStrip);
407
- const nativeView = this.nativeViewProtected;
408
- if (!nativeView) {
409
- return;
410
- }
411
- this.handleTabStripChanged(nativeView, oldTabStrip, newTabStrip);
412
- }
413
- onSelectedIndexChanged(oldIndex, newIndex) {
414
- if (this.mTabsBar) {
415
- this.selectTabBar(oldIndex, newIndex);
416
- }
417
- super.onSelectedIndexChanged(oldIndex, newIndex);
418
- }
419
- initNativeView() {
420
- super.initNativeView();
421
- if (this.mAndroidViewId < 0) {
422
- this.mAndroidViewId = android.view.View.generateViewId();
423
- }
424
- const nativeView = this.nativeViewProtected;
425
- const viewPager = nativeView.viewPager;
426
- viewPager.setId(this.mAndroidViewId);
427
- }
428
- _onAttachedToWindow() {
429
- var _a;
430
- super._onAttachedToWindow();
431
- const activity = Application.android.foregroundActivity || Application.android.startActivity;
432
- const lifecycle = ((_a = activity === null || activity === void 0 ? void 0 : activity.getLifecycle) === null || _a === void 0 ? void 0 : _a.call(activity).getCurrentState()) || androidx.lifecycle.Lifecycle.State.CREATED;
433
- if ((this._manager && this._manager.isDestroyed()) || (activity instanceof androidx.fragment.app.FragmentActivity && !lifecycle.isAtLeast(androidx.lifecycle.Lifecycle.State.CREATED))) {
434
- return;
435
- }
436
- this.mViewPager.setCurrentItem(this.selectedIndex, false);
437
- }
438
- _onDetachedFromWindow() {
439
- super._onDetachedFromWindow();
440
- this.disposeTabFragments();
441
- }
442
- _loadUnloadTabItems(newIndex) {
443
- const items = this.items;
444
- if (!items) {
445
- return;
446
- }
447
- const lastIndex = items.length - 1;
448
- const offsideItems = this.offscreenTabLimit;
449
- const toUnload = [];
450
- const toLoad = [];
451
- iterateIndexRange(newIndex, offsideItems, lastIndex, (i) => toLoad.push(i));
452
- if (this.unloadOnTabChange) {
453
- items.forEach((item, i) => {
454
- const indexOfI = toLoad.indexOf(i);
455
- if (indexOfI < 0) {
456
- toUnload.push(i);
457
- }
458
- toUnload.forEach((index) => {
459
- const item = items[index];
460
- if (items[index]) {
461
- item.unloadView(item.content);
462
- }
463
- });
464
- });
465
- }
466
- const newItem = items[newIndex];
467
- const selectedView = newItem && newItem.content;
468
- if (selectedView instanceof Frame) {
469
- selectedView._pushInFrameStackRecursive();
470
- }
471
- toLoad.forEach((index) => {
472
- const item = items[index];
473
- if (this.isLoaded && items[index]) {
474
- item.loadView(item.content);
475
- }
476
- });
477
- }
478
- onLoaded() {
479
- super.onLoaded();
480
- if (this._originalBackground) {
481
- this.backgroundColor = null;
482
- this.backgroundColor = this._originalBackground;
483
- this._originalBackground = null;
484
- }
485
- this.setItems(this.items);
486
- if (this.tabStrip) {
487
- this.setTabStripItems(this.tabStrip.items);
488
- }
489
- }
490
- onUnloaded() {
491
- super.onUnloaded();
492
- this.setItems(null);
493
- this.setTabStripItems(null);
494
- this.items.forEach((item, i) => {
495
- item.unloadView(item.content);
496
- });
497
- }
498
- disposeNativeView() {
499
- if (this.mTabsBar) {
500
- this.setTabBarItems(null, null);
501
- }
502
- this.mPagerAdapter.owner = null;
503
- this.mPagerAdapter = null;
504
- this.nativeViewProtected.removeOnAttachStateChangeListener(AttachStateChangeListener);
505
- super.disposeNativeView();
506
- this.disposeTabFragments();
507
- }
508
- _onRootViewReset() {
509
- super._onRootViewReset();
510
- this.disposeTabFragments();
511
- }
512
- disposeTabFragments() {
513
- const fragments = this.fragments;
514
- for (let i = 0; i < fragments.length; i++) {
515
- this.removeFragment(fragments[i]);
516
- }
517
- this.fragments = [];
518
- }
519
- removeFragment(fragment) {
520
- if (fragment) {
521
- if (!fragment.isAdded() || fragment.isRemoving()) {
522
- return;
523
- }
524
- else {
525
- const fragmentExitTransition = fragment.getExitTransition();
526
- if (fragmentExitTransition && fragmentExitTransition instanceof org.nativescript.widgets.CustomTransition) {
527
- fragmentExitTransition.setResetOnTransitionEnd(true);
528
- }
529
- if (fragment && fragment.isAdded() && !fragment.isRemoving()) {
530
- const pfm = _getParentFragmentManagerFromFragment(fragment);
531
- if (pfm && !pfm.isDestroyed()) {
532
- try {
533
- if (pfm.isStateSaved()) {
534
- pfm.beginTransaction().remove(fragment).commitNowAllowingStateLoss();
535
- }
536
- else {
537
- pfm.beginTransaction().remove(fragment).commitNow();
538
- }
539
- }
540
- catch (e) { }
541
- }
542
- }
543
- }
544
- }
545
- }
546
- shouldUpdateAdapter(items) {
547
- if (!this.mPagerAdapter) {
548
- return false;
549
- }
550
- const currentPagerAdapterItems = this.mPagerAdapter.items;
551
- if (!items && !currentPagerAdapterItems) {
552
- return false;
553
- }
554
- if (!items || !currentPagerAdapterItems) {
555
- return true;
556
- }
557
- if (items.length !== currentPagerAdapterItems.length) {
558
- return true;
559
- }
560
- const matchingItems = currentPagerAdapterItems.filter((currentItem) => !!items.filter((item) => item._domId === currentItem._domId)[0]);
561
- if (matchingItems.length !== items.length) {
562
- return true;
563
- }
564
- return false;
565
- }
566
- setItems(items) {
567
- if (this.shouldUpdateAdapter(items)) {
568
- this.mPagerAdapter.items = items;
569
- if (items && items.length) {
570
- items.forEach((item, i) => {
571
- item.index = i;
572
- });
573
- }
574
- this.mPagerAdapter.notifyDataSetChanged();
575
- }
576
- }
577
- setTabStripItems(items) {
578
- const length = items ? items.length : 0;
579
- if (length === 0) {
580
- if (this.mTabsBar) {
581
- this.setTabBarItems(null, null);
582
- }
583
- return;
584
- }
585
- const tabItems = new Array();
586
- items.forEach((tabStripItem, i, arr) => {
587
- tabStripItem._index = i;
588
- const tabItemSpec = this.createTabItemSpec(tabStripItem);
589
- tabStripItem.tabItemSpec = tabItemSpec;
590
- tabItems.push(tabItemSpec);
591
- });
592
- const tabsBar = this.mTabsBar;
593
- this.setTabBarItems(tabItems, this.mViewPager);
594
- this.tabStrip.setNativeView(tabsBar);
595
- items.forEach((item, i, arr) => {
596
- const tv = this.getTabBarItemTextView(i);
597
- item.setNativeView(tv);
598
- this._setItemColor(item);
599
- });
600
- }
601
- createTabItemSpec(tabStripItem) {
602
- const tabItemSpec = new com.nativescript.material.core.TabItemSpec();
603
- if (tabStripItem.isLoaded) {
604
- const nestedLabel = tabStripItem.label;
605
- let title = nestedLabel.text;
606
- const textTransform = this.getItemLabelTextTransform(tabStripItem);
607
- title = getTransformedText(title, textTransform);
608
- tabItemSpec.title = title;
609
- const backgroundColor = tabStripItem.style.backgroundColor;
610
- tabItemSpec.backgroundColor = backgroundColor ? backgroundColor.android : this.getTabBarBackgroundArgbColor();
611
- const itemColor = this.selectedIndex === tabStripItem._index ? this.mSelectedItemColor : this.mUnSelectedItemColor;
612
- const color = itemColor || nestedLabel.style.color;
613
- tabItemSpec.color = color && color.android;
614
- const fontInternal = nestedLabel.style.fontInternal;
615
- if (fontInternal) {
616
- tabItemSpec.fontSize = fontInternal.fontSize;
617
- tabItemSpec.typeFace = fontInternal.getAndroidTypeface();
618
- }
619
- const iconSource = tabStripItem.image && tabStripItem.image.src;
620
- if (iconSource) {
621
- const iconInfo = this.getIconInfo(tabStripItem, itemColor);
622
- if (iconInfo) {
623
- tabItemSpec.iconDrawable = iconInfo.drawable;
624
- tabItemSpec.imageHeight = iconInfo.height;
625
- }
626
- else {
627
- }
628
- }
629
- }
630
- return tabItemSpec;
631
- }
632
- getOriginalIcon(tabStripItem, color) {
633
- const iconSource = tabStripItem.image && tabStripItem.image.src;
634
- if (!iconSource) {
635
- return null;
636
- }
637
- let is;
638
- if (Utils.isFontIconURI(iconSource)) {
639
- const fontIconCode = iconSource.split('//')[1];
640
- const target = tabStripItem.image ? tabStripItem.image : tabStripItem;
641
- const font = target.style.fontInternal;
642
- if (!color) {
643
- color = target.style.color;
644
- }
645
- is = ImageSource.fromFontIconCodeSync(fontIconCode, font, color);
646
- }
647
- else {
648
- is = ImageSource.fromFileOrResourceSync(iconSource);
649
- }
650
- return is && is.android;
651
- }
652
- getDrawableInfo(image) {
653
- if (image) {
654
- if (this.tabStrip && this.tabStrip.isIconSizeFixed) {
655
- image = this.getFixedSizeIcon(image);
656
- }
657
- const imageDrawable = new android.graphics.drawable.BitmapDrawable(appResources, image);
658
- return {
659
- drawable: imageDrawable,
660
- height: image.getHeight()
661
- };
662
- }
663
- return new IconInfo();
664
- }
665
- getIconInfo(tabStripItem, color) {
666
- const originalIcon = this.getOriginalIcon(tabStripItem, color);
667
- return this.getDrawableInfo(originalIcon);
668
- }
669
- getFixedSizeIcon(image) {
670
- const inWidth = image.getWidth();
671
- const inHeight = image.getHeight();
672
- const iconSpecSize = getIconSpecSize({
673
- width: inWidth,
674
- height: inHeight
675
- });
676
- const widthPixels = iconSpecSize.width * Utils.layout.getDisplayDensity();
677
- const heightPixels = iconSpecSize.height * Utils.layout.getDisplayDensity();
678
- const scaledImage = android.graphics.Bitmap.createScaledBitmap(image, widthPixels, heightPixels, true);
679
- return scaledImage;
680
- }
681
- updateAndroidItemAt(index, spec) {
682
- try {
683
- if (this.mTabsBar) {
684
- this.updateTabsBarItemAt(index, spec);
685
- }
686
- }
687
- catch (err) { }
688
- }
689
- getTabBarBackgroundColor() {
690
- return this.mTabsBar.getBackground();
691
- }
692
- setTabBarBackgroundColor(value) {
693
- if (value instanceof Color) {
694
- this.mTabsBar.setBackgroundColor(value.android);
695
- }
696
- else {
697
- this.mTabsBar.setBackground(tryCloneDrawable(value, this.nativeViewProtected.getResources()));
698
- }
699
- }
700
- getTabBarHighlightColor() {
701
- return getDefaultAccentColor(this._context);
702
- }
703
- setTabBarHighlightColor(value) {
704
- const color = value instanceof Color ? value.android : value;
705
- this.setTabsBarSelectedIndicatorColors([color]);
706
- }
707
- getTabBarSelectedItemColor() {
708
- return this.mSelectedItemColor;
709
- }
710
- setTabBarSelectedItemColor(value) {
711
- this.mSelectedItemColor = value;
712
- }
713
- getTabBarUnSelectedItemColor() {
714
- return this.mUnSelectedItemColor;
715
- }
716
- setTabBarUnSelectedItemColor(value) {
717
- this.mUnSelectedItemColor = value;
718
- }
719
- updateItem(tabStripItem) {
720
- const tabStripItemIndex = this.tabStrip.items.indexOf(tabStripItem);
721
- const tabItemSpec = this.createTabItemSpec(tabStripItem);
722
- this.updateAndroidItemAt(tabStripItemIndex, tabItemSpec);
723
- }
724
- setTabBarItemTitle(tabStripItem, value) {
725
- this.updateItem(tabStripItem);
726
- }
727
- setTabBarItemBackgroundColor(tabStripItem, value) {
728
- this.updateItem(tabStripItem);
729
- }
730
- _setItemColor(tabStripItem) {
731
- if (!tabStripItem.nativeViewProtected) {
732
- return;
733
- }
734
- const itemColor = tabStripItem._index === this.selectedIndex ? this.mSelectedItemColor : this.mUnSelectedItemColor;
735
- if (!itemColor) {
736
- return;
737
- }
738
- tabStripItem.nativeViewProtected.setTextColor(itemColor.android);
739
- this.setIconColor(tabStripItem, itemColor);
740
- }
741
- setIconColor(tabStripItem, color) {
742
- if (!tabStripItem.nativeViewProtected) {
743
- return;
744
- }
745
- const tabBarItem = this.getTabBarItemView(tabStripItem._index);
746
- const drawableInfo = this.getIconInfo(tabStripItem, color);
747
- const imgView = tabBarItem.getChildAt(0);
748
- imgView.setImageDrawable(drawableInfo.drawable);
749
- if (color) {
750
- imgView.setColorFilter(color.android);
751
- }
752
- }
753
- setTabBarItemColor(tabStripItem, value) {
754
- const itemColor = tabStripItem._index === this.selectedIndex ? this.mSelectedItemColor : this.mUnSelectedItemColor;
755
- if (itemColor) {
756
- return;
757
- }
758
- const androidColor = value instanceof Color ? value.android : value;
759
- tabStripItem.nativeViewProtected.setTextColor(androidColor);
760
- }
761
- setTabBarIconColor(tabStripItem, value) {
762
- const itemColor = tabStripItem._index === this.selectedIndex ? this.mSelectedItemColor : this.mUnSelectedItemColor;
763
- if (itemColor) {
764
- return;
765
- }
766
- this.setIconColor(tabStripItem);
767
- }
768
- setTabBarIconSource(tabStripItem, value) {
769
- this.updateItem(tabStripItem);
770
- }
771
- setTabBarItemFontInternal(tabStripItem, value) {
772
- if (value.fontSize) {
773
- tabStripItem.nativeViewProtected.setTextSize(value.fontSize);
774
- }
775
- tabStripItem.nativeViewProtected.setTypeface(value.getAndroidTypeface());
776
- }
777
- setTabBarItemTextTransform(tabStripItem, value) {
778
- const nestedLabel = tabStripItem.label;
779
- const title = getTransformedText(nestedLabel.text, value);
780
- tabStripItem.nativeViewProtected.setText(title);
781
- }
782
- setTabBarTextTransform(value) {
783
- const items = this.tabStrip && this.tabStrip.items;
784
- if (items) {
785
- items.forEach((tabStripItem) => {
786
- if (tabStripItem.label && tabStripItem.nativeViewProtected) {
787
- const nestedLabel = tabStripItem.label;
788
- const title = getTransformedText(nestedLabel.text, value);
789
- tabStripItem.nativeViewProtected.setText(title);
790
- }
791
- });
792
- }
793
- this.mTextTransform = value;
794
- }
795
- onTabsBarSelectedPositionChange(position, prevPosition) {
796
- var _a;
797
- const tabStripItems = (_a = this.tabStrip) === null || _a === void 0 ? void 0 : _a.items;
798
- if (position >= 0 && tabStripItems && tabStripItems[position]) {
799
- tabStripItems[position]._emit(TabStripItem.selectEvent);
800
- this._setItemColor(tabStripItems[position]);
801
- }
802
- if (prevPosition >= 0 && tabStripItems && tabStripItems[prevPosition]) {
803
- tabStripItems[prevPosition]._emit(TabStripItem.unselectEvent);
804
- this._setItemColor(tabStripItems[prevPosition]);
805
- }
806
- }
807
- onTabsBarTap(position) {
808
- const tabStrip = this.tabStrip;
809
- const tabStripItems = tabStrip && tabStrip.items;
810
- if (position >= 0 && tabStripItems[position]) {
811
- tabStripItems[position]._emit(TabStripItem.tapEvent);
812
- tabStrip.notify({ eventName: TabStrip.itemTapEvent, object: tabStrip, index: position });
813
- }
814
- if (!this.items[position]) {
815
- return false;
816
- }
817
- return true;
818
- }
819
- [selectedIndexProperty.setNative](value) {
820
- this.mViewPager.setCurrentItem(value, this.animationEnabled);
821
- }
822
- [itemsProperty.getDefault]() {
823
- return null;
824
- }
825
- [itemsProperty.setNative](value) {
826
- this.setItems(value);
827
- selectedIndexProperty.coerce(this);
828
- }
829
- [tabStripProperty.getDefault]() {
830
- return null;
831
- }
832
- [tabStripProperty.setNative](value) {
833
- this.setTabStripItems((value === null || value === void 0 ? void 0 : value.items) || null);
834
- }
835
- [swipeEnabledProperty.getDefault]() {
836
- return true;
837
- }
838
- [swipeEnabledProperty.setNative](value) {
839
- this.mViewPager.setSwipePageEnabled(value);
840
- }
841
- [offscreenTabLimitProperty.getDefault]() {
842
- return this.mViewPager.getOffscreenPageLimit();
843
- }
844
- [offscreenTabLimitProperty.setNative](value) {
845
- this.mViewPager.setOffscreenPageLimit(value);
846
- }
847
- [animationEnabledProperty.setNative](value) {
848
- this.mViewPager.setAnimationEnabled(value);
849
- }
850
- }
851
- function tryCloneDrawable(value, resources) {
852
- if (value) {
853
- const constantState = value.getConstantState();
854
- if (constantState) {
855
- return constantState.newDrawable(resources);
856
- }
857
- }
858
- return value;
859
- }
860
- //# sourceMappingURL=index.android.js.map