Skip to content

Commit 10ecedf

Browse files
author
farfromrefuge
committed
fix(android): create native view using inflate (a bit faster)
1 parent 38cf33b commit 10ecedf

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

Diff for: plugin/platforms/android/native-api-usage.json

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"android.text:Layout",
1010
"android.os:Build",
1111
"android.util:TypedValue",
12+
"android.view:LayoutInflater",
1213
"android.graphics:Paint",
1314
"android.graphics:Paint.FontMetrics",
1415
"android.text:Spanned",

Diff for: src/label.android.ts

+13-3
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,8 @@ abstract class LabelBase extends View implements LabelViewDefinition {
215215
protected _paintFlags: number;
216216
}
217217

218+
let layoutId;
219+
let LayoutInflater: typeof android.view.LayoutInflater;
218220
export class Label extends LabelBase {
219221
nativeViewProtected: com.nativescript.text.TextView;
220222
handleFontSize = true;
@@ -228,10 +230,18 @@ export class Label extends LabelBase {
228230

229231
@profile
230232
public createNativeView() {
231-
if (!TextView) {
232-
TextView = com.nativescript.text.TextView;
233+
// if (!TextView) {
234+
// TextView = com.nativescript.text.TextView;
235+
// }
236+
// return new TextView(this._context);
237+
if (!layoutId) {
238+
const context = Utils.android.getApplicationContext();
239+
layoutId = context.getResources().getIdentifier('label', 'layout', context.getPackageName());
233240
}
234-
return new TextView(this._context);
241+
if (!LayoutInflater) {
242+
LayoutInflater = android.view.LayoutInflater;
243+
}
244+
return LayoutInflater.from(this._context).inflate(layoutId, null, false);
235245
}
236246
urlSpanClickListener: com.nativescript.text.URLSpanClickListener;
237247
public disposeNativeView() {

0 commit comments

Comments
 (0)