@nativescript-community/ui-material-bottom-navigation 6.2.14 → 6.2.15
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 +8 -0
- package/index.android.d.ts +15 -57
- package/index.android.js +38 -755
- package/index.ios.d.ts +6 -6
- package/index.ios.js +50 -48
- package/package.json +5 -5
- package/pnpm-lock.yaml +90 -0
- package/react/index.js +1 -1
package/index.android.js
CHANGED
@@ -1,106 +1,14 @@
|
|
1
1
|
import { TabContentItem } from '@nativescript-community/ui-material-core/tab-navigation-base/tab-content-item';
|
2
|
-
import {
|
2
|
+
import { PRIMARY_COLOR, TabNavigation } from '@nativescript-community/ui-material-core/tab-navigation-base/tab-navigation/index.android';
|
3
3
|
import { TabStrip } from '@nativescript-community/ui-material-core/tab-navigation-base/tab-strip';
|
4
4
|
import { TabStripItem } from '@nativescript-community/ui-material-core/tab-navigation-base/tab-strip-item';
|
5
|
-
import {
|
6
|
-
import { getTransformedText } from '@nativescript/core/ui/text-base';
|
5
|
+
import { CSSType, Color, Utils } from '@nativescript/core';
|
7
6
|
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
7
|
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
8
|
function initializeNativeClasses() {
|
30
9
|
if (BottomNavigationBar) {
|
31
10
|
return;
|
32
11
|
}
|
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 && this.owner.nativeViewProtected) {
|
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
12
|
var BottomNavigationBarImplementation = /** @class */ (function (_super) {
|
105
13
|
__extends(BottomNavigationBarImplementation, _super);
|
106
14
|
function BottomNavigationBarImplementation(context, owner) {
|
@@ -109,585 +17,72 @@ function initializeNativeClasses() {
|
|
109
17
|
return global.__native(_this);
|
110
18
|
}
|
111
19
|
BottomNavigationBarImplementation.prototype.onSelectedPositionChange = function (position, prevPosition) {
|
20
|
+
console.log('onSelectedPositionChange', position, prevPosition);
|
112
21
|
var owner = this.owner;
|
113
22
|
if (!owner) {
|
114
23
|
return;
|
115
24
|
}
|
116
|
-
owner.
|
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);
|
25
|
+
owner.onTabsBarSelectedPositionChange(position, prevPosition);
|
125
26
|
};
|
126
27
|
BottomNavigationBarImplementation.prototype.onTap = function (position) {
|
127
28
|
var owner = this.owner;
|
128
29
|
if (!owner) {
|
129
30
|
return false;
|
130
31
|
}
|
131
|
-
|
132
|
-
|
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;
|
32
|
+
console.log('onTap', position, owner.onTabsBarTap(position));
|
33
|
+
return owner.onTabsBarTap(position);
|
145
34
|
};
|
146
35
|
return BottomNavigationBarImplementation;
|
147
36
|
}(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
37
|
BottomNavigationBar = BottomNavigationBarImplementation;
|
173
|
-
AttachStateChangeListener = new AttachListener();
|
174
|
-
appResources = Application.android.context.getResources();
|
175
38
|
}
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
const val = DEFAULT_ELEVATION * Utils.layout.getDisplayDensity();
|
180
|
-
compat.setElevation(bottomNavigationBar, val);
|
39
|
+
let BottomNavigation = class BottomNavigation extends TabNavigation {
|
40
|
+
updateTabsBarItemAt(position, itemSpec) {
|
41
|
+
this.mTabsBar.updateItemAt(position, itemSpec);
|
181
42
|
}
|
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);
|
43
|
+
setTabsBarSelectedIndicatorColors(colors) {
|
189
44
|
}
|
190
|
-
|
191
|
-
|
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));
|
45
|
+
getTabBarItemView(index) {
|
46
|
+
return this.mTabsBar.getViewForItemAt(index);
|
199
47
|
}
|
200
|
-
|
201
|
-
return
|
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
|
-
}
|
48
|
+
getTabBarItemTextView(index) {
|
49
|
+
return this.mTabsBar.getTextViewForItemAt(index);
|
212
50
|
}
|
213
|
-
|
51
|
+
createNativeTabBar(context) {
|
214
52
|
initializeNativeClasses();
|
215
|
-
const
|
216
|
-
const
|
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);
|
53
|
+
const tabsBar = new BottomNavigationBar(context, this);
|
54
|
+
const primaryColor = Utils.android.resources.getPaletteColor(PRIMARY_COLOR, context);
|
233
55
|
if (primaryColor) {
|
234
|
-
|
56
|
+
tabsBar.setBackgroundColor(primaryColor);
|
235
57
|
}
|
236
|
-
|
58
|
+
tabsBar.setSelectedPosition(this.selectedIndex);
|
59
|
+
return tabsBar;
|
237
60
|
}
|
238
|
-
|
239
|
-
|
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
|
-
}
|
61
|
+
setTabBarItems(tabItems, viewPager) {
|
62
|
+
this.mTabsBar.setItems(tabItems);
|
253
63
|
}
|
254
|
-
|
255
|
-
|
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
|
-
});
|
64
|
+
selectTabBar(oldIndex, newIndex) {
|
65
|
+
this.mTabsBar.setSelectedPosition(newIndex);
|
286
66
|
}
|
287
67
|
onLoaded() {
|
288
68
|
super.onLoaded();
|
289
|
-
if (this.
|
290
|
-
this.
|
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);
|
69
|
+
if (!this.tabStrip) {
|
70
|
+
this.mTabsBar.setVisibility(android.view.View.GONE);
|
302
71
|
}
|
303
72
|
}
|
304
73
|
_onAttachedToWindow() {
|
305
|
-
var _a;
|
306
74
|
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
|
-
this.items[position].callLoaded();
|
413
|
-
return fragment;
|
414
|
-
}
|
415
|
-
setPrimaryItem(position, fragment, force = false) {
|
416
|
-
if (fragment !== this._currentFragment || force) {
|
417
|
-
if (this._currentFragment != null) {
|
418
|
-
this._currentFragment.setMenuVisibility(false);
|
419
|
-
this._currentFragment.setUserVisibleHint(false);
|
420
|
-
}
|
421
|
-
if (fragment != null) {
|
422
|
-
fragment.setMenuVisibility(true);
|
423
|
-
fragment.setUserVisibleHint(true);
|
424
|
-
if (!this.unloadOnTabChange) {
|
425
|
-
this.showFragment(fragment);
|
426
|
-
}
|
427
|
-
}
|
428
|
-
this._currentFragment = fragment;
|
429
|
-
this.selectedIndex = position;
|
430
|
-
const tabItems = this.items;
|
431
|
-
const tabItem = tabItems ? tabItems[position] : null;
|
432
|
-
if (tabItem) {
|
433
|
-
tabItem.canBeLoaded = true;
|
434
|
-
this._loadUnloadTabItems(position);
|
435
|
-
}
|
436
|
-
}
|
437
|
-
}
|
438
|
-
destroyItem(position, fragment) {
|
439
|
-
if (fragment) {
|
440
|
-
this.removeFragment(fragment);
|
441
|
-
const index = this.fragments.indexOf(fragment);
|
442
|
-
if (index !== -1) {
|
443
|
-
this.fragments.splice(index, 1);
|
444
|
-
}
|
445
|
-
if (this._currentFragment === fragment) {
|
446
|
-
this._currentFragment = null;
|
447
|
-
}
|
448
|
-
}
|
449
|
-
if (this.items && this.items[position]) {
|
450
|
-
this.items[position].canBeLoaded = false;
|
451
|
-
}
|
452
|
-
this.items[position].callUnloaded();
|
453
|
-
}
|
454
|
-
hideFragment(fragment, fragmentManager) {
|
455
|
-
if (!fragmentManager) {
|
456
|
-
fragmentManager = this._getParentFragmentManagerFromFragment(fragment);
|
457
|
-
if (!fragmentManager) {
|
458
|
-
return;
|
459
|
-
}
|
460
|
-
}
|
461
|
-
if (fragment) {
|
462
|
-
if (!fragment.isAdded() || fragment.isRemoving()) {
|
463
|
-
return;
|
464
|
-
}
|
465
|
-
else {
|
466
|
-
const fragmentExitTransition = fragment.getExitTransition();
|
467
|
-
if (fragmentExitTransition && fragmentExitTransition instanceof org.nativescript.widgets.CustomTransition) {
|
468
|
-
fragmentExitTransition.setResetOnTransitionEnd(true);
|
469
|
-
}
|
470
|
-
if (fragment && fragment.isAdded() && !fragment.isRemoving()) {
|
471
|
-
const pfm = fragment.getParentFragmentManager ? fragment.getParentFragmentManager() : null;
|
472
|
-
if (pfm && !pfm.isDestroyed()) {
|
473
|
-
try {
|
474
|
-
if (pfm.isStateSaved()) {
|
475
|
-
pfm.beginTransaction().hide(fragment).commitNowAllowingStateLoss();
|
476
|
-
}
|
477
|
-
else {
|
478
|
-
pfm.beginTransaction().hide(fragment).commitNow();
|
479
|
-
}
|
480
|
-
}
|
481
|
-
catch (e) { }
|
482
|
-
}
|
483
|
-
}
|
484
|
-
}
|
485
|
-
}
|
486
|
-
}
|
487
|
-
showFragment(fragment, fragmentManager) {
|
488
|
-
if (!fragmentManager) {
|
489
|
-
fragmentManager = this._getParentFragmentManagerFromFragment(fragment);
|
490
|
-
if (!fragmentManager) {
|
491
|
-
return;
|
492
|
-
}
|
493
|
-
}
|
494
|
-
if (fragment) {
|
495
|
-
if (!fragment.isAdded() || fragment.isRemoving()) {
|
496
|
-
return;
|
497
|
-
}
|
498
|
-
else {
|
499
|
-
const fragmentExitTransition = fragment.getExitTransition();
|
500
|
-
if (fragmentExitTransition && fragmentExitTransition instanceof org.nativescript.widgets.CustomTransition) {
|
501
|
-
fragmentExitTransition.setResetOnTransitionEnd(true);
|
502
|
-
}
|
503
|
-
if (fragment && fragment.isAdded() && !fragment.isRemoving()) {
|
504
|
-
const pfm = fragment.getParentFragmentManager ? fragment.getParentFragmentManager() : null;
|
505
|
-
if (pfm && !pfm.isDestroyed()) {
|
506
|
-
try {
|
507
|
-
if (pfm.isStateSaved()) {
|
508
|
-
pfm.beginTransaction().show(fragment).commitNowAllowingStateLoss();
|
509
|
-
}
|
510
|
-
else {
|
511
|
-
pfm.beginTransaction().show(fragment).commitNow();
|
512
|
-
}
|
513
|
-
}
|
514
|
-
catch (e) { }
|
515
|
-
}
|
516
|
-
}
|
517
|
-
}
|
518
|
-
}
|
519
|
-
}
|
520
|
-
removeFragment(fragment, fragmentManager) {
|
521
|
-
if (!fragmentManager) {
|
522
|
-
fragmentManager = this._getParentFragmentManagerFromFragment(fragment);
|
523
|
-
if (!fragmentManager) {
|
524
|
-
return;
|
525
|
-
}
|
526
|
-
}
|
527
|
-
if (fragment) {
|
528
|
-
if (!fragment.isAdded() || fragment.isRemoving()) {
|
529
|
-
return;
|
530
|
-
}
|
531
|
-
else {
|
532
|
-
const fragmentExitTransition = fragment.getExitTransition();
|
533
|
-
if (fragmentExitTransition && fragmentExitTransition instanceof org.nativescript.widgets.CustomTransition) {
|
534
|
-
fragmentExitTransition.setResetOnTransitionEnd(true);
|
535
|
-
}
|
536
|
-
if (fragment && fragment.isAdded() && !fragment.isRemoving()) {
|
537
|
-
const pfm = fragment.getParentFragmentManager ? fragment.getParentFragmentManager() : null;
|
538
|
-
if (pfm && !pfm.isDestroyed()) {
|
539
|
-
try {
|
540
|
-
if (pfm.isStateSaved()) {
|
541
|
-
pfm.beginTransaction().remove(fragment).commitNowAllowingStateLoss();
|
542
|
-
}
|
543
|
-
else {
|
544
|
-
pfm.beginTransaction().remove(fragment).commitNow();
|
545
|
-
}
|
546
|
-
}
|
547
|
-
catch (e) { }
|
548
|
-
}
|
549
|
-
}
|
550
|
-
}
|
551
|
-
}
|
552
|
-
}
|
553
|
-
setTabStripItems(items) {
|
554
|
-
if (!this.tabStrip || !items) {
|
555
|
-
this._bottomNavigationBar.setItems(null);
|
556
|
-
return;
|
557
|
-
}
|
558
|
-
const tabItems = new Array();
|
559
|
-
items.forEach((tabStripItem, i, arr) => {
|
560
|
-
tabStripItem._index = i;
|
561
|
-
if (items[i]) {
|
562
|
-
const tabItemSpec = this.createTabItemSpec(items[i]);
|
563
|
-
tabItems.push(tabItemSpec);
|
564
|
-
}
|
565
|
-
});
|
566
|
-
this._bottomNavigationBar.setItems(tabItems);
|
567
|
-
items.forEach((item, i, arr) => {
|
568
|
-
const textView = this._bottomNavigationBar.getTextViewForItemAt(i);
|
569
|
-
item.setNativeView(textView);
|
570
|
-
this._setItemColor(item);
|
571
|
-
});
|
572
|
-
}
|
573
|
-
getItemLabelTextTransform(tabStripItem) {
|
574
|
-
const nestedLabel = tabStripItem.label;
|
575
|
-
let textTransform = null;
|
576
|
-
if (nestedLabel && nestedLabel.style.textTransform !== 'initial') {
|
577
|
-
textTransform = nestedLabel.style.textTransform;
|
578
|
-
}
|
579
|
-
else if (tabStripItem.style.textTransform !== 'initial') {
|
580
|
-
textTransform = tabStripItem.style.textTransform;
|
581
|
-
}
|
582
|
-
return textTransform || this._textTransform;
|
583
|
-
}
|
584
|
-
createTabItemSpec(tabStripItem) {
|
585
|
-
const tabItemSpec = new com.nativescript.material.core.TabItemSpec();
|
586
|
-
if (tabStripItem.isLoaded) {
|
587
|
-
const titleLabel = tabStripItem.label;
|
588
|
-
let title = titleLabel.text;
|
589
|
-
const textTransform = this.getItemLabelTextTransform(tabStripItem);
|
590
|
-
title = getTransformedText(title, textTransform);
|
591
|
-
tabItemSpec.title = title;
|
592
|
-
const backgroundColor = tabStripItem.style.backgroundColor;
|
593
|
-
tabItemSpec.backgroundColor = backgroundColor ? backgroundColor.android : this.getTabBarBackgroundArgbColor();
|
594
|
-
const itemColor = this.selectedIndex === tabStripItem._index ? this._selectedItemColor : this._unSelectedItemColor;
|
595
|
-
const color = itemColor || titleLabel.style.color;
|
596
|
-
tabItemSpec.color = color && color.android;
|
597
|
-
const fontInternal = titleLabel.style.fontInternal;
|
598
|
-
if (fontInternal) {
|
599
|
-
tabItemSpec.fontSize = fontInternal.fontSize;
|
600
|
-
tabItemSpec.typeFace = fontInternal.getAndroidTypeface();
|
601
|
-
}
|
602
|
-
const iconSource = tabStripItem.image && tabStripItem.image.src;
|
603
|
-
if (iconSource) {
|
604
|
-
const iconInfo = this.getIconInfo(tabStripItem, itemColor);
|
605
|
-
if (iconInfo) {
|
606
|
-
tabItemSpec.iconDrawable = iconInfo.drawable;
|
607
|
-
tabItemSpec.imageHeight = iconInfo.height;
|
608
|
-
}
|
609
|
-
else {
|
610
|
-
}
|
611
|
-
}
|
612
|
-
}
|
613
|
-
return tabItemSpec;
|
614
|
-
}
|
615
|
-
getOriginalIcon(tabStripItem, color) {
|
616
|
-
const iconSource = tabStripItem.image && tabStripItem.image.src;
|
617
|
-
if (!iconSource) {
|
618
|
-
return null;
|
619
|
-
}
|
620
|
-
let is;
|
621
|
-
if (Utils.isFontIconURI(iconSource)) {
|
622
|
-
const fontIconCode = iconSource.split('//')[1];
|
623
|
-
const target = tabStripItem.image ? tabStripItem.image : tabStripItem;
|
624
|
-
const font = target.style.fontInternal;
|
625
|
-
if (!color) {
|
626
|
-
color = target.style.color;
|
627
|
-
}
|
628
|
-
is = ImageSource.fromFontIconCodeSync(fontIconCode, font, color);
|
629
|
-
}
|
630
|
-
else {
|
631
|
-
is = ImageSource.fromFileOrResourceSync(iconSource);
|
632
|
-
}
|
633
|
-
return is && is.android;
|
634
|
-
}
|
635
|
-
getDrawableInfo(image) {
|
636
|
-
if (image) {
|
637
|
-
if (this.tabStrip && this.tabStrip.isIconSizeFixed) {
|
638
|
-
image = this.getFixedSizeIcon(image);
|
639
|
-
}
|
640
|
-
const imageDrawable = new android.graphics.drawable.BitmapDrawable(Application.android.context.getResources(), image);
|
641
|
-
return {
|
642
|
-
drawable: imageDrawable,
|
643
|
-
height: image.getHeight()
|
644
|
-
};
|
645
|
-
}
|
646
|
-
return new IconInfo();
|
647
|
-
}
|
648
|
-
getIconInfo(tabStripItem, color) {
|
649
|
-
const originalIcon = this.getOriginalIcon(tabStripItem, color);
|
650
|
-
return this.getDrawableInfo(originalIcon);
|
651
|
-
}
|
652
|
-
getFixedSizeIcon(image) {
|
653
|
-
const inWidth = image.getWidth();
|
654
|
-
const inHeight = image.getHeight();
|
655
|
-
const iconSpecSize = getIconSpecSize({
|
656
|
-
width: inWidth,
|
657
|
-
height: inHeight
|
658
|
-
});
|
659
|
-
const widthPixels = iconSpecSize.width * Utils.layout.getDisplayDensity();
|
660
|
-
const heightPixels = iconSpecSize.height * Utils.layout.getDisplayDensity();
|
661
|
-
const scaledImage = android.graphics.Bitmap.createScaledBitmap(image, widthPixels, heightPixels, true);
|
662
|
-
return scaledImage;
|
663
75
|
}
|
664
76
|
updateAndroidItemAt(index, spec) {
|
665
|
-
|
666
|
-
this.
|
77
|
+
try {
|
78
|
+
if (this.mTabsBar) {
|
79
|
+
this.mTabsBar.updateItemAt(index, spec);
|
80
|
+
}
|
667
81
|
}
|
668
|
-
|
669
|
-
getTabBarBackgroundColor() {
|
670
|
-
return this._bottomNavigationBar.getBackground();
|
82
|
+
catch (err) { }
|
671
83
|
}
|
672
84
|
setTabBarBackgroundColor(value) {
|
673
|
-
|
674
|
-
return;
|
675
|
-
}
|
676
|
-
if (value instanceof Color) {
|
677
|
-
this._bottomNavigationBar.setBackgroundColor(value.android);
|
678
|
-
}
|
679
|
-
else {
|
680
|
-
this._bottomNavigationBar.setBackground(tryCloneDrawable(value, this.nativeViewProtected.getResources()));
|
681
|
-
}
|
682
|
-
this.updateTabStripItems();
|
683
|
-
}
|
684
|
-
updateTabStripItems() {
|
685
|
-
this.tabStrip.items.forEach((tabStripItem) => {
|
686
|
-
if (tabStripItem.nativeView) {
|
687
|
-
const tabItemSpec = this.createTabItemSpec(tabStripItem);
|
688
|
-
this.updateAndroidItemAt(tabStripItem._index, tabItemSpec);
|
689
|
-
}
|
690
|
-
});
|
85
|
+
super.setTabBarBackgroundColor(value);
|
691
86
|
}
|
692
87
|
_setItemsColors(items) {
|
693
88
|
items.forEach((item) => {
|
@@ -696,134 +91,22 @@ let BottomNavigation = class BottomNavigation extends TabNavigationBase {
|
|
696
91
|
}
|
697
92
|
});
|
698
93
|
}
|
699
|
-
getTabBarSelectedItemColor() {
|
700
|
-
return this._selectedItemColor;
|
701
|
-
}
|
702
94
|
setTabBarSelectedItemColor(value) {
|
703
|
-
|
95
|
+
super.setTabBarSelectedItemColor(value);
|
704
96
|
this._setItemsColors(this.tabStrip.items);
|
705
97
|
}
|
706
|
-
getTabBarUnSelectedItemColor() {
|
707
|
-
return this._unSelectedItemColor;
|
708
|
-
}
|
709
98
|
setTabBarUnSelectedItemColor(value) {
|
710
|
-
|
99
|
+
super.setTabBarUnSelectedItemColor(value);
|
711
100
|
this._setItemsColors(this.tabStrip.items);
|
712
101
|
}
|
713
|
-
|
714
|
-
|
715
|
-
|
716
|
-
this.
|
717
|
-
}
|
718
|
-
setTabBarItemTitle(tabStripItem, value) {
|
719
|
-
this.updateItem(tabStripItem);
|
720
|
-
}
|
721
|
-
setTabBarItemBackgroundColor(tabStripItem, value) {
|
722
|
-
this.updateItem(tabStripItem);
|
723
|
-
}
|
724
|
-
_setItemColor(tabStripItem) {
|
725
|
-
const itemColor = tabStripItem._index === this.selectedIndex ? this._selectedItemColor : this._unSelectedItemColor;
|
726
|
-
if (!itemColor) {
|
727
|
-
return;
|
728
|
-
}
|
729
|
-
tabStripItem.nativeViewProtected.setTextColor(itemColor.android);
|
730
|
-
this.setIconColor(tabStripItem, itemColor);
|
731
|
-
}
|
732
|
-
setIconColor(tabStripItem, color) {
|
733
|
-
const tabBarItem = this._bottomNavigationBar.getViewForItemAt(tabStripItem._index);
|
734
|
-
if (!tabBarItem) {
|
735
|
-
return;
|
736
|
-
}
|
737
|
-
const drawableInfo = this.getIconInfo(tabStripItem, color);
|
738
|
-
const imgView = tabBarItem.getChildAt(0);
|
739
|
-
imgView.setImageDrawable(drawableInfo.drawable);
|
740
|
-
if (color) {
|
741
|
-
imgView.setColorFilter(color.android);
|
742
|
-
}
|
743
|
-
}
|
744
|
-
setTabBarItemColor(tabStripItem, value) {
|
745
|
-
const itemColor = tabStripItem._index === this.selectedIndex ? this._selectedItemColor : this._unSelectedItemColor;
|
746
|
-
if (itemColor) {
|
747
|
-
return;
|
748
|
-
}
|
749
|
-
const androidColor = value instanceof Color ? value.android : value;
|
750
|
-
tabStripItem.nativeViewProtected.setTextColor(androidColor);
|
751
|
-
}
|
752
|
-
setTabBarIconColor(tabStripItem, value) {
|
753
|
-
const itemColor = tabStripItem._index === this.selectedIndex ? this._selectedItemColor : this._unSelectedItemColor;
|
754
|
-
if (itemColor) {
|
755
|
-
return;
|
756
|
-
}
|
757
|
-
this.setIconColor(tabStripItem);
|
758
|
-
}
|
759
|
-
setTabBarIconSource(tabStripItem, value) {
|
760
|
-
this.updateItem(tabStripItem);
|
761
|
-
}
|
762
|
-
setTabBarItemFontInternal(tabStripItem, value) {
|
763
|
-
if (value.fontSize) {
|
764
|
-
tabStripItem.nativeViewProtected.setTextSize(value.fontSize);
|
765
|
-
}
|
766
|
-
tabStripItem.nativeViewProtected.setTypeface(value.getAndroidTypeface());
|
767
|
-
}
|
768
|
-
setTabBarItemTextTransform(tabStripItem, value) {
|
769
|
-
const titleLabel = tabStripItem.label;
|
770
|
-
const title = getTransformedText(titleLabel.text, value);
|
771
|
-
tabStripItem.nativeViewProtected.setText(title);
|
772
|
-
}
|
773
|
-
getTabBarTextTransform() {
|
774
|
-
return this._textTransform;
|
775
|
-
}
|
776
|
-
setTabBarTextTransform(value) {
|
777
|
-
const items = this.tabStrip && this.tabStrip.items;
|
778
|
-
if (items) {
|
779
|
-
items.forEach((tabStripItem) => {
|
780
|
-
if (tabStripItem.label && tabStripItem.nativeViewProtected) {
|
781
|
-
const nestedLabel = tabStripItem.label;
|
782
|
-
const title = getTransformedText(nestedLabel.text, value);
|
783
|
-
tabStripItem.nativeViewProtected.setText(title);
|
784
|
-
}
|
785
|
-
});
|
786
|
-
}
|
787
|
-
this._textTransform = value;
|
788
|
-
}
|
789
|
-
[selectedIndexProperty.setNative](value) {
|
790
|
-
if (this.tabStrip) {
|
791
|
-
this._bottomNavigationBar.setSelectedPosition(value);
|
792
|
-
}
|
793
|
-
else {
|
794
|
-
this.changeTab(value);
|
795
|
-
}
|
796
|
-
}
|
797
|
-
[itemsProperty.getDefault]() {
|
798
|
-
return null;
|
799
|
-
}
|
800
|
-
[itemsProperty.setNative](value) {
|
801
|
-
if (value) {
|
802
|
-
value.forEach((item, i) => {
|
803
|
-
item.index = i;
|
804
|
-
});
|
805
|
-
}
|
806
|
-
selectedIndexProperty.coerce(this);
|
807
|
-
}
|
808
|
-
[tabStripProperty.getDefault]() {
|
809
|
-
return null;
|
810
|
-
}
|
811
|
-
[tabStripProperty.setNative](value) {
|
812
|
-
const items = this.tabStrip ? this.tabStrip.items : null;
|
813
|
-
this.setTabStripItems(items);
|
102
|
+
onTabsBarSelectedPositionChange(position, prevPosition) {
|
103
|
+
super.onTabsBarSelectedPositionChange(position, prevPosition);
|
104
|
+
this.mViewPager.setCurrentItem(position, true);
|
105
|
+
this._setItemsColors(this.tabStrip.items);
|
814
106
|
}
|
815
107
|
};
|
816
108
|
BottomNavigation = __decorate([
|
817
109
|
CSSType('BottomNavigation')
|
818
110
|
], BottomNavigation);
|
819
111
|
export { BottomNavigation };
|
820
|
-
function tryCloneDrawable(value, resources) {
|
821
|
-
if (value) {
|
822
|
-
const constantState = value.getConstantState();
|
823
|
-
if (constantState) {
|
824
|
-
return constantState.newDrawable(resources);
|
825
|
-
}
|
826
|
-
}
|
827
|
-
return value;
|
828
|
-
}
|
829
112
|
//# sourceMappingURL=index.android.js.map
|