Advertisement
Guest User

Untitled

a guest
Mar 30th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.98 KB | None | 0 0
  1. import React, { Component, PropTypes } from 'react';
  2. import {
  3. ActivityIndicator,
  4. LayoutAnimation,
  5. StyleSheet,
  6. Text,
  7. TouchableOpacity,
  8. View,
  9. Image,
  10. } from 'react-native';
  11. import LinearGradient from 'react-native-linear-gradient';
  12.  
  13. const LoginBtn = require('../../../img/button_04.png');
  14.  
  15. const { any, bool, func, string } = PropTypes;
  16.  
  17. class Button extends Component {
  18.  
  19. static propTypes = {
  20. label: string,
  21. onPress: func,
  22. loading: bool,
  23. style: any,
  24. Active : bool,
  25. };
  26.  
  27. static defaultProps = {
  28. loading: false,
  29. onPress: emptyFn,
  30. Active : true,
  31. };
  32.  
  33. onPressButton = () => {
  34. const { loading, onPress } = this.props;
  35.  
  36. LayoutAnimation.easeInEaseOut();
  37. onPress(!loading);
  38. }
  39.  
  40. renderActivityIndicator() {
  41. if (this.props.loading) {
  42. return (
  43. <ActivityIndicator size="small" color="#fff" />
  44. );
  45. }
  46. }
  47.  
  48. renderLabel() {
  49. const { label, loading,Active } = this.props;
  50. if(!loading) {
  51. return (
  52. <Text style={ Active ? styles.label2:styles.label}>{label}</Text>
  53. );
  54. }
  55. }
  56.  
  57. render() {
  58. const { loading, style,Active} = this.props;
  59.  
  60. return (
  61. <View>
  62.  
  63. <TouchableOpacity
  64. disabled={Active}
  65. style={[
  66. styles.main,
  67. style,
  68. loading ? styles.loading : null,
  69. ]}
  70. activeOpacity={0.4}
  71. onPress={this.onPressButton}
  72. >
  73. <Image source={LoginBtn} style={Active ? styles.Butt2:styles.Butt}>
  74.  
  75. </Image>
  76. <View style={{position:'absolute', top:-5, backgroundColor:'transparent', textAlign:'center', left: 0, right: 0, bottom: 0, justifyContent: 'center', alignItems: 'center'}}>
  77. {this.renderLabel()}
  78. {this.renderActivityIndicator()}
  79. </View>
  80.  
  81.  
  82. </TouchableOpacity>
  83. </View>
  84.  
  85. );
  86. }
  87. }
  88.  
  89. function emptyFn() {}
  90.  
  91. const styles = StyleSheet.create({
  92. main: {
  93.  
  94. paddingLeft:55,
  95. paddingRight:55,
  96. // backgroundColor: 'red',
  97. borderRadius: 20,
  98. // padding: 10,
  99. // paddingLeft: 135,
  100. // paddingRight: 135,
  101.  
  102. },
  103. Butt : {
  104. height:50, paddingRight:100, width:null, resizeMode:'contain', opacity:1
  105. },
  106. Butt2 : {
  107. height:50, paddingRight:100, width:null, resizeMode:'contain', opacity:0.6
  108. },
  109. main2: {
  110.  
  111. paddingLeft:55,
  112. paddingRight:55,
  113. // backgroundColor: 'red',
  114. borderRadius: 20,
  115. // padding: 10,
  116. // paddingLeft: 135,
  117. // paddingRight: 135,
  118. backgroundColor: 'rgba(255,255,255,0.9)',
  119. },
  120. label: {
  121. color: '#fff',
  122. fontWeight: 'bold',
  123. textAlign: 'center',
  124. backgroundColor: 'transparent',
  125. },
  126. label2: {
  127. color: 'rgba(255,255,255,0.4)',
  128. fontWeight: 'bold',
  129. textAlign: 'center',
  130. backgroundColor: 'transparent',
  131. },
  132. loading: {
  133. // padding: 10,
  134. // paddingLeft: 10,
  135. // paddingRight: 10,
  136. },
  137. buttonNextWrappr:{
  138. // resizeMode: "stretch"
  139. },
  140.  
  141. });
  142.  
  143. export default Button;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement