In this section, we will focus on building the pinpointing to the center of the map to visually confirm the pickup location. This pin also contains a button, which can be used to trigger a pickup request:
This component is again very light in terms of functionality, but has a lot of custom style. Let's dive into some of the style details.
flexDirection
By default, React Native and Flexbox stack elements vertically:
For the banner in our pin, we want to stack every element horizontally after each other as follows:
This can be achieved by adding the following styles to the containing element flexDirection: 'row'. The other valid options for flexDirection are:
row-reverse
column (default)
column-reverse
Dimensions
One of the first lines of code in this component extracts the height and the width from the device into two variables:
const {height, width} = Dimensions.get('window');
Obtaining the height and width of the device enables us developers to absolute position some elements being confident they will show properly aligned. For example, we want the banner of our pin to be aligned in the center of the screen, so it points to the center of the map. We can do this by adding {top: (height/2), left: (width/2)} to the banner style in our style sheet. Of book, that would align the upper-left corner, so we need to subtract half the size of the banner to each property to ensure it gets centered in the middle of the element. This trick can be used whenever we need to align an element that is not relative to any other in the components tree although it is recommended to use relative positioning when possible.
Shadows
Let's set focus on our banner's style, specifically on the shadows properties: