- React Native Cookbook
- Dan Ward
- 177字
- 2025-04-04 14:57:29
How it works...
In the Device utility, we imported a dependency that React Native provides called Dimension for getting the dimensions of the current device. We also defined a tablet constant in the Device utility, which is an object containing the width and height that is used with Dimension to calculate whether the device is a tablet or not. The values of this constant are based on the smallest Android tablet available on the market.
In step 5, we got the width and height by calling the Dimensions.get("window") method, and then we got the maximum and minimum values depending on the orientation we wanted.
In step 12, it's important to note that we used an arrow function to define the renderContact method. Using an arrow function keeps the correct binding scope, otherwise, the this in the call to this.capitalize would be bound to the wrong scope. Check the See also section for more information on how both the this keyword and arrow functions work.