Skip to content

Commit 1eff66f

Browse files
committed
chore: new core-tabs package
1 parent e62441d commit 1eff66f

File tree

37 files changed

+412
-1134
lines changed

37 files changed

+412
-1134
lines changed

packages/bottom-navigation/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@
5151
},
5252
"readmeFilename": "README.md",
5353
"dependencies": {
54-
"@nativescript-community/ui-material-core": "^6.2.20"
54+
"@nativescript-community/ui-material-core": "^6.2.20",
55+
"@nativescript-community/ui-material-core-tabs": "^6.2.20"
5556
},
5657
"gitHead": "f4a17600487dd826a4a581f2ebde8cf6457710ca"
5758
}

packages/bottom-navigation/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"paths": {
77
"@nativescript-community/ui-material-core": ["packages/core/index"],
88
"@nativescript-community/ui-material-core/*": ["packages/core/*"],
9+
"@nativescript-community/ui-material-core-tabs/*": ["packages/core-tabs/*"],
910
}
1011
},
1112
"include": ["../../src/bottom-navigation/**/*.ts", "../../references.d.ts", "../../src/references.d.ts"],

packages/core-tabs/.npmignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
node_modules/
2+
pnpm-global/
3+
bin/
4+
src/
5+
hooks/
6+
*.ts
7+
*.old
8+
tsconfig.json
9+
!*.d.ts

packages/core-tabs/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Nativescript Material Core
2+
3+
[npm-url]:https://npmjs.org/package/nativescript-material-components
4+
5+
Core module for all Nativescript material components

packages/core-tabs/package.json

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
"name": "@nativescript-community/ui-material-core-tabs",
3+
"version": "6.2.20",
4+
"description": "Material Core Tabs component",
5+
"main": "./index",
6+
"sideEffects": false,
7+
"typings": "./index.d.ts",
8+
"scripts": {
9+
"tsc": "../../node_modules/.bin/cpy '**/*.d.ts' '../../packages/core-tabs' --cwd=../../src/core-tabs --parents && ../../node_modules/.bin/tsc -d",
10+
"tsc-win": "..\\..\\node_modules\\.bin\\cpy '**/*.d.ts' '..\\..\\packages\\core-tabs' --cwd=..\\..\\src\\core-tabs --parents && ..\\..\\node_modules\\.bin\\tsc -d",
11+
"build": "npm run tsc ",
12+
"build.watch": "npm run tsc -- -w",
13+
"build.win": "npm run tsc-win ",
14+
"build.all": "npm run build.hooks && npm run build",
15+
"build.all.win": "npm run build.hooks.win && npm run build.win",
16+
"clean": "../../node_modules/.bin/rimraf ./*.d.ts ./*.js ./*.js.map android"
17+
},
18+
"nativescript": {
19+
"platforms": {
20+
"android": "6.2.0",
21+
"ios": "6.2.0"
22+
}
23+
},
24+
"keywords": [
25+
"NativeScript",
26+
"JavaScript",
27+
"Android",
28+
"iOS"
29+
],
30+
"author": {
31+
"name": "Martin Guillon",
32+
"email": "[email protected]"
33+
},
34+
"bugs": {
35+
"url": "https://github.com/nativescript-community/ui-material-components/issues"
36+
},
37+
"license": "Apache-2.0",
38+
"homepage": "https://github.com/nativescript-community/ui-material-components",
39+
"repository": "https://github.com/nativescript-community/ui-material-components",
40+
"readmeFilename": "README.md",
41+
"dependencies": {
42+
"@nativescript-community/ui-material-core": "^6.2.20"
43+
},
44+
"gitHead": "f4a17600487dd826a4a581f2ebde8cf6457710ca"
45+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.nativescript.material.coretabs"/>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
dependencies {
3+
def androidxViewPager2Version = project.hasProperty("androidxViewPager2Version") ? project.androidxViewPager2Version : "1.0.0"
4+
implementation "androidx.viewpager2:viewpager2:$androidxViewPager2Version"
5+
}

packages/core/platforms/android/java/com/nativescript/material/core/BottomNavigationBar.java renamed to packages/core-tabs/platforms/android/java/com/nativescript/material/core/BottomNavigationBar.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,8 +287,8 @@ public void setSelectedPosition(int position) {
287287
return;
288288
}
289289

290-
mTabStrip.setSelectedPosition(position);
291290
onSelectedPositionChange(position, prevPosition);
291+
mTabStrip.setSelectedPosition(position);
292292
}
293293

