diff --git a/.gitignore b/.gitignore index 3fe3476..038531a 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,5 @@ android/build build node_modules rn-cli.config.js +.DS_Store + diff --git a/Tab.js b/Tab.js index 9565608..e7cb1bc 100644 --- a/Tab.js +++ b/Tab.js @@ -18,6 +18,8 @@ class Tab extends Component { name: PropTypes.string, onTabSelected: PropTypes.func, textColor: PropTypes.string, + textSize: PropTypes.number, + textMargin: PropTypes.number, }; onTabSelected = (e) => { diff --git a/android/src/main/java/com/xebia/reactnative/ReactTabStub.java b/android/src/main/java/com/xebia/reactnative/ReactTabStub.java index 5d159c1..a300eb0 100644 --- a/android/src/main/java/com/xebia/reactnative/ReactTabStub.java +++ b/android/src/main/java/com/xebia/reactnative/ReactTabStub.java @@ -12,6 +12,7 @@ import android.widget.FrameLayout; import android.widget.ImageView; import android.widget.TextView; +import android.widget.LinearLayout; import com.facebook.stetho.common.StringUtil; public class ReactTabStub extends ViewGroup { @@ -38,6 +39,8 @@ protected void onLayout(boolean changed, int l, int t, int r, int b) { private String iconUri; private int iconSize; private int textColor; + private int textSize; + private int textMargin; public void attachCustomTabView(Tab tab) { Log.d(TAG, "attachCustomTabView"); @@ -58,6 +61,12 @@ public void attachCustomTabView(Tab tab) { if (textColor != 0) { textColorChanged(); } + if (textSize != 0) { + textSizeChanged(); + } + if (textMargin != 0) { + textMarginChanged(); + } if (iconUri != null) { iconUriChanged(); } else if (iconResId != null) { @@ -101,6 +110,16 @@ public void setTextColor(int textColor) { textColorChanged(); } + public void setTextSize(int textSize) { + this.textSize = textSize; + textSizeChanged(); + } + + public void setTextMargin(int textMargin) { + this.textMargin = textMargin; + textMarginChanged(); + } + public void setCustomView(View customView) { this.customView = customView; customViewChanged(); @@ -177,6 +196,22 @@ private void textColorChanged() { tabText.setTextColor(textColor); } + private void textSizeChanged() { + if (tabText == null) return; + Log.d(TAG, "textSizeChanged: " + textSize); + + tabText.setTextSize(textSize); + } + + private void textMarginChanged() { + if (tabText == null) return; + Log.d(TAG, "textMarginChanged: " + textMargin); + + LinearLayout.LayoutParams margin = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); + margin.setMargins(0, textMargin, 0, 0); + tabText.setLayoutParams(margin); + } + public void accessibilityLabelChanged() { if (customView == null || customView.getParent() == null) return; CharSequence contentDescription = getContentDescription(); diff --git a/android/src/main/java/com/xebia/reactnative/TabManager.java b/android/src/main/java/com/xebia/reactnative/TabManager.java index eee9276..f571fc7 100644 --- a/android/src/main/java/com/xebia/reactnative/TabManager.java +++ b/android/src/main/java/com/xebia/reactnative/TabManager.java @@ -64,6 +64,16 @@ public void setTextColor(ReactTabStub view, int textColor) { view.setTextColor(textColor); } + @ReactProp(name = "textSize") + public void setTextSize(ReactTabStub view, int textSize) { + view.setTextSize(textSize); + } + + @ReactProp(name = "textMargin") + public void setTextMargin(ReactTabStub view, int textMargin) { + view.setTextMargin(textMargin); + } + @Override public void setAccessibilityLabel(ReactTabStub view, String accessibilityLabel) { view.setAccessibilityLabel(accessibilityLabel);