Repository navigation
perf(android): create view managers on demand - #813
imranbarbhuiya wants to merge 1 commit into
Conversation
|
@imranbarbhuiya is attempting to deploy a commit to the appandflow Team on Vercel. A member of the Team first needs to authorize it. |
floco-af
left a comment
There was a problem hiding this comment.
Automated review (Floco, App & Flow's coding agent). Static review only; I did not build or run this on a device.
Correctness
getViewManagerNamesreturnsRNCSafeAreaProviderandRNCSafeAreaView. These are theREACT_CLASSconstants that both managers return fromgetName(), so the names RN looks up match.createViewManagerreturns a new manager for each name andnullfor anything else. That matches the@Nullablecontract ofViewManagerOnDemandReactPackage.createViewManagersis unchanged, so setups that call it directly (eager packages, old architecture) still work.- The interface signatures match RN 0.76 (Java) and 0.85 (Kotlin), so the change should compile across the supported range. The peer dependency is
*.
Platforms and breaking changes
- Android only. No JS, iOS or API change.
- On RN versions without react/react-native#58097 the PR says it is a no-op, which fits the code.
Tests and validation
- Nothing exercises this class (the JS test suite doesn't cover the Android package), so there is no regression test to add.
- The perf numbers come from react/react-native#59173, not from this library, and I did not reproduce them.
- The PR describes a manual run of the example app on a Pixel 9 emulator, and I couldn't confirm that.
- The CI status shown is only the Vercel authorization check. No build ran.
Verdict: looks good. The change is small and contained. The only thing I'd want before merging is a Kotlin compile and a smoke run of the example app on Android, which maintainers can do quickly.
|
Both ran: I built the example with this change ( |
floco-af
left a comment
There was a problem hiding this comment.
Follow-up from Floco (App & Flow's coding agent), after the author's note that the example was built and run on a Pixel 9 emulator.
What I ran on c4dd7ed: yarn validate:eslint, yarn validate:typescript and yarn validate:jest all pass (5 suites, 32 passed, 2 skipped). The change only touches SafeAreaContextPackage.kt, so none of these exercise it.
What I could not do: build the Android example or run it on a device. The remote Mac mini I use for Android builds refused the build in this run, and this host has no Android emulator. So I can't independently confirm the Kotlin compile or the emulator run the author describes. The only CI check on the PR is the Vercel authorization one, so no build has run there either.
Verdict unchanged: looks good. The change is small and contained. A maintainer should still do one Android build and smoke run of the example before merging.
Summary
On Android with the New Architecture (bridgeless), React Native builds the view config (props and events) of every view manager in an eager
ReactPackagewhen JS first readsUIManager. That happens on the JS thread during startup, before the first screen renders.SafeAreaContextPackagenow implementsViewManagerOnDemandReactPackage. React Native then listsRNCSafeAreaProviderandRNCSafeAreaViewand builds each config only when JS first uses that view.MainReactPackage,react-native-gesture-handlerandreact-native-svgalready work this way.getViewManagerNamesreturns both names (REACT_CLASS).createViewManagercreates only the requested manager.createViewManagersis unchanged, for setups that call it.The gain needs React Native 0.89+, which includes react/react-native#58097. On older versions,
UIManager.jsbuilds every lazy config anyway, and the change is harmless. Two view managers are a small share on their own. Across all packages in a production app, building view configs on demand cut JS start → first mount from 110 ms to 66 ms (react/react-native#59173). The same change is open forreact-native-screens(software-mansion/react-native-screens#5221) andreact-native-keyboard-controller(kirillzyusko/react-native-keyboard-controller#1767).Test Plan
Example app, debug build on a Pixel 9 emulator (Android 16), New Architecture (React Native 0.85):
SafeAreaView Example,SafeAreaView Edges ExampleandHooks Example(from the dev menu) render with the expected insets: top 54, bottom 24, provider frame 411×923.ViewManagerPropertyUpdater: Could not find generated setterwarnings forSafeAreaProviderManageralso appear without this change.