Implement Spacing Between Components in React Native

Seeking assistance in resolving the issue of overlapping views within my react native app, specifically requiring spacing between them.

Upon clicking the plus sign twice in the top right corner, the two Views overlap without any space between them (referred to as HoldWorkout Components).

Image illustrating the overlap

The code snippet from my App.js is as follows:

                let PRs = PRArray.map((val, key) => {
                 return (
                     <HoldWorkout
                        key={key}
                        keyval={key}
                        val={val}
                        exName={setName}
                        setsHold={setSets}
                     />
                  );
                });

PRs are contained within a Scroll View with the following structure:

        <View style={styles.container}>
            <View style={styles.whiteColor}>
                <TouchableOpacity
                    activeOpacity={0.5}
                    onPress={addPR.bind(this)}
                    style={styles.TouchableOpacity}
                >
                    <Icon name="ios-add" color="purple" size={45} />
                </TouchableOpacity>

                <View style={styles.header}>
                    <Text style={styles.headerTitle}>Personal Records</Text>
                </View>
            </View>

            <ScrollView style={styles.scrollViewStyle}>
                <View style={styles.color}>{PRs}</View>
            </ScrollView>
        </View>

The styles defined in App.js include:

               const styles = StyleSheet.create({
                   whiteColor: {
                     backgroundColor: "white",
                     borderBottomColor: "#F0EFF5",
                     borderBottomWidth: 2,
                     height: 80
                  },
                  container: {
                    flex: 1,
                    borderBottomColor: "#F0EFF5",
                    borderBottomWidth: 2
                  },
                  color: {
                     marginTop: 20,
                     backgroundColor: "#F0EFF5"
                  },
               });

In the HoldWorkout.js file, the return section comprises of:

             <View key={props.keyval} style={styles.boxWorkouts}>
                 <TextInput
                    style={styles.input2}
                    placeholder="Excercise Name"
                    placeholderTextColor="#a9a9a9"
                    onChangeText={props.exName}
                 />
                 <ExSets weight={setWeights} rep={setRep} date={setDates} />
                 {sets}
                 <View style={styles.addSet}>
                     <Button title="Add Set" color="purple" onPress={addSets}></Button>
                 </View>
             </View>

The specific styling for the View is assigned under style.boxWorkouts in HoldWorkout.js and appears as:

             const styles = StyleSheet.create({
                 boxWorkouts: {
                    borderColor: "#BFBFBF",
                    borderWidth: 1,
                    backgroundColor: "white",
                    height: 90
                 }
              });

Tried incorporating marginBottom: 100 to styles.boxWorkouts, however, this fixed amount doesn't accommodate for changes in component height upon pressing the "Add Set" button, resulting in overlap.

Image showing the result after clicking Add Set on the initial Hold Workout Component with marginBottom set to 100

Require guidance on how to address spacing issues persisting due to the vertical expansion of components when adding new rows upon pressing "Add Set." Struggling to find a solution that adjusts the placement of components accordingly to avoid overlap when multiple "Add Set" actions are triggered on preceding HoldWorkouts Components.

Answer №1

To create the desired spacing, remember to include an empty row or a div with appropriate padding.

let PRs = PRArray.map((val, key) => {
                 return (
                     <div>
                        <HoldWorkout
                          key={key}
                          keyval={key}
                          val={val}
                          exName={setName}
                          setsHold={setSets}
                        />
                        <div>&nbsp; <br/> </div>
                     </div>
                  );
                });

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Ways to showcase the resulting answer using vue.js?

My current query is regarding the display of error messages. How can I show the error message "passwords do not match" {"errors": {"password": ["Passwords donot match"]}, "status": false, "msg": "Validation erro", "error-type": 0} In my code snippet, I h ...

Accessing Category Field Value in Mongoose One-to-Many Relationship

I am managing two collections: Category and Book Book: const mongoose = require('mongoose'); // eslint-disable-next-line camelcase const mongoose_delete = require('mongoose-delete'); const { Schem ...

Tips for eliminating the gap separating the authentication design from the additional elements within the Laravel, Vue, and Inertia framework

I'm currently working with Laravel and Vue using Inertia. When I log into the system, the authentication layout creates a space at the top of the page. How can I resolve this issue? Here is an image highlighting the space I need to remove, marked wit ...

Need to capture click events on an HTML element? Here's how!

