React Native Dynamically Add Render View Component on Button Click in Android iOS App Example Using Animation

Views are the base of every react native application and without them we cannot make certain type of shapes and designs. View can be created programmatically at application run time on a certain event like button click. So in this tutorial we would going to Dynamically Add Render View Component on Button Click in Android iOS App Example Using Animation. We are using the Parent View as ScrollView and will render all the Views inside ScrollView. So let’s get started .

See the live app example :


Contents in this project Dynamically Add Render View Component on Button Click in Android iOS App Example Using Animation:

1. Import StyleSheet, View, Text, Image, ScrollView, TouchableOpacity, Animated and Platform component in your project.

2. Create constructor() in your class and make 2 State named as ViewArray and Disable_Button and animatedValue object with default animation value of Zero with Array_Value_Index.

ViewArray : View array is our main array to make Views.

Disable_Button : This State will used to disable the Floating Button while animation is executing.

animatedValue : Used to set the default animated value as 0.

Array_Value_Index : This array will increase(+1) each time when user trying to add new View and the Value of this would store inside ViewArray.

3. Create a function named as Add_New_View_Function(), Inside this function we would first set the Animated value as 0 and we would save the Array_Value_Index inside a New_Added_View_Value variable. Now we would change the Button State and make the button disable and start the View adding animation and after done inserting View would would increase the Array_Value_Index value to +1 and make the button enable again.

4. Create a constant AnimationValue inside the render’s block and define the input and output range of translateY.

5. Now we would make Render_Animated_View and start printing View dynamically and stored them into this Render_Animated_View.

6. Create a Root View inside render’s return block and inside it would make a ScrollView component and inside the ScrollView we would render the Render_Animated_View variable, We would also make a floating action button using TouchableOpacity after ScrollView closed.

7. Creating Style.

8. Complete source code for App.js File :

Screenshot in Android device:

Dynamically Add Render View Component on Button Click

Screenshot in iOS device: