MyButton.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. };
  9. static propTypes = {
  10. //按钮宽度
  11. width: PropTypes.string.isRequired,
  12. //按钮高度
  13. height: PropTypes.string.isRequired,
  14. //按钮的圆度
  15. borderRadius: PropTypes.string.isRequired,
  16. //文本的样式
  17. style: PropTypes.object,
  18. //背景颜色
  19. bgColor: PropTypes.string,
  20. //字体颜色
  21. fColor: PropTypes.string,
  22. //文本
  23. text: PropTypes.string.isRequired,
  24. //按钮事件
  25. onPress: PropTypes.func.isRequired,
  26. //用于给残障人士显示的文本
  27. accessibilityLabel: PropTypes.string
  28. }
  29. render() {
  30. let { style, bgColor, fColor, text, accessibilityLabel, width, height, borderRadius, shadowBgc } = this.props
  31. return (
  32. <TouchableOpacity onPress={this.props.onPress}>
  33. <View style={{
  34. width: width,
  35. height: height,
  36. backgroundColor: bgColor,
  37. justifyContent: "center",
  38. alignItems: "center",
  39. shadowRadius: 5,
  40. shadowOpacity: 0.3,
  41. shadowOffset: { width: -2, height: 2 },
  42. shadowColor: shadowBgc,
  43. borderRadius: borderRadius
  44. }}>
  45. <Text style={{
  46. fontWeight: 'bold',
  47. color: fColor,
  48. ...style
  49. }}
  50. accessibilityLabel={accessibilityLabel}
  51. >{text}</Text>
  52. </View>
  53. </TouchableOpacity>
  54. )
  55. }
  56. }