I am attempting to capture click events on an <object/> element that is embedding a Flash file This is the approach I have taken so far: <div class="myban" data-go="http://google.com"> <object class="myban" data="index.swf>">< ...

Troubleshooting the issue of JavaScript not executing on elements with a specific CSS class

I am attempting to execute a JavaScript function on each element of an ASP.NET page that is assigned a specific CSS Class. Despite my limited knowledge of JavaScript, I am unable to determine why the code is not functioning properly. The CSS Class is being ...

Filtering tables with checkboxes using Next.js and TypeScript

I've recently delved into Typescript and encountered a roadblock. While I successfully tackled the issue in JavaScript, transitioning to Typescript has left me feeling lost. My dilemma revolves around fetching data from an API and populating a table u ...

Ajax returns with a successful response, yet the specified action is never executed

Currently assisting with a plugin build on Wordpress and facing an issue with a basic ajax call. I am attempting to pass an object through the method 'grab_object_from_ajax_call,' but the method is not executing as expected. Below is the JavaScri ...

Approach the data from various angles, customize the rendering of container components using parameters

Is it considered an antipattern to have a container component return different representation elements based on a condition variable passed to it? For example, I have routes for both the SummaryPageComponent and CustomersPageComponent. The Summary page ha ...

Automatically assign the active class to the initial element in the class list, then update the active class upon clicking with React

As a beginner in React, I am facing an issue with CSS classes. I have two classes defined in my CSS file - btn and btn-active. My goal is to apply the btn-active class to the first button by default, and then remove it from the current button when anothe ...

Querying subdocuments within an array using MongoDB's aggregation framework

Currently, I'm facing a challenge while developing a statistics dashboard for a meditation app. I'm struggling with creating a MongoDB query to fetch the most popular meditations based on user progress. The key collections involved are users and ...

Troubleshooting Routing Issues in a Next.js Website Tutorial

After going through the next.js tutorial at https://github.com/zeit/next-learn-demo.git, I encountered an issue starting from stage 3 "dynamic routing". Despite the tutorial indicating that dynamic routing should be working from stages 3 to 8, it wasn&apos ...

Storing data efficiently with Angular 2's local storage service

I am attempting to create a ToDoList using localstorage within a service. add.component.ts export class AddComponent implements OnInit { item: Item[]; constructor( private router: Router, private itemService: ItemService) { } ...

Challenges with implementing CSS transitions

I've been delving into CSS3 transitions, and I'm encountering some confusion. I can't tell if I'm misunderstanding something or if it's the browsers causing issues. Initially, I believed Opera had transition support starting from ...

The error message "Attempting to send a message using an undefined 'send' property in the welcomeChannel" is displayed

bot.on('guildMemberAdd', (member) => { console.log(member) const welcomeChannel = member.guild.channels.cache.find(channel => channel.name === 'welcome'); //const channelId = '789052445485563935' // welcome c ...

The Ruby on Rails application is having trouble detecting the stylesheet in the assets

I'm having some trouble displaying a border on my buttons. The button styles are defined in the app/assets/stylesheets/modules/_buttons.scss file, which I have imported into application.scss. @import "bootstrap-sprockets"; @import "bootstrap"; //m ...

Integrate an external script with React and initialize a new instance

I've been working on integrating a neat canvas background feature from this GitHub project into my React web application. Here's what I've attempted: import {WarpSpeed} from './warpspeed.js' import WarpSpeed from './warpspee ...

The callback function used for the database query did not provide any results

So here's a code snippet: module.exports.checkEmailInUse = (email) => { connection.query('SELECT `id` FROM `users` WHERE email = ?', [ email ], function(err, rows, fields) { console. ...

What is the best way to ensure that multiple bootstrap buttons in a row have the same width?

Could you help me figure out how to make the <div id="full"> element take up the full width of its parent container, while also ensuring that the 3 buttons inside share this width and have equal sizes with gaps between them? https://i.stac ...

Should I package my dependencies with webpack for production builds?

As I utilize webpack to generate my production bundle for my express application, I had high hopes for the externals field. I believed that it would package up all the required dependencies for deployment without the need for a yarn install or npm install. ...

I attempted to verify the login through postman, but encountered an error in the process

I created the login route on the backend and tested it in Postman, but encountered this error message: https://i.stack.imgur.com/PdyCo.png Below is the code for the login route: router.post("/login", async (req, res) => { try { const user = await ...