What is 'layout-only view removal' optimization in react-native?

后端 未结 1 1003
我寻月下人不归
我寻月下人不归 2021-01-04 08:48

React native exposes certain props on View like testID that are super useful for native testing, but have following note attached to them

相关标签:
1条回答
  • 2021-01-04 09:29

    When RN creates the native views from the shadow nodes tree - it performs some optimizations. Views that do not actually show on screen (don't draw anything or just used in JSX to contain and layout their children) can be removed when constructing the native hierarchy. This is why they're called "layout-only" views.

    As this warning suggests, a view with the testID prop will not be removed even if it's a "layout-only" view so it will actually be there when you're performing e2e tests.

    Generally speaking, rendering a lot of views can cause performance issues, but using testID on some views won't make a noticeable difference in performance because:

    1. You probably don't have a lot of views with a testID
    2. Most of the views with a testID are probably not "layout-only" views so it makes no difference if you use this prop or not regarding the optimizations.

    In case you do have "layout-only" views with a testID, it would be easier to move the testID to a more suitable view.

    0 讨论(0)
提交回复
热议问题