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