Skip to content

refactor(android): remove no-op global.__native(this) constructor returns - #11652

Merged
edusperoni merged 1 commit into
mainfrom
refactor/android-drop-global-native
Nov 22, 2026
Merged

edusperoni merged 1 commit into
mainfrom
refactor/android-drop-global-native

Conversation

@edusperoni

Copy link
Copy Markdown
Contributor

PR Checklist

What is the current behavior?

34 native class constructors in packages/core end with return global.__native(this);.

__native (the runtime's ts_helpers.js) only does something for the placeholder object of the pre-TypeScript 2.0 emit, _super.call(this); return __native(this);. With the current emit, var _this = _super.call(this) || this already holds the native instance. That instance never has __container__, so __native returns it unchanged.

What is the new behavior?

Removes 33 of those constructor returns. The global.__native function itself is not touched, so third-party code that still calls it keeps working. NativeScript/docs#206 removes it from the docs.

The 34th is in ui/transition/page-transition.android.ts, inside SnapshotViewGroup, which #11651 deletes as unused.

Static binding generator note: when a constructor body becomes only super(...), the ES5 emit becomes return _super.call(this, ...) || this;. In core's build that is 6 classes:

  • TNSAccessibilityDelegateImpl
  • SeekBarChangeListenerImpl
  • LruBitmapCache
  • DialogFragmentImpl
  • TabHostImpl
  • fragment-transitions AnimationListenerImpl

The Android SBG finds the class location in that shape since NativeScript/android#2101, which is merged and on the runtime's next tag. On 9.0–9.1.1 runtimes these classes are generated at runtime anyway (a naming bug #2101 also fixed), so nothing changes there. On runtimes older than 9.0, these 6 classes switch from prebuilt to runtime-generated.

Split out of #11636.

…urns

__native only unwraps the placeholder object of the pre-TypeScript 2.0 constructor emit (super(); return __native(this)). With the current emit the constructor already holds the native instance from var _this = _super.call(this) || this, so __native returns it unchanged.
@nx-cloud

nx-cloud Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit 25395c6

Command Status Duration Result
nx test apps-automated -c=android ✅ Succeeded 2m 34s View ↗
nx run-many --target=test --configuration=ci --... ✅ Succeeded <1s View ↗

💡 With Ultracache enabled, Nx Cloud learns each task's file inputs in CI and uses them on later runs. Turn on Ultracache in workspace settings ↗ · Read docs ↗


☁️ Nx Cloud last updated this comment at 2026-11-20 18:16:10 UTC

@pkg-pr-new

pkg-pr-new Bot commented Nov 20, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@nativescript/core@11652
npm i https://pkg.pr.new/@nativescript/vite@11652
npm i https://pkg.pr.new/@nativescript/webpack@11652

commit: 25395c6

@NathanWalker NathanWalker left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean removal across all 33 @NativeClass constructors (with the 34th in SnapshotViewGroup removed in #11651), while keeping global.__native intact and leaving layout-helper.android.ts and the bundler specs covering the legacy return pattern. Note that a few of these constructors (Button, ActionBar, SegmentedBar, TextBase, fragment.transitions) overlap with #11656–#11658 and #11662, so whichever lands second will just need a quick rebase on those lines.

@NathanWalker NathanWalker added this to the 9.2 milestone Nov 21, 2026
@edusperoni
edusperoni merged commit 564b25a into main Nov 22, 2026
10 of 11 checks passed
@edusperoni
edusperoni deleted the refactor/android-drop-global-native branch November 22, 2026 18:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants