nativescript/skills

ns-xml-custom-components

Use when authoring NativeScript XML — custom components via xmlns, codeFile/cssFile/import attributes, ios:/android: attribute prefixes vs / element blocks — or when decoding a "Building UI from XML." error like "Module not found for element", including why…

소스 보기
원본 Skill 문서

원본 저장소의 제목, 예시, 코드, 표, 링크, 이미지를 유지해 표시합니다.

XML builder: custom components, platform blocks, and its errors

Custom components

Point an xmlns prefix at a module path (relative to app/), then use exported view classes as tags:

xml
<Page xmlns:ui="components/rating">
  <StackLayout>
    <ui:Rating value="3" />
  </StackLayout>
</Page>
  • The module's exported symbol name is the tag (export class Rating extends GridLayout).
  • A component folder can be XML-first: components/card/Card.xml (+ optional co-located Card.css, code-behind, or a package.json naming the entry) — usable with no JS class at all.
  • Framework modules work through the same mechanism: xmlns:c="ui/label"<c:Label>.
  • Unknown attributes on a custom component become plain expando properties (panel['myProperty'] = 'myValue') — never an error, so attribute typos fail silently. Property names are checked nowhere; test bindings visually.
  • Dashed lowercase tags are first-class: <stack-layout>, <segmented-bar> — and CSS type selectors must use that dashed form.

Page-level attributes

  • codeFile="~/views/shared/list-code" and import="..." are equivalent — both point the page at a different code-behind; a bad path throws at parse time.
  • cssFile="~/styles/custom.css" scopes a stylesheet to the page — and the path is itself run through file-qualifier resolution (custom.land.css can override what you referenced — see ns-file-qualifiers).

Platform-conditional markup: two mechanisms, don't nest them

xml
<TextField ios:editable="false" android:editable="true" />

<ios><TextField hint="Cupertino" /></ios>
<android><Label text="Mountain View" /></android>

Attribute prefixes (ios:/android:) and element blocks (<ios>/<android>) both work — but nesting an `<android>` block inside an `<ios>` block throws. Keep platform blocks siblings.

Reading builder errors

Building UI from XML. @app/views/feed/feed-page.xml:11:5
 > Module 'Unicorn' not found for element 'Unicorn'.

The @file:line:col points at the offending element. Two timing rules:

  • Page-level errors throw when the page loads.
  • Errors inside an itemTemplate are deferred: Builder.load() succeeds and the throw happens only when the template first instantiates (first row render) — a list page that "loads fine then crashes on data arrival" is usually a broken template element, and the reported line/col points inside the template.

Programmatic use: Builder.parse(xmlString, context) and Builder.load({ path, name, exports, page, attributes }).

Verified 2026-08 against @nativescript/core 9.1.0-rc.3: error format, deferred template throws, platform-block nesting throw, expando attributes, dashed tags and codeFile/cssFile behavior are asserted in apps/automated/src/xml-declaration/xml-declaration-tests.ts; not re-run standalone.

같은 저장소의 Skills

더 많은 Skills

모든 Skills
nativescript
커뮤니티

ns-css-selectors

Use when a NativeScript CSS rule silently doesn't apply and you're asking "does NativeScript support this selector?" — the supported selector set (:not/:is/:where/:pressed/:hovered/@media/attribute operators), :where()'s zero specificity, bare [attr] selectors matching nothing, per-declaration (not per-block) error recovery, and the className-swap stale-background workaround.

설치 수
1
GitHub Stars
1
업데이트
8월 27일
nativescript
커뮤니티

ns-css-variables-calc

Use when using var(--x, fallback) or calc() in NativeScript CSS, when view.width reads back as a unit object instead of a number, or when a calc() mixing px and % never evaluates — the var() fallback truth table, the unit-dependent return shapes of calc(), and percent values being fractions (50% parses to value 0.5).

설치 수
1
GitHub Stars
1
업데이트
8월 27일
nativescript
커뮤니티

ns-ios-corespotlight

Use when adding CoreSpotlight/system-search indexing to a NativeScript iOS app, when an app freezes or becomes unresponsive shortly after launch/data load, or when a hang report shows the main thread stuck in v8::Locker::Initialize — indexSearchableItems enumerates JS-array adapters on dispatchapply worker threads and deadlocks the V8 isolate unless you materialize real NSArrays and hop completion handlers back to the main thread.

설치 수
1
GitHub Stars
1
업데이트
8월 27일