Skip to content

Commit ae8561a

Browse files
committed
chore(widgets): update readme
1 parent 2a839f7 commit ae8561a

1 file changed

Lines changed: 22 additions & 22 deletions

File tree

packages/widgets/README.md

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ registerWidgetListener(PROVIDER, {
130130
const root = new LinearLayout();
131131

132132
const title = new TextView();
133-
title.native.setText('Hello from NativeScript');
134-
title.native.setTextColor(new Color('#ffffff').android);
133+
title.setText('Hello from NativeScript');
134+
title.setTextColor(new Color('#ffffff').android);
135135
root.addView(title);
136136

137137
const rv = root.toAndroidRemoteViews(); // -> AndroidRemoteViews
@@ -182,11 +182,11 @@ The JS classes are **thin wrappers** over `org.nativescript.widgets.RemoteViews.
182182

183183
```ts
184184
const tv = new TextView();
185-
tv.native.setText('Total: 42'); // fluent native API
186-
tv.native.setTextColor(0xffffffff); // ARGB int
185+
tv.setText('Total: 42'); // fluent wrapper API
186+
tv.setTextColor(0xffffffff); // ARGB int
187187
```
188188

189-
> **TypeScript note:** the wrapper's `.native` getter is typed as the base `org.nativescript.widgets.RemoteViews`, which does not surface the leaf setters (`setText`, `setImageUrl`, …). At runtime the instance is the correct subclass, so the calls work — add a cast (`(tv.native as any).setText(...)`) if the compiler complains, or reach for the fully‑typed `org.nativescript.widgets.RemoteViews.*` classes directly.
189+
Most common operations are exposed directly on the JS wrapper (`setText`, `setImageUrl`, `setVisibility`, `setSize`, and more). The `.native` handle is still available for platform-level interop when needed.
190190

191191
Every node takes an optional stable `id` string in its constructor (`new TextView('total')`). Omit it and one is generated.
192192

@@ -216,8 +216,8 @@ All of them extend the base `RemoteViews` wrapper, which exposes `.native` and `
216216

217217
```ts
218218
const label = new TextView('label');
219-
label.native.setText('Weather');
220-
label.native.setTextColor(new Color('#222222').android);
219+
label.setText('Weather');
220+
label.setTextColor(new Color('#222222').android);
221221
```
222222

223223
### Images
@@ -226,9 +226,9 @@ label.native.setTextColor(new Color('#222222').android);
226226
import { ImageSource } from '@nativescript/core';
227227

228228
const icon = new ImageView('icon');
229-
icon.native.setImageResource(android.R.drawable.ic_dialog_info); // drawable resource id
229+
icon.setImageResource(android.R.drawable.ic_dialog_info); // drawable resource id
230230
// or a bitmap you already have:
231-
// icon.native.setImageBitmap(ImageSource.fromFileSync(path).android);
231+
// icon.setImageBitmap(ImageSource.fromFileSync(path).android);
232232
```
233233

234234
### Remote images (from a URL)
@@ -242,10 +242,10 @@ registerWidgetListener(PROVIDER, {
242242
onUpdateAsync({ appWidgetIds, widgetManager }) {
243243
const root = new LinearLayout();
244244
const img = new ImageView();
245-
img.native.setImageUrl('https://example.com/chart.png');
245+
img.setImageUrl('https://example.com/chart.png');
246246
root.addView(img);
247247

248-
root.native.resolveRemoteResources(); // fetch remote images (blocking, safe on worker thread)
248+
root.resolveRemoteResources(); // fetch remote images (blocking, safe on worker thread)
249249

250250
const rv = root.toAndroidRemoteViews();
251251
appWidgetIds.forEach((id) => widgetManager.native.updateAppWidget(id, rv.native));
@@ -263,10 +263,10 @@ Container nodes build a tree with `addView` / `removeView`. Children are linked
263263
const root = new LinearLayout('root');
264264

265265
const title = new TextView('title');
266-
title.native.setText('Today');
266+
title.setText('Today');
267267

268268
const value = new TextView('value');
269-
value.native.setText('72°');
269+
value.setText('72°');
270270

271271
root.addView(title);
272272
root.addView(value);
@@ -291,32 +291,32 @@ const flags =
291291
const pi = android.app.PendingIntent.getActivity(ctx, 0, launch, flags);
292292

293293
const button = new Button('open');
294-
button.native.setText('Open app');
295-
button.native.setOnClickPendingIntent(pi);
294+
button.setText('Open app');
295+
button.setOnClickPendingIntent(pi);
296296
```
297297

298298
### Sizing & visibility
299299

300300
```ts
301301
// Visibility uses android.view.View constants: VISIBLE(0) / INVISIBLE(4) / GONE(8)
302-
node.native.setVisibility(android.view.View.GONE);
302+
node.setVisibility(android.view.View.GONE);
303303

304304
// setBackgroundColor takes an ARGB int
305-
node.native.setBackgroundColor(new Color('#1e88e5').android);
305+
node.setBackgroundColor(new Color('#1e88e5').android);
306306

307307
// Explicit layout sizing (Android 12 / API 31+ only — no-op on older devices)
308308
const DIP = android.util.TypedValue.COMPLEX_UNIT_DIP;
309-
node.native.setSize(120, DIP, 60, DIP);
309+
node.setSize(120, DIP, 60, DIP);
310310
// or individually:
311-
node.native.setWidth(120, DIP);
312-
node.native.setHeight(60, DIP);
311+
node.setWidth(120, DIP);
312+
node.setHeight(60, DIP);
313313
```
314314

315315
Lower‑level passthroughs (`setInt`, `setBoolean`, `setString`, `setFloat`, `setLong`, `setShort`, `setByte`) map straight onto the corresponding `RemoteViews.set*` methods, letting you call any remotable setter by method name:
316316

317317
```ts
318-
node.native.setBoolean('setEnabled', true);
319-
node.native.setInt('setMaxLines', 2);
318+
node.setBoolean('setEnabled', true);
319+
node.setInt('setMaxLines', 2);
320320
```
321321

322322
---

0 commit comments

Comments
 (0)