@nativescript-community/ui-material-core-tabs 7.0.7 → 7.0.10
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
CHANGED
@@ -3,6 +3,33 @@
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
5
5
|
|
6
|
+
## [7.0.10](https://github.com/nativescript-community/ui-material-components/compare/v7.0.9...v7.0.10) (2022-05-12)
|
7
|
+
|
8
|
+
**Note:** Version bump only for package @nativescript-community/ui-material-core-tabs
|
9
|
+
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
|
14
|
+
## [7.0.9](https://github.com/nativescript-community/ui-material-components/compare/v7.0.8...v7.0.9) (2022-05-12)
|
15
|
+
|
16
|
+
**Note:** Version bump only for package @nativescript-community/ui-material-core-tabs
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
## [7.0.8](https://github.com/nativescript-community/ui-material-components/compare/v7.0.7...v7.0.8) (2022-05-10)
|
23
|
+
|
24
|
+
|
25
|
+
### Bug Fixes
|
26
|
+
|
27
|
+
* **tabs:** correctly calculate sizing and animation positions ([20a977d](https://github.com/nativescript-community/ui-material-components/commit/20a977dcc436dff54878034ea3305c20afa6898a))
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
|
32
|
+
|
6
33
|
## [7.0.7](https://github.com/nativescript-community/ui-material-components/compare/v7.0.6...v7.0.7) (2022-05-09)
|
7
34
|
|
8
35
|
**Note:** Version bump only for package @nativescript-community/ui-material-core-tabs
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@nativescript-community/ui-material-core-tabs",
|
3
|
-
"version": "7.0.
|
3
|
+
"version": "7.0.10",
|
4
4
|
"description": "Material Core Tabs component",
|
5
5
|
"main": "./index",
|
6
6
|
"sideEffects": false,
|
@@ -39,7 +39,7 @@
|
|
39
39
|
"repository": "https://github.com/nativescript-community/ui-material-components",
|
40
40
|
"readmeFilename": "README.md",
|
41
41
|
"dependencies": {
|
42
|
-
"@nativescript-community/ui-material-core": "^7.0.
|
42
|
+
"@nativescript-community/ui-material-core": "^7.0.10"
|
43
43
|
},
|
44
|
-
"gitHead": "
|
44
|
+
"gitHead": "ac0b95759c348a33d49c2dfc183d7bdc2dec29e1"
|
45
45
|
}
|
@@ -43,7 +43,11 @@ class TabStrip extends LinearLayout {
|
|
43
43
|
|
44
44
|
private final int mDefaultBottomBorderColor;
|
45
45
|
|
46
|
+
// selected tab position (final)
|
46
47
|
private int mSelectedPosition;
|
48
|
+
// current tab position for when the view is animating (scrolling)
|
49
|
+
private int mSelectionTabPosition;
|
50
|
+
// scrolling offset in relation to the current tab position
|
47
51
|
private float mSelectionOffset;
|
48
52
|
|
49
53
|
private final SimpleTabColorizer mDefaultTabColorizer;
|
@@ -173,6 +177,7 @@ class TabStrip extends LinearLayout {
|
|
173
177
|
|
174
178
|
|
175
179
|
void onTabsViewPagerPageChanged(int position, float positionOffset) {
|
180
|
+
mSelectionTabPosition = position;
|
176
181
|
mSelectionOffset = positionOffset;
|
177
182
|
invalidate();
|
178
183
|
}
|
@@ -206,24 +211,30 @@ class TabStrip extends LinearLayout {
|
|
206
211
|
final SimpleTabColorizer tabColorizer = mDefaultTabColorizer;
|
207
212
|
|
208
213
|
// Thick colored underline below the current selection
|
209
|
-
if (childCount > 0 &&
|
210
|
-
View selectedTitle = getChildAt(
|
214
|
+
if (childCount > 0 && mSelectionTabPosition < childCount) {
|
215
|
+
View selectedTitle = getChildAt(mSelectionTabPosition);
|
211
216
|
int left = selectedTitle.getLeft();
|
217
|
+
int width = selectedTitle.getWidth();
|
212
218
|
int right = selectedTitle.getRight();
|
213
|
-
int color = tabColorizer.getIndicatorColor(
|
214
|
-
|
215
|
-
|
216
|
-
|
219
|
+
int color = tabColorizer.getIndicatorColor(mSelectionTabPosition);
|
220
|
+
int nextTab = mSelectionTabPosition + 1;
|
221
|
+
|
222
|
+
// we're always at mSelectionTabPosition + mSelectionOffset (ex: 1 + 0.5)
|
223
|
+
// if we mSelectionOffset > 0f then we need to mutate the position, width and color of the selection
|
224
|
+
// if we're on the last tab, nextTab will be getChildCount() + 1 so it won't enter as there's nothing to animate
|
225
|
+
if (mSelectionOffset > 0f && nextTab >= 0 && nextTab < getChildCount()) {
|
226
|
+
int nextColor = tabColorizer.getIndicatorColor(nextTab);
|
217
227
|
if (color != nextColor) {
|
218
228
|
color = blendColors(nextColor, color, mSelectionOffset);
|
219
229
|
}
|
220
230
|
|
221
231
|
// Draw the selection partway between the tabs
|
222
|
-
View nextTitle = getChildAt(
|
223
|
-
left
|
224
|
-
|
225
|
-
right
|
226
|
-
|
232
|
+
View nextTitle = getChildAt(nextTab);
|
233
|
+
// left is the current tab left + it's width * mSelectionOffset ex: 0 + (100 * 0.5) = 50, halfway through the current cell
|
234
|
+
left = (int) (left + mSelectionOffset * width);
|
235
|
+
// right is the tab right + the next tab's width * mSelectionOffset ex: 100 + (200 * 0.5) = 200, halfway through the next cell
|
236
|
+
// this ensures that the width mutates smoothly as we move between cells
|
237
|
+
right = (int) (right + mSelectionOffset * nextTitle.getWidth());
|
227
238
|
}
|
228
239
|
|
229
240
|
mSelectedIndicatorPaint.setColor(color);
|
@@ -116,6 +116,8 @@ public class TabsBar extends HorizontalScrollView {
|
|
116
116
|
|
117
117
|
public void setDistributeEvenly(boolean distributeEvenly) {
|
118
118
|
mDistributeEvenly = distributeEvenly;
|
119
|
+
mTabStrip.setMeasureWithLargestChildEnabled(distributeEvenly);
|
120
|
+
refreshTabStrip();
|
119
121
|
}
|
120
122
|
|
121
123
|
/**
|
@@ -300,10 +302,13 @@ public class TabsBar extends HorizontalScrollView {
|
|
300
302
|
ll.setMinimumHeight((int) (SMALL_MIN_HEIGHT * density));
|
301
303
|
}
|
302
304
|
|
305
|
+
LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) ll.getLayoutParams();
|
303
306
|
if (mDistributeEvenly) {
|
304
|
-
LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) ll.getLayoutParams();
|
305
307
|
lp.width = 0;
|
306
308
|
lp.weight = 1;
|
309
|
+
} else {
|
310
|
+
lp.width = ViewGroup.LayoutParams.WRAP_CONTENT;
|
311
|
+
lp.weight = 0;
|
307
312
|
}
|
308
313
|
}
|
309
314
|
|
@@ -355,6 +360,21 @@ public class TabsBar extends HorizontalScrollView {
|
|
355
360
|
}
|
356
361
|
}
|
357
362
|
|
363
|
+
private void refreshTabStrip() {
|
364
|
+
final FragmentStateAdapter adapter = (FragmentStateAdapter)mViewPager.getAdapter();
|
365
|
+
for (int i = 0; i < adapter.getItemCount(); i++) {
|
366
|
+
TabItemSpec tabItem;
|
367
|
+
if (this.mTabItems != null && this.mTabItems.length > i) {
|
368
|
+
tabItem = this.mTabItems[i];
|
369
|
+
} else {
|
370
|
+
tabItem = new TabItemSpec();
|
371
|
+
}
|
372
|
+
if (i < mTabStrip.getChildCount()) {
|
373
|
+
this.updateItemAt(i, tabItem);
|
374
|
+
}
|
375
|
+
}
|
376
|
+
}
|
377
|
+
|
358
378
|
public void setContentDescription(int i, String desc) {
|
359
379
|
mContentDescriptions.put(i, desc);
|
360
380
|
}
|