Repository navigation
Conversation
2574c3a to
04606d3
Compare
Visual regressionNo visual differences at ios: no capture |
chrfalch
left a comment
There was a problem hiding this comment.
I checked every prop in the three new delegates against the reflective setters, including the names, prop group indices, defaults, color conversion and Dynamic wrapping. They match, and the new test compares both paths prop by prop. One question about the feature flag: the earlier test asserted that core managers keep their native prop metadata when skipNativePropsForViewManagerWithDelegateAndroid is on, and this change reverses that. With the flag on, RCTView, RCTText and RCTImageView report empty NativeProps. Anything that still reads their native view config then sees no props: a NativeComponentRegistry setup with native: true or verify: true, or JS code that reads UIManager.getViewManagerConfig('RCTView').NativeProps. RCTSelectableText also keeps reporting its props while RCTText does not. Can you confirm that every app that enables the flag uses static view configs for these three components with verification off?
`ReactViewManager`, `ReactTextViewManager` and `ReactImageManager` have no codegen delegate, so `GenericViewManagerDelegate` sets their props: it finds each prop's annotated setter in `ViewManagersPropertyCache` and calls it with `Method.invoke`, boxing primitive values. Each of these managers now returns a delegate that calls its setters directly, with the defaults and conversions of the reflective setters, and passes the props of `BaseViewManager` to `BaseViewManagerDelegate`. `SelectableTextViewManager`, which is final and declares no props, gets the direct delegate of `ReactTextViewManager`. Other subclasses of `ReactViewManager` and `ReactTextViewManager` keep the reflective delegate, because it also finds the props they declare. `BaseViewManagerDelegate` now sets `onStartShouldSetResponder`, whose setter marks a view as interactable when `enableInteractableResponderViews` is on. It ignored the prop, so the direct delegates would have dropped that behavior; components with codegen delegates now get it too. The direct delegates keep two behaviors of the reflective one. When a setter fails, for example because a value has the wrong type or is null where the setter needs a value, they throw the `JSApplicationIllegalArgumentException` that names the prop and the view manager, with the message `ViewManagersPropertyCache` builds. And native view configs do not change: when `skipNativePropsForViewManagerWithDelegateAndroid` is on, `getNativeProps` now returns an empty map only for managers whose delegate is not an `AnnotatedPropsDelegate`. The reflective delegate and the three direct delegates carry this internal marker, because each sets exactly the props its manager declares with `@ReactProp` and `@ReactPropGroup`, so RCTView, RCTText, RCTSelectableText and RCTImageView keep reporting their native props. `ViewManagerDelegatesTest` sets every prop that the reflective setters of View, Text, SelectableText and Image know, first to null and then to a value, through the reflective and the direct delegate on separate mock managers, and checks that both make the same calls with the same arguments. It fails when a prop is missing from a delegate, when an index or a default value differs, or when `BaseViewManagerDelegate` ignores `onStartShouldSetResponder`. It checks that both delegates throw the same `JSApplicationIllegalArgumentException` for a value of the wrong type, for a null `backfaceVisibility` and for a wrong `opacity`, which `BaseViewManagerDelegate` sets. It also checks which managers get the direct delegate, and that a subclass of `ReactViewManager` still receives the props it declares. `UIManagerModuleConstantsHelperTest` checks that the four core managers report their native props with `skipNativePropsForViewManagerWithDelegateAndroid` on. Each new assertion fails when the behavior it checks is removed. The ReactAndroid unit tests pass with `-PenableWarningsAsErrors=true`, `yarn android-api-validate` passes, and RNTester's Release build mounts its home, Text and Image screens on an arm64 Android 16 emulator. On that emulator, a benchmark in RNTester's Release build applied each set of props through each delegate in one process, rotating which ran first, in five launches of three rounds of 21 samples. The table gives the median of the round medians with the interquartile range: | Props | Reflective | Direct | | --- | --- | --- | | View: 10 style and accessibility props, 4 layout props | 1,362 ns (1,237–1,482), 803 B | 1,024 ns (909–1,054), 524 B | | Text: 8 props | 438 ns (432–443), 197 B | 243 ns (240–245), 49 B | | Image: 8 props, without a source | 442 ns (432–452), 328 B | 237 ns (232–238), 180 B | The bytes are Java heap allocated per set of props. The try/catch in the direct delegates costs nothing measurable: over 30 alternating rounds per component against the same delegates without it, the median difference was −2 ns for View, 0 ns for Text and +2 ns for Image, and neither variant was faster in a clear majority of rounds. Signed-off-by: James Ide <ide@expo.dev>
04606d3 to
bea8497
Compare
|
Thanks for checking every prop. You're right that the flag would have changed what these three components report, and I can't confirm that every app that enables it uses static view configs with verification off. So the PR no longer changes native view configs: with |
Summary:
ReactViewManager,ReactTextViewManagerandReactImageManagerhave no codegen delegate, soGenericViewManagerDelegatesets their props: it finds each prop's annotated setter inViewManagersPropertyCacheand calls it withMethod.invoke, boxing primitive values. Each of these managers now returns a delegate that calls its setters directly, with the defaults and conversions of the reflective setters, and passes the props ofBaseViewManagertoBaseViewManagerDelegate.SelectableTextViewManager, which is final and declares no props, gets the direct delegate ofReactTextViewManager. Other subclasses ofReactViewManagerandReactTextViewManagerkeep the reflective delegate, because it also finds the props they declare.BaseViewManagerDelegatenow setsonStartShouldSetResponder, whose setter marks a view as interactable whenenableInteractableResponderViewsis on. It ignored the prop, so the direct delegates would have dropped that behavior; components with codegen delegates now get it too.The direct delegates keep two behaviors of the reflective one. When a setter fails, for example because a value has the wrong type or is null where the setter needs a value, they throw the
JSApplicationIllegalArgumentExceptionthat names the prop and the view manager, with the messageViewManagersPropertyCachebuilds. And native view configs do not change: whenskipNativePropsForViewManagerWithDelegateAndroidis on,getNativePropsnow returns an empty map only for managers whose delegate is not anAnnotatedPropsDelegate. The reflective delegate and the three direct delegates carry this internal marker, because each sets exactly the props its manager declares with@ReactPropand@ReactPropGroup, so RCTView, RCTText, RCTSelectableText and RCTImageView keep reporting their native props.Changelog:
[ANDROID] [CHANGED] - Set the props of View, Text and Image with direct calls instead of reflection.
Test Plan:
ViewManagerDelegatesTestsets every prop that the reflective setters of View, Text, SelectableText and Image know, first to null and then to a value, through the reflective and the direct delegate on separate mock managers, and checks that both make the same calls with the same arguments. It fails when a prop is missing from a delegate, when an index or a default value differs, or whenBaseViewManagerDelegateignoresonStartShouldSetResponder. It checks that both delegates throw the sameJSApplicationIllegalArgumentExceptionfor a value of the wrong type, for a nullbackfaceVisibilityand for a wrongopacity, whichBaseViewManagerDelegatesets. It also checks which managers get the direct delegate, and that a subclass ofReactViewManagerstill receives the props it declares.UIManagerModuleConstantsHelperTestchecks that the four core managers report their native props withskipNativePropsForViewManagerWithDelegateAndroidon. Each new assertion fails when the behavior it checks is removed. The ReactAndroid unit tests pass with-PenableWarningsAsErrors=true,yarn android-api-validatepasses, and RNTester's Release build mounts its home, Text and Image screens on an arm64 Android 16 emulator.On that emulator, a benchmark in RNTester's Release build applied each set of props through each delegate in one process, rotating which ran first, in five launches of three rounds of 21 samples. The table gives the median of the round medians with the interquartile range:
The bytes are Java heap allocated per set of props. The try/catch in the direct delegates costs nothing measurable: over 30 alternating rounds per component against the same delegates without it, the median difference was −2 ns for View, 0 ns for Text and +2 ns for Image, and neither variant was faster in a clear majority of rounds.