react-native-elements,按钮边距不生效

react-native-elements, button margin not taking effect

我遇到了一个问题,在应用 marginTop: 15 属性.

后,按钮上方有一个白色阴影

发生这种情况是因为 buttonStyle 将样式应用到内部 View 并且因为高度(阴影)应用到外部 View,这样你基本上创建了一个 'padding' 在外面 View.

我原以为它会按照您在下面看到的以下方式解决:

import React, { Component } from "react";
import { View, Text, ScrollView, Dimensions } from "react-native";
import { Button } from "react-native-elements";

const SCREEN_WIDTH = Dimensions.get("window").width;

class Slides extends Component {
  renderLastSlide(index) {
    if (index === this.props.data.length - 1) {
      return (
        <Button
          title="Onwards!"
          raised
          buttonStyle={styles.buttonStyle}
          containerViewStyle={{ marginTop: 15 }}
          onPress={this.props.onComplete}
        />
      );
    }
  }

  renderSlides() {
    return this.props.data.map((slide, index) => {
      return (
        <View
          key={slide.text}
          style={[styles.slideStyle, { backgroundColor: slide.color }]}
        >
          <Text style={styles.textStyles}>{slide.text}</Text>
          {this.renderLastSlide(index)}
        </View>
      );
    });
  }

  render() {
    return (
      <ScrollView horizontal style={{ flex: 1 }} pagingEnabled>
        {this.renderSlides()}
      </ScrollView>
    );
  }
}

const styles = {
  slideStyle: {
    flex: 1,
    justifyContent: "center",
    alignItems: "center",
    width: SCREEN_WIDTH
  },
  textStyles: {
    fontSize: 30,
    color: "white",
    textAlign: "center"
  },
  buttonStyle: {
    backgroundColor: "#0288D1"
  }
};

export default Slides;

但是 marginTop: 15 现在对按钮没有影响。我不确定在这里还能做什么。

你可以试试View

<View style={{marginTop: 15}}}>
  <Button
          title="Onwards!"
          raised
          buttonStyle={styles.buttonStyle}
          onPress={this.props.onComplete}
        />
<View>

不使用“样式”将样式应用到 React Native Elements 组件,而是使用 containerStyle

这里是对文档的引用:

https://reactnativeelements.com/docs/customization/

一个例子:

        // A React Native Elements button
        <Button
            containerStyle={styles.button} // apply styles calling "containerStyle"
            title="Sign up"
        />

       // On the StyleSheet:
       const styles = StyleSheet.create({
        
         button: {
           color: '#C830CC',
           margin: 10,
         },
    
       });