Category: Components and APIs
-
AsyncStorage
In this chapter, we will show you how to persist your data using AsyncStorage. Step 1: Presentation In this step, we will create the App.js file. Step 2: Logic Name from the initial state is empty string. We will update it from persistent storage when the component is mounted. setName will take the text from our input field, save it…
-
Geolocation
In this chapter, we will show you how to use Geolocation. Step 1: App.js Step 2: Geolocation We will start by setting up the initial state for that will hold the initial and the last position. Now, we need to get current position of the device when a component is mounted using the navigator.geolocation.getCurrentPosition. We will stringify…
-
Alert
In this chapter, we will understand how to create custom Alert component. Step 1: App.js Step 2: alert_example.js We will create a button for triggering the showAlert function. Output When you click the button, you will see the following −
-
Text
In this chapter, we will talk about Text component in React Native. This component can be nested and it can inherit properties from parent to child. This can be useful in many ways. We will show you example of capitalizing the first letter, styling words or parts of the text, etc. Step 1: Create File The file…
-
Switch
In this chapter, we will explain the Switch component in a couple of steps. Step 1: Create File We will use the HomeContainer component for logic, but we need to create the presentational component. Let us now create a new file: SwitchExample.js. Step 2: Logic We are passing value from the state and functions for toggling switch items to SwitchExample component. Toggle functions will…
-
Status Bar
In this chapter, we will show you how to control the status bar appearance in React Native. The Status bar is easy to use and all you need to do is set properties to change it. The hidden property can be used to hide the status bar. In our example it is set to false. This is default…
-
Picker
In this chapter, we will create simple Picker with two available options. Step 1: Create File Here, the App.js folder will be used as a presentational component. App.js Step 2: Logic this.state.user is used for picker control. The updateUser function will be triggered when a user is picked. PickerExample.js Output If you click on the name it prompts you all…
-
ActivityIndicator
In this chapter we will show you how to use the activity indicator in React Native. Step 1: App App component will be used to import and show our ActivityIndicator. App.js Step 2: ActivityIndicatorExample Animating property is a Boolean which is used for showing the activity indicator. The latter closes six seconds after the component is mounted.…
-
Modal
In this chapter, we will show you how to use the modal component in React Native. Let us now create a new file: ModalExample.js We will put logic inside ModalExample. We can update the initial state by running the toggleModal. After updating the initial state by running the toggleModal, we will set the visible property to our modal. This prop will…
-
WebView
In this chapter, we will learn how to use WebView. It is used when you want to render web page to your mobile app inline. Using WebView The HomeContainer will be a container component. App.js Let us create a new file called WebViewExample.js inside the src/components/home folder. web_view_example.js The above program will generate the following output.