Skip to content

Commit

Permalink
chore: Making use of AndroidHelper functions in segmented bar module
Browse files Browse the repository at this point in the history
  • Loading branch information
Dimitris - Rafail Katsampas committed Mar 15, 2024
1 parent 747753a commit dba175a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as segmentedBarModule from '@nativescript/core/ui/segmented-bar';
import { Color } from '@nativescript/core';
import { AndroidHelper } from '@nativescript/core/ui/core/view';

export function getNativeTabWidget(bar: segmentedBarModule.SegmentedBar): android.widget.TabWidget {
return (<android.widget.TabHost>bar.android).getTabWidget();
Expand Down Expand Up @@ -44,7 +45,7 @@ export var checkBackgroundColorUpdatedAfterItemSelected = function (bar: segment
const item = bar.items[i];
const textView = item?.nativeViewProtected;

const newDrawable = tryCloneDrawable(view.getBackground(), view.getResources());
const newDrawable = AndroidHelper.getCopyOrDrawable(view.getBackground(), view.getResources());
newDrawable.setColorFilter(new android.graphics.Paint(bar.selectedBackgroundColor.android).getColorFilter());

if (bar.selectedIndex == i) {
Expand All @@ -68,16 +69,5 @@ export var checkBackgroundColorUpdatedAfterItemSelected = function (bar: segment
}
}

function tryCloneDrawable(value: android.graphics.drawable.Drawable, resources: android.content.res.Resources): android.graphics.drawable.Drawable {
if (value) {
const constantState = value.getConstantState();
if (constantState) {
return constantState.newDrawable(resources);
}
}

return value;
}

return isValid === 0;
};
2 changes: 1 addition & 1 deletion packages/core/ui/segmented-bar/index.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export class SegmentedBarItem extends SegmentedBarItemBase {
const backgroundDrawable = viewGroup.getBackground();
if (SDK_VERSION > 21 && backgroundDrawable) {
const newDrawable = AndroidHelper.getCopyOrDrawable(backgroundDrawable, nativeView.getResources());
newDrawable.setColorFilter(new android.graphics.Paint(color).getColorFilter());
AndroidHelper.setDrawableColor(color, newDrawable);
viewGroup.setBackground(newDrawable);
} else {
const stateDrawable = new android.graphics.drawable.StateListDrawable();
Expand Down

0 comments on commit dba175a

Please sign in to comment.