294294
public void setContentDescription(int i, String desc) {

packages/core/platforms/android/java/com/nativescript/material/core/TabStrip.java renamed to packages/core-tabs/platforms/android/java/com/nativescript/material/core/TabStrip.java

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import android.graphics.Paint;
2424
import android.util.AttributeSet;
2525
import android.util.TypedValue;
26+
import android.util.Log;
2627
import android.view.View;
2728
import android.widget.LinearLayout;
2829
import android.widget.TextView;
@@ -45,7 +46,6 @@ class TabStrip extends LinearLayout {
4546
private int mSelectedPosition;
4647
private float mSelectionOffset;
4748

48-
private TabLayout.TabColorizer mCustomTabColorizer;
4949
private final SimpleTabColorizer mDefaultTabColorizer;
5050

5151
private int mTabTextColor;
@@ -94,14 +94,7 @@ class TabStrip extends LinearLayout {
9494
setMeasureWithLargestChildEnabled(true);
9595
}
9696

97-
void setCustomTabColorizer(TabLayout.TabColorizer customTabColorizer) {
98-
mCustomTabColorizer = customTabColorizer;
99-
invalidate();
100-
}
101-
10297
void setSelectedIndicatorColors(int... colors) {
103-
// Make sure that the custom colorizer is removed
104-
mCustomTabColorizer = null;
10598
mDefaultTabColorizer.setIndicatorColors(colors);
10699
invalidate();
107100
}
@@ -128,12 +121,24 @@ void setShouldUpdateTabsTextColor(boolean value) {
128121
mShouldUpdateTabsTextColor = value;
129122
}
130123

124+
125+
private void updateTabTextColor(int index, boolean selected){
126+
if (mShouldUpdateTabsTextColor) {
127+
TextView textView = getTextViewAt(index);
128+
if (selected){
129+
textView.setTextColor(mSelectedTabTextColor);
130+
}
131+
else {
132+
textView.setTextColor(mTabTextColor);
133+
}
134+
}
135+
}
136+
131137
private void updateTabsTextColor(){
132138
if (mShouldUpdateTabsTextColor) {
133139
final int childCount = getChildCount();
134140
for (int i = 0; i < childCount; i++){
135-
LinearLayout linearLayout = (LinearLayout)getChildAt(i);
136-
TextView textView = (TextView)linearLayout.getChildAt(1);
141+
TextView textView = getTextViewAt(i);
137142
if (i == mSelectedPosition){
138143
textView.setTextColor(mSelectedTabTextColor);
139144
}
@@ -153,26 +158,21 @@ float getTabTextFontSize(){
153158
return mTabTextFontSize;
154159
}
155160

161+
private TextView getTextViewAt(int index) {
162+
LinearLayout linearLayout = (LinearLayout)getChildAt(index);
163+
return (TextView)linearLayout.getChildAt(1);
164+
}
165+
156166
private void updateTabsTextFontSize(){
157167
final int childCount = getChildCount();
158168
for (int i = 0; i < childCount; i++){
159-
LinearLayout linearLayout = (LinearLayout)getChildAt(i);
160-
TextView textView = (TextView)linearLayout.getChildAt(1);
169+
TextView textView = getTextViewAt(i);
161170
textView.setTextSize(mTabTextFontSize);
162171
}
163172
}
164173

165-
// Used by TabLayout (the 'old' tab-view control)
166-
void onViewPagerPageChanged(int position, float positionOffset) {
167-
mSelectedPosition = position;
168-
mSelectionOffset = positionOffset;
169-
invalidate();
170-
updateTabsTextColor();
171-
}
172174

173-
// Used by TabsBar
174175
void onTabsViewPagerPageChanged(int position, float positionOffset) {
175-
mSelectedPosition = position;
176176
mSelectionOffset = positionOffset;
177177
invalidate();
178178
}
@@ -182,9 +182,14 @@ int getSelectedPosition(){
182182
}
183183

184184
void setSelectedPosition(int position) {
185-
mSelectedPosition = position;
186-
invalidate();
187-
updateTabsTextColor();
185+
if (mSelectedPosition != position) {
186+
getChildAt(mSelectedPosition).setSelected(false);
187+
getChildAt(position).setSelected(true);
188+
updateTabTextColor(mSelectedPosition, false);
189+
updateTabTextColor(position, false);
190+
mSelectedPosition = position;
191+
invalidate();
192+
}
188193
}
189194

190195
@Override
@@ -193,9 +198,7 @@ protected void dispatchDraw(Canvas canvas) {
193198

194199
final int height = getHeight();
195200
final int childCount = getChildCount();
196-
final TabLayout.TabColorizer tabColorizer = mCustomTabColorizer != null
197-
? mCustomTabColorizer
198-
: mDefaultTabColorizer;
201+
final SimpleTabColorizer tabColorizer = mDefaultTabColorizer;
199202

200203
// Thick colored underline below the current selection
201204
if (childCount > 0 && mSelectedPosition < childCount) {
@@ -249,10 +252,9 @@ private static int blendColors(int color1, int color2, float ratio) {
249252
return Color.rgb((int) r, (int) g, (int) b);
250253
}
251254

252-
private static class SimpleTabColorizer implements TabLayout.TabColorizer {
255+
private static class SimpleTabColorizer {
253256
private int[] mIndicatorColors;
254257

255-
@Override
256258
public final int getIndicatorColor(int position) {
257259
return mIndicatorColors[position % mIndicatorColors.length];
258260
}

0 commit comments

Comments
 (0)