React Native Change Text Font Size on Button Click Example

Hello friends, In today’s tutorial we would learn about increasing and decreasing Text component size on button click in react native. This would be possible via State management. Now what we are doing is that on the fontSize style prop we would pass a State variable which value can be change dynamically on button onPress event. Now the main part is that we would Toggle the smaller and larger values. When first time click on button it will increase the Text font size now again when user clicks on button it will decrease the value. So in this tutorial we would learn about React Native Change Text Font Size on Button Click Example.

Contents in this project React Native Change Text Font Size on Button Click Example :-

1. Open your project’s main App.js file and import useState, Text, StyleSheet, Button and SafeAreaView component.

2. Creating our main App component.

3. Creating 1 State named as FontSize with State update method setFontSize with default value of 20. This is our default text font size.

4. Creating another State named as text with State update method setText with default Button above text. Now we would use this State to update button above text on font increase and decrease time.

5. Creating a function named as letChangeTextSize(). In this function we would simply increase and decrease Text font values using Toggle. So this 1 function will do both work for us.

6. Creating return() block, Now here we would make our Text component and Button component.

7. Creating Style.

8. Complete Source Code for App.js File :-

Screenshots :-

React Native Change Text Font Size on Button Click Example

Leave a Reply

Your email address will not be published. Required fields are marked *