Skip to content

UIKit host views attach after first React paint #36

@DjDeveloperr

Description

@DjDeveloperr

Summary

When using @nativescript/react-native UIKit host helpers (defineUIKitView, defineUIKitContainer, and defineUIViewController), the React Native host view can appear on the first paint before the NativeScript-created UIKit subtree/controller is attached. The UIKit content then appears on a later paint.

This makes app startup look two-staged: the React Native shell is visible first, then native nav/tab/accessory/card views pop in. In our app we ended up hiding the root with a double requestAnimationFrame until the native views appear, which feels like the wrong layer for the fix.

Observed behavior

In a React Native/Expo app using @nativescript/react-native@9.0.0-preview.4:

  • UIKit components are defined at module load with defineUIKitView / defineUIKitContainer / defineUIViewController.
  • On initial render, the RN host commits without the native UIKit view/controller handle.
  • The actual UIKit subtree appears on the next render/paint.
  • A native tab/navigation shell therefore needs a timing workaround to avoid visible first-paint flicker.

Expected behavior

If the component is already defined before app render, UIKit-backed host views/controllers should be attachable in the initial host commit, or the package should expose a deterministic precreate/ready mechanism so apps do not need timing hacks.

Likely cause

From reading the package source, defineUIKitHost creates the native UIKit object from a React useEffect. That means the initial render starts with nativeViewHandle, childrenViewHandle, and controllerHandle undefined. After runOnUI() resolves, the package calls setNativeViewHandle, setChildrenViewHandle, and/or setControllerHandle, causing a second React commit where the shared native host finally receives the handles.

So defining the component earlier does not help, because the native object creation/handle publication still happens after the first commit.

Why this matters

Native shell UI such as UITabBarController, UINavigationController, tab bar accessories, and native cards should feel present on the first frame. The current behavior forces app code to either accept a visible two-stage paint or hide the whole shell with timing-based workarounds.

Possible directions

  • Create/publish UIKit handles before the initial React Native host commit when possible.
  • Provide an explicit precreate API for startup-critical native hosts.
  • Provide a deterministic onReady/mounted signal from the package, so apps can hide only until the actual native handle is attached rather than guessing with animation frames.

Happy to provide a small repro if useful.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions