Skip to content

Commit 8f4d1b1

Browse files
committed
fix(core): android crash with N 8.2
1 parent 0f4b7ae commit 8f4d1b1

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

src/core/index.android.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ import {
55
Color,
66
Length,
77
PercentLength,
8+
Utils,
89
View,
910
androidDynamicElevationOffsetProperty,
1011
androidElevationProperty,
11-
backgroundInternalProperty,
12-
profile
12+
backgroundInternalProperty
1313
} from '@nativescript/core';
1414
import { createRippleDrawable, createStateListAnimator, getAttrColor, getColorStateList, handleClearFocus, isPostLollipop, isPostLollipopMR1, isPostMarshmallow } from './android/utils';
1515
import { CornerFamily, applyMixins } from './index.common';
@@ -29,6 +29,14 @@ function cornerTreat(cornerFamily: CornerFamily): com.google.android.material.sh
2929
}
3030
}
3131

32+
let context: android.content.Context;
33+
function getContext() {
34+
if (!context) {
35+
context = Utils.ad.getApplicationContext();
36+
}
37+
return context;
38+
}
39+
3240
// stub class as we don't use this on android
3341
export class Themer {
3442
primaryColor: string | Color;
@@ -53,7 +61,7 @@ export class Themer {
5361
}
5462
getPrimaryColor(): string | Color {
5563
if (!this.primaryColor) {
56-
this.primaryColor = new Color(getAttrColor(Application.android.startActivity, 'colorPrimary'));
64+
this.primaryColor = new Color(getAttrColor(getContext(), 'colorPrimary'));
5765
}
5866
return this.primaryColor;
5967
}
@@ -63,14 +71,14 @@ export class Themer {
6371
}
6472
getOnPrimaryColor() {
6573
if (!this.onPrimaryColor) {
66-
this.onPrimaryColor = new Color(getAttrColor(Application.android.startActivity, 'colorOnPrimary'));
74+
this.onPrimaryColor = new Color(getAttrColor(getContext(), 'colorOnPrimary'));
6775
}
6876
return this.onPrimaryColor;
6977
}
7078

7179
setAccentColor(value: string | Color) {
7280
if (!this.accentColor) {
73-
this.accentColor = new Color(getAttrColor(Application.android.startActivity, 'colorAccent'));
81+
this.accentColor = new Color(getAttrColor(getContext(), 'colorAccent'));
7482
}
7583
this.accentColor = value;
7684
}
@@ -95,7 +103,7 @@ export class Themer {
95103
}
96104
getPrimaryColorVariant(): string | Color {
97105
if (!this.primaryColorVariant) {
98-
this.primaryColorVariant = new Color(getAttrColor(Application.android.context, 'colorSecondary'));
106+
this.primaryColorVariant = new Color(getAttrColor(getContext(), 'colorSecondary'));
99107
}
100108
return this.primaryColorVariant;
101109
}
@@ -109,7 +117,7 @@ export class Themer {
109117
controlHighlightColor: Color;
110118
getControlHighlightColor(): Color {
111119
if (!this.controlHighlightColor) {
112-
this.controlHighlightColor = new Color(getAttrColor(Application.android.context, 'colorControlHighlight'));
120+
this.controlHighlightColor = new Color(getAttrColor(getContext(), 'colorControlHighlight'));
113121
}
114122
return this.controlHighlightColor;
115123
}

0 commit comments

Comments
 (0)