WhoBuilt

Native Navigation in JavaScript World

Jul 4, 2024· 23 min· 616 views·Watch on YouTube

Speaker

Tymoteusz Boba of Software Mansion explains how React Native Screens powers native navigation in JavaScript, at a React Universe Meetup hosted by Callstack.

What React Native Screens adds

Boba contrasts hand-built navigation, which requires managing views and state, with React Navigation’s ready-made navigators, including stacks, tabs, and drawers. React Navigation uses React Native Screens to connect its API to native screen components.

Native screens and JavaScript stacks

With the native stack, iOS and Android controllers handle screen changes, animations, and orientation. A JavaScript stack still uses React Native Screens: inactive screens are detached to save memory while their React component state remains preserved. Screens also provides primitives such as Screen, ScreenContainer, and ScreenStack.

How routes become native views

Boba traces the flow from navigator routes through Native Stack View and Route View, which apply screen options, context, and header configuration. Codegen components then pass Screen, ScreenStack, and Header Config calls to native code.

Expo Router and React Navigation

Expo Router maps files in an app directory to routes, supports dynamic paths, and uses React Navigation underneath, so it also uses React Native Screens. Boba sees Expo Router’s automatic deep linking and type safety as useful for new projects, while React Navigation remains straightforward and well supported for existing apps. He says a full rewrite is not necessary.

Planned features and React Freeze

Boba describes React Navigation v7’s planned static configuration API for simpler TypeScript checking and deep linking. React Native Screens work included Android Material 3 support, collapsible headers, form sheets, and a split-screen proof of concept. In the Q&A, he explains that React Freeze can prevent hidden screens from triggering native renders and can be enabled with the Screens `enableFreeze` option.

Takeaways

  • Use React Native Screens to detach inactive screens and reduce memory use while preserving React state.
  • Choose a native stack when OS controllers should manage screen transitions; a JavaScript stack gives more control over navigation behavior.
  • Expo Router adds file-based routes on top of React Navigation, so existing apps do not need a full rewrite to try it.
  • Consider enabling React Freeze to avoid native renders from screens that are not visible.

Mentioned in this talk

Search inside this talk

What was claimed 16

Show all 16 facts

Related talks

Native Navigation in JavaScript World, Tymoteusz Boba · WhoBuilt