StatusImage.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. import React, { useEffect, useRef } from 'react';
  2. import { Animated, Easing, Image, StyleSheet, Text, View } from 'react-native';
  3. import utils from '../../utils/utils';
  4. import TextView from '../../components/TextView';
  5. const size = $vw(35) > 280 ? 280 : $vw(35);
  6. export default StatusImage = ({
  7. isLoading=false,
  8. isAuthentic=false,
  9. isInitial=false,
  10. isCharging=false,
  11. isStop=false,
  12. soc=-1
  13. }) => {
  14. var rotate = useRef(new Animated.Value(0)).current;
  15. const spins = () => {
  16. Animated.loop(
  17. Animated.timing(rotate, {
  18. toValue: 1,
  19. duration: 5000,
  20. easing: Easing.linear,
  21. useNativeDriver: true
  22. })
  23. ).start();
  24. }
  25. useEffect(() => {
  26. if (isLoading) {
  27. spins();
  28. }
  29. }, [rotate]);
  30. const spin = rotate.interpolate({
  31. inputRange: [0, 1],
  32. outputRange: ['0deg', '360deg']
  33. })
  34. return (
  35. <View style={styles.chargingHeader}>
  36. <View style={styles.statusView}>
  37. { isAuthentic
  38. ? <Image
  39. style={styles.stepImage}
  40. resizeMode="contain"
  41. source={require('../../images/charge3/status-auth.png')}/>
  42. : (isInitial
  43. ? <Image
  44. style={styles.stepImage}
  45. resizeMode="contain"
  46. source={require('../../images/charge3/status-init.png')}/>
  47. : (isCharging
  48. ? <Image
  49. style={styles.stepImage}
  50. resizeMode="contain"
  51. source={require('../../images/charge3/status-charge.png')}/>
  52. : <Image
  53. style={styles.stepImage}
  54. resizeMode="contain"
  55. source={require('../../images/charge3/status-default.png')}/>
  56. ))}
  57. </View>
  58. { isLoading &&
  59. <Animated.View style={[
  60. styles.loadingBorder, {
  61. transform: [{
  62. rotate: spin
  63. }]
  64. }
  65. ]}>
  66. { isCharging
  67. ? <Image
  68. style={styles.loadingImage}
  69. resizeMode="contain"
  70. source={require('../../images/charge3/anim-charging.png')}/>
  71. : <Image
  72. style={styles.loadingImage}
  73. resizeMode="contain"
  74. source={require('../../images/charge3/anim-loading.png')}/>
  75. }
  76. </Animated.View>
  77. }
  78. { (isAuthentic || isStop) &&
  79. <View style={styles.authBorder}></View>
  80. }
  81. { isStop &&
  82. <View style={styles.centerView}>
  83. <Image
  84. style={styles.checkedImage}
  85. resizeMode="contain"
  86. source={require('../../images/charge3/stop-check.png')}/>
  87. </View>
  88. }
  89. { soc >= 0 &&
  90. <View style={styles.socView}>
  91. <TextView style={styles.socText}>{soc}%</TextView>
  92. </View>
  93. }
  94. </View>
  95. );
  96. }
  97. const styles = StyleSheet.create({
  98. chargingHeader: {
  99. margin: 16,
  100. alignItems: 'center'
  101. },
  102. statusView: {
  103. width: size,
  104. height: size,
  105. padding: 4,
  106. alignItems: 'center',
  107. justifyContent: 'center'
  108. },
  109. stepImage: {
  110. width: '100%',
  111. height: '100%'
  112. },
  113. authBorder: {
  114. top: 0,
  115. width: size,
  116. height: size,
  117. position: 'absolute',
  118. borderWidth: 6,
  119. borderRadius: size,
  120. borderColor: '#00FF19'
  121. },
  122. loadingBorder: {
  123. top: 0,
  124. position: 'absolute',
  125. alignItems: 'center',
  126. justifyContent: 'center'
  127. },
  128. loadingImage: {
  129. width: size,
  130. height: size
  131. },
  132. centerView: {
  133. top: 0,
  134. width: size,
  135. height: size,
  136. position: 'absolute',
  137. alignItems: 'center',
  138. justifyContent: 'center'
  139. },
  140. checkedImage: {
  141. width: size / 2.3,
  142. height: size / 2.3
  143. },
  144. socView: {
  145. width: size,
  146. height: size,
  147. position: 'absolute',
  148. alignItems: 'center',
  149. justifyContent: 'center'
  150. },
  151. socText: {
  152. width: 38,
  153. height: 38,
  154. marginTop: size / -2.5,
  155. marginLeft: size / -4,
  156. fontSize: 13,
  157. fontWeight: 'bold',
  158. borderWidth: 2,
  159. borderRadius: 38,
  160. alignItems: 'center',
  161. justifyContent: 'center',
  162. borderColor: colorAccent,
  163. backgroundColor: colorLight
  164. }
  165. })