Skip to content

feat: RN TurboModule -- threading + Fabric integration, rebuilt (supersedes #46) - #72

Open
DjDeveloperr wants to merge 19 commits into
refactorfrom
rn-turbomodule
Open

feat: RN TurboModule -- threading + Fabric integration, rebuilt (supersedes #46)#72
DjDeveloperr wants to merge 19 commits into
refactorfrom
rn-turbomodule

Conversation

@DjDeveloperr

Copy link
Copy Markdown
Collaborator

What this is

Threading + Fabric integration for the RN TurboModule, rebuilt from scratch after the owner rejected #46's architecture (see DECISIONS.md/ARCHITECTURE.md). installWorkletRuntime puts the real NativeScript interop bridge on the worklets UI runtime, so a "worklet" hook calls UIKit directly with zero JSON/RPC round-trip. The UI runtime is main-queue-scheduled but not thread-affine — runOnUISync is banned, only async crossings allowed — so the UI/JS-thread deadlock is unconstructible rather than merely gated.

API shape

One call whose hook names ARE the Fabric ObjC lifecycle names; bodies are worklets:

export const Screen = defineNativeComponent<ScreenProps, ScreenEvents, ScreenInstance>({
  name: "NSScreen",
  props: { activityState: 2, stackPresentation: "push", title: "" },
  events: ["onAppear", "onDisappear", "onDismissed"],
  create(ctx) {
    "worklet";
    const vc = (globalThis as any).UIViewController.alloc().init();
    vc.view = ctx.view;
    ctx.instance.controller = vc;
  },
  updateProps(ctx, next) {
    "worklet";
    if (next.title) ctx.instance.controller.navigationItem.title = next.title;
  },
});

Proof + line counts

packages/react-native-screens/src/index.ts is a full UINavigationController native stack (push/pop/modal, header config, transitionCoordinator-gated reconciliation) in 458 lines, zero native code — vs. a 16,029-line NativeScriptScreenStack.tsx for the same surface in the rejected #46.

  • Module (TS surface + native Fabric glue): 2,329 + 2,058 = 4,387 lines.
  • Net diff vs refactor across both packages: 44 files, +3,366/-4,553.
  • Whole-branch diff vs refactor: 55 files, +4,698/-4,561.
  • feat: add React Native UIKit runtime primitives #46 for comparison: +16,263 insertions over 46 files.

What was deleted

The process-wide UIView/RCTViewComponentView method swizzle (NativeScriptUIView.mm), NativeScriptUIViewManager.mm, NativeScriptUIViewComponentView.{mm,h}, NativeScriptUIKitHost.h, installIdleAwareWorkletsFrameLoop, BatchOps.mm and its walkers, nativeCommitObservations/nativeHandleAuthority, the point-fix RPCs, and the old defineUIKitView/defineUIKitContainer/defineUIViewController surface with its registries. Grepped clean — nothing references any of it.

Known caveat

UIViewControllerTransitionCoordinator's completion block is declared solely on a protocol; the metadata resolver only walks the concrete class hierarchy, so that one call site needs interop.Block(fn, "v@?@") instead of a bare closure (see reconcileStack in the screens consumer). Class-declared completions (presentViewController:animated:completion:) already work with a bare closure. #71 fixes this at the runtime level; until it lands, protocol-declared completion params need interop.Block.

Supersedes #46.

@coderabbitai

coderabbitai Bot commented Aug 20, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 00bedaed-2bac-4951-a0c2-02e15df51256

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

DjDeveloperr added a commit that referenced this pull request Aug 20, 2026
Matches @nativescript/react-native's existing peerDependenciesMeta
convention. Without it, npm's auto-peer-install for
@nativescript/react-native-screens pulled in react-native-worklets@0.11.4
(peer react-native 0.83-0.86), conflicting with the workspace's real
react-native@0.79.5 (pinned transitively via react-native-node-api) and
breaking `npm install` at the repo root -- this is what CI's build job
runs, and it failed on PR #72 for exactly this reason.
DjDeveloperr added a commit that referenced this pull request Aug 20, 2026
Matches @nativescript/react-native's existing peerDependenciesMeta
convention. Without it, npm's auto-peer-install for
@nativescript/react-native-screens pulled in react-native-worklets@0.11.4
(peer react-native 0.83-0.86), conflicting with the workspace's real
react-native@0.79.5 (pinned transitively via react-native-node-api) and
breaking `npm install` at the repo root -- this is what CI's build job
runs, and it failed on PR #72 for exactly this reason.
Build the metadata generator for the host architecture when requested. Copy the shared bridge sources required by the npm package. This fixes the Xcode 26 arm64 libclang link failure and missing-source build errors.
Add main-thread Worklets entry and dynamic Fabric component registration. The simulator test covers native calls and reentrant callbacks on the UI runtime. It also mounts two names backed by the same component implementation.
Add the Fabric component types, lifecycle hook dispatch, serialized definition store, and TypeScript authoring API. Components can define props, events, commands, child mounting, layout handling, and cleanup without project-specific native code.
Use Worklets' flat runOnUI call, serialize definitions before native registration, and create component state before any Fabric hook. Buffer early events until Fabric installs the event emitter.
The component acceptance test now covers the behavior that the spike exercised. Remove the script for the deleted spike-only API.
Describe the bridge accessor without naming a Hermes-only file so the FFI boundary check accepts the shared source.
Exercise command dispatch, mounting transactions, layout decline, content size, delegate creation, deferred work, and cleanup in the simulator app. Add reload markers so the same test can run after Worklets recreates its UI runtime.
Resolve the TypeScript dispatcher from the current JSI runtime on each call. A process-lifetime cached function could outlive its Hermes runtime and crash during destruction. The simulator test now runs through a development reload.
Forward full mounting mutations, make child hooks replace Fabric's defaults, route teardown through both recycle paths, and apply native content size during shadow-node adoption.
Make retainer helpers worklets, validate event names, expose command dispatch, reject non-worklet hooks, and clean up retained component state after teardown.
Extend the simulator app to cover the corrected mount, state, command, delegate, event, and teardown behavior.
Implement Screen and ScreenStack with defineNativeComponent. The package owns UINavigationController containment, modal presentation, prop updates, and gesture-driven pop reconciliation.
Fix worklet retainers, direct-event registration, and view-controller containment. Handle transition completion safely while the runtime lacks protocol method metadata.
Leave style out of the component's validAttributes map so React Native's style descriptor survives the view-config merge. Yoga now receives flex, size, and spacing updates.
Fabric sends only changed keys to a component. Type next and prev as Partial<Props> so hook implementations merge updates instead of replacing stored state.
Walk nested worklet closures and report undefined captures before a component mounts. The error tells authors to put mutually dependent helpers on a stable object because Worklets does not hoist transformed declarations.
Remove the content-size workaround now that Yoga receives style props. Use UIViewController completion callbacks directly and wrap the protocol-only transition callback with an explicit block signature.
Prevent npm from installing an incompatible Worklets version when the workspace already supplies React Native through react-native-node-api.
Replace the removed UIKit helper API with the current component API. Tighten the README, source comments, test output, and errors so they state the runtime contracts without internal planning notes.
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.

1 participant