Skip to content
This repository was archived by the owner on Aug 14, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ android/build
build
node_modules
rn-cli.config.js
.DS_Store

2 changes: 2 additions & 0 deletions Tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
35 changes: 35 additions & 0 deletions android/src/main/java/com/xebia/reactnative/ReactTabStub.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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");
Expand All @@ -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) {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
10 changes: 10 additions & 0 deletions android/src/main/java/com/xebia/reactnative/TabManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down