Skip to content

Commit db104bf

Browse files
committed
chore: Making use of AndroidHelper functions in segmented bar module
1 parent 747753a commit db104bf

File tree

2 files changed

+3
-13
lines changed

2 files changed

+3
-13
lines changed

apps/automated/src/ui/segmented-bar/segmented-bar-tests-native.android.ts

+2-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as segmentedBarModule from '@nativescript/core/ui/segmented-bar';
22
import { Color } from '@nativescript/core';
3+
import { AndroidHelper } from '@nativescript/core/ui/core/view';
34

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

47-
const newDrawable = tryCloneDrawable(view.getBackground(), view.getResources());
48+
const newDrawable = AndroidHelper.getCopyOrDrawable(view.getBackground(), view.getResources());
4849
newDrawable.setColorFilter(new android.graphics.Paint(bar.selectedBackgroundColor.android).getColorFilter());
4950

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

71-
function tryCloneDrawable(value: android.graphics.drawable.Drawable, resources: android.content.res.Resources): android.graphics.drawable.Drawable {
72-
if (value) {
73-
const constantState = value.getConstantState();
74-
if (constantState) {
75-
return constantState.newDrawable(resources);
76-
}
77-
}
78-
79-
return value;
80-
}
81-
8272
return isValid === 0;
8373
};

packages/core/ui/segmented-bar/index.android.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ export class SegmentedBarItem extends SegmentedBarItemBase {
171171
const backgroundDrawable = viewGroup.getBackground();
172172
if (SDK_VERSION > 21 && backgroundDrawable) {
173173
const newDrawable = AndroidHelper.getCopyOrDrawable(backgroundDrawable, nativeView.getResources());
174-
newDrawable.setColorFilter(new android.graphics.Paint(color).getColorFilter());
174+
AndroidHelper.setDrawableColor(color, newDrawable);
175175
viewGroup.setBackground(newDrawable);
176176
} else {
177177
const stateDrawable = new android.graphics.drawable.StateListDrawable();

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy