简体   繁体   English

React Native 在组件之间添加间距

[英]React Native Add Spacing Between Components

I need help fixing the overlap of views in my react native app (Need spacing between them).我需要帮助修复我的本机应用程序中的视图重叠(需要它们之间的间距)。

After pressing the plus sign twice in top right corner, the two Views end up overlapping without any space between them (Which are called HoldWorkout Components)在右上角按两次加号后,两个视图最终重叠,它们之间没有任何空间(称为 HoldWorkout 组件)

Image of overlap重叠的图像

My App.js contains:我的 App.js 包含:

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

PRs is contained in the following Scroll View on Return: PR 包含在以下返回时的滚动视图中:

        <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 in App.js is: App.js 中的样式是:

               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 HoldWorkout.js on return I have在 HoldWorkout.js 返回时,我有

             <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 Style for the View is style.boxWorkouts which is in HoldWorkout.js and looks like视图的样式是 style.boxWorkouts,它在 HoldWorkout.js 中,看起来像

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

I tried adding marginBottom: 100 to styles.boxWorkouts but that is fixed amount and if I click "Add Set" button on one of the HoldWorkout Components then it will add another row which will increase the height of the component and end up overlapping the component underneath it.我尝试将 marginBottom: 100 添加到 styles.boxWorkouts 但这是固定数量,如果我单击 HoldWorkout 组件之一上的“添加设置”按钮,则它将添加另一行,这将增加组件的高度并最终与组件重叠在它下面。

Image of after clicking Add Set on first Hold Workout Component with marginBottom set to 100在第一个 Hold Workout 组件上单击 Add Set 并将 marginBottom 设置为 100 后的图像

Please help on telling me how to fix the spacing for this as I have been trying to figure it out for a while because I am not sure how to get the components pushed down when I click "Add Set" button on the components above.请帮助告诉我如何修复这个间距,因为我一直在尝试解决这个问题,因为当我单击上面组件上的“添加集”按钮时,我不确定如何将组件推下。 This will ensure it wont overlap no matter how many times "Add Set" is pressed on the HoldWorkouts Components Above.这将确保无论在上面的 HoldWorkouts 组件上按下多少次“添加集”,它都不会重叠。

You need to add empty row or empty div with spacing as below.您需要添加空行或空 div,其间距如下。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM