Skip to content

Commit db7c8ea

Browse files
committed
chore: refactor to prevent null context
1 parent dd334ef commit db7c8ea

File tree

4 files changed

+13
-17
lines changed

4 files changed

+13
-17
lines changed

src/button/button.android.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,8 @@ export class Button extends ButtonBase {
5353
}
5454
layoutId = layoutIds[layoutStringId];
5555
if (!layoutId) {
56-
layoutId = layoutIds[layoutStringId] = getLayout(layoutStringId);
56+
layoutId = layoutIds[layoutStringId] = getLayout(this._context, layoutStringId);
5757
}
58-
// const layoutId = getLayout(layoutIdName);
5958
if (!LayoutInflater) {
6059
LayoutInflater = android.view.LayoutInflater;
6160
}

src/core/android/utils.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -230,26 +230,23 @@ export function setFocusable(view: android.view.View, focusable: boolean) {
230230
view.setFocusableInTouchMode(focusable);
231231
}
232232

233-
export function getLayout(id: string) {
234-
if (!id) {
233+
export function getLayout(context: android.content.Context, id: string) {
234+
if (!id || !context) {
235235
return 0;
236236
}
237-
const context: android.content.Context = Application.android.context;
238237
return context.getResources().getIdentifier(id, 'layout', context.getPackageName());
239238
}
240239

241-
export function getStyle(id: string) {
242-
if (!id) {
240+
export function getStyle(context: android.content.Context, id: string) {
241+
if (!id || !context) {
243242
return 0;
244243
}
245-
const context: android.content.Context = Application.android.context;
246244
return context.getResources().getIdentifier(id, 'style', context.getPackageName());
247245
}
248-
export function getAttr(id: string) {
249-
if (!id) {
246+
export function getAttr(context: android.content.Context, id: string) {
247+
if (!id || !context) {
250248
return 0;
251249
}
252-
const context: android.content.Context = Application.android.context;
253250
return context.getResources().getIdentifier(id, 'attr', context.getPackageName());
254251
}
255252

src/textfield/textfield.android.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,17 @@ export class TextField extends TextFieldBase {
7070
let needsTransparent = false;
7171
if (variant === 'filled') {
7272
if (!filledId) {
73-
filledId = getLayout('material_text_field_filled');
73+
filledId = getLayout(this._context, 'material_text_field_filled');
7474
}
7575
layoutId = filledId;
7676
} else if (variant === 'outline') {
7777
if (!outlineId) {
78-
outlineId = getLayout('material_text_field_outline');
78+
outlineId = getLayout(this._context, 'material_text_field_outline');
7979
}
8080
layoutId = outlineId;
8181
} else {
8282
if (!noneId) {
83-
noneId = getLayout('material_text_field');
83+
noneId = getLayout(this._context, 'material_text_field');
8484
}
8585
layoutId = noneId;
8686
needsTransparent = true;

src/textview/textview.android.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,17 @@ export class TextView extends TextViewBase {
6666
let needsTransparent = false;
6767
if (variant === 'filled') {
6868
if (!filledId) {
69-
filledId = getLayout('material_text_view_filled');
69+
filledId = getLayout(this._context, 'material_text_view_filled');
7070
}
7171
layoutId = filledId;
7272
} else if (variant === 'outline') {
7373
if (!outlineId) {
74-
outlineId = getLayout('material_text_view_outline');
74+
outlineId = getLayout(this._context, 'material_text_view_outline');
7575
}
7676
layoutId = outlineId;
7777
} else {
7878
if (!noneId) {
79-
noneId = getLayout('material_text_view');
79+
noneId = getLayout(this._context, 'material_text_view');
8080
}
8181
layoutId = noneId;
8282
needsTransparent = true;

0 commit comments

Comments
 (0)