0

marginTop: 15应用属性后,我遇到了一个问题,即按钮上方有一个白色阴影。

发生这种情况是因为buttonStyle将样式应用于内部View,并且由于高程(阴影)应用于外部View,因此您基本上可以在外部创建“填充” 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现在对按钮没有影响。我不确定在这里还能做什么。

4

2 回答 2

3

你可以试试View

<View style={{marginTop: 15}}}>
  <Button
          title="Onwards!"
          raised
          buttonStyle={styles.buttonStyle}
          onPress={this.props.onComplete}
        />
<View>
于 2019-05-08T02:27:34.460 回答
1

不要使用“样式”将样式应用于 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,
         },
    
       });
于 2021-04-11T16:38:16.037 回答