MyButton.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import React, { Component } from 'react'
  2. import { Text, TouchableOpacity, View } from 'react-native'
  3. import PropTypes from 'prop-types'
  4. export default class MyButton extends Component {
  5. static defaultProps = {
  6. bgColor: '#000',
  7. fColor: '#fff',
  8. borderColor: null,
  9. borderWidth:null
  10. };
  11. static propTypes = {
  12. //按钮宽度
  13. width: PropTypes.string.isRequired,
  14. //按钮高度
  15. height: PropTypes.string.isRequired,
  16. //按钮的圆度
  17. borderRadius: PropTypes.string.isRequired,
  18. //文本的样式
  19. style: PropTypes.object,
  20. //背景颜色
  21. bgColor: PropTypes.string,
  22. //字体颜色
  23. fColor: PropTypes.string,
  24. //文本
  25. text: PropTypes.string.isRequired,
  26. //按钮事件
  27. onPress: PropTypes.func.isRequired,
  28. //用于给残障人士显示的文本
  29. accessibilityLabel: PropTypes.string
  30. }
  31. render() {
  32. let { style, bgColor, fColor, text, accessibilityLabel, width, height, borderRadius, shadowBgc, borderColor, borderWidth } = this.props
  33. return (
  34. <TouchableOpacity onPress={this.props.onPress}>
  35. <View style={{
  36. width: width,
  37. height: height,
  38. backgroundColor: bgColor,
  39. justifyContent: "center",
  40. alignItems: "center",
  41. shadowRadius: 5,
  42. shadowOpacity: 0.3,
  43. shadowOffset: { width: -2, height: 2 },
  44. shadowColor: shadowBgc,
  45. borderRadius: borderRadius,
  46. borderWidth: borderWidth,
  47. borderColor: borderColor
  48. }}>
  49. <Text style={{
  50. fontWeight: 'bold',
  51. color: fColor,
  52. ...style
  53. }}
  54. accessibilityLabel={accessibilityLabel}
  55. >{text}</Text>
  56. </View>
  57. </TouchableOpacity>
  58. )
  59. }
  60. }