React Native has all the components and functionality that works perfectly for app development but both Android and iOS works differently in design language. To satisfy both the design language and make both look similar to a native application, custom components play a major role in App development.
Let’s take Text field as a really good example both Android and iOS since both of them have a different style for Text Field.
Android:
iOS:
Let’s start by creating a Custom Text Field Component for both Android and iOS which will look similar in their design language.
STEP 1: Create a class for Custom component and define the props which will customize our Custom component.
STEP 2: Then let’s start with the render() method
Here the Platform object separates the code for iOS and Android but the Components are controlled by various props. With a native component, we cannot achieve Android’s material Text Field which can be solved by installing and importing “react-native-material-textfield” for android.
STEP 3: Import the Custom Text Field Component in parent component and make sure you give right path for the component.
STEP 4: Insert the Custom Component inside render() method of parent component where we want the display in.
Now you can run this on iOS and Android to see the difference in the text field which is usually difficult to achieve with default react native text field component. You can also create a useful custom component for Button, Text Label, Search bar etc. Make sure you utilize the advantage of reusable code to the full extent in React Native :)