Guest User

Untitled

a guest
Dec 11th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. import React, { Component } from 'react';
  2. import { Text, TouchableOpacity, Linking } from 'react-native';
  3.  
  4. // 1. Changed to a class based component
  5. class Button extends Component {
  6. constructor(props) {
  7. super(props);
  8. }
  9.  
  10. // 2. Custom function called onPress TouchableOpacity
  11. onPressHandler = () => {
  12. const { onPress, url } = this.props
  13. if (url) {
  14. Linking.openURL(url)
  15. }
  16. onPress()
  17. }
  18.  
  19. render(){
  20. const { buttonStyle, textStyle } = styles;
  21. const { label, primary } = this.props;
  22.  
  23. // 3. Change color of button depending on 'primary' prop
  24. const newButtonStyle = primary ? buttonStyle : [buttonStyle, { backgroundColor: '#f34541', borderBottomColor: '#a43532' }];
  25.  
  26. return (
  27. <TouchableOpacity onPress={this.onPressHandler} style={newButtonStyle}>
  28. <Text style={textStyle}>
  29. {label}
  30. </Text>
  31. </TouchableOpacity>
  32. );
  33. }
  34. };
  35.  
  36. Button.defaultProps = {
  37. primary: true,
  38. }
  39.  
  40. const styles = {
  41. textStyle: {
  42. alignSelf: 'center',
  43. color: '#fff',
  44. fontSize: 16,
  45. fontWeight: '600',
  46. },
  47. buttonStyle: {
  48. height: 45,
  49. alignSelf: 'stretch',
  50. justifyContent: 'center',
  51. backgroundColor: '#38ba7d',
  52. borderBottomWidth: 6,
  53. borderBottomColor: '#1e6343',
  54. borderWidth: 1,
  55. marginLeft: 15,
  56. marginRight: 15
  57. }
  58. };
  59.  
  60. export default Button;
Add Comment
Please, Sign In to add comment