Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

react-native

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

This disables the 'layout-only view removal' optimization for this view!

After searching for a while I was not able to find information that describes what this optimisation is. Is it significant? If it viable to only set these tests id's in dev mode / dev target? i.e. they will be undefined otherwise?

like image 800
Ilja Avatar asked Nov 27 '18 18:11

Ilja


People also ask

What is onLayout in React Native?

react-native-on-layout is an npm package that you can include in your app using npm i react-native-on-layout or with yarn add react-native-on-layout . It is a View component that will do this onLayout dance for you and then passes the layout values as parameters to a render prop.

What is testID in React Native?

Hello friends, In today's tutorial we would learn about testID prop of Image component in react native. Most of us heard about this prop for the first time. So in easy language the testID prop is used as a unique identifier ID for UI Automation Testing Script.

What is the use of view in React Native?

The most fundamental component for building a UI, View is a container that supports layout with flexbox, style, some touch handling, and accessibility controls. View maps directly to the native view equivalent on whatever platform React Native is running on, whether that is a UIView , <div> , android.


1 Answers

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.

like image 165
Artal Avatar answered Oct 18 '22 15:10

Artal