We all know that buttons are an essential UI component in every application. We use buttons for navigation, to trigger API calls, and so on. In this recipe, we will create a toggle button, which by default is going to be unselected. When the user taps on it, we will change the styles of the button to make it look selected.
We will learn how to detect the tap event, use an image as the UI, keep the state of the button, and add styles based on the component state.
Let's create a new app using the React Native CLI. We are going to name it
ButtonsAndEvents. We are going to use one image in this recipe; make sure to download the assets for this recipe or feel free to use your own image.