Choose.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. import * as React from 'react';
  2. import { Animated } from 'react-native';
  3. import { Div, Button, Image, Text, Tag, Icon } from 'react-native-magnus';
  4. import { useAnimation } from 'react-native-animation-hooks';
  5. import SvgIcon from './SvgIcon';
  6. const map = new Map([
  7. [
  8. 'bad',
  9. {
  10. name: '非常差',
  11. },
  12. ],
  13. [
  14. 'normal',
  15. {
  16. name: '一般',
  17. },
  18. ],
  19. [
  20. 'good',
  21. {
  22. name: '超赞',
  23. },
  24. ],
  25. ]);
  26. export default function Choose(props) {
  27. const { chooseValue, changeValue } = props;
  28. const badOpacity = useAnimation({
  29. type: 'timing',
  30. initialValue: 1,
  31. duration: 100,
  32. toValue: chooseValue && chooseValue !== 'bad' ? 0 : 1,
  33. });
  34. const normalOpacity = useAnimation({
  35. type: 'timing',
  36. initialValue: 1,
  37. duration: 100,
  38. toValue: chooseValue && chooseValue !== 'normal' ? 0 : 1,
  39. });
  40. const goodOpacity = useAnimation({
  41. type: 'timing',
  42. initialValue: 1,
  43. duration: 100,
  44. toValue: chooseValue && chooseValue !== 'good' ? 0 : 1,
  45. });
  46. const chooseStyle = {
  47. position: 'absolute',
  48. left: '50%',
  49. transform: [{ translateX: 0 - 53 / 2 }],
  50. top: 12,
  51. };
  52. return (
  53. <Div>
  54. <Div row justifyContent="space-around" py={12} px={15}>
  55. <Animated.View
  56. style={[
  57. {
  58. opacity: badOpacity,
  59. },
  60. chooseValue === 'bad' && chooseStyle,
  61. ]}
  62. >
  63. <Button
  64. bg="hide"
  65. disabled={chooseValue}
  66. onPress={() => changeValue('bad')}
  67. >
  68. <Div alignItems="center">
  69. <SvgIcon name="bestBad" width={53} height={53} />
  70. {!chooseValue && (
  71. <Text color="gray500" mt={10} fontSize="xs">
  72. 非常差
  73. </Text>
  74. )}
  75. </Div>
  76. </Button>
  77. </Animated.View>
  78. <Animated.View
  79. style={[
  80. {
  81. opacity: normalOpacity,
  82. },
  83. chooseValue === 'normal' && chooseStyle,
  84. ]}
  85. >
  86. <Button
  87. bg="hide"
  88. disabled={chooseValue}
  89. onPress={() => changeValue('normal')}
  90. >
  91. <Div alignItems="center">
  92. <SvgIcon name="normal" width={53} height={53} />
  93. {!chooseValue && (
  94. <Text color="gray500" mt={10} fontSize="xs">
  95. 一般
  96. </Text>
  97. )}
  98. </Div>
  99. </Button>
  100. </Animated.View>
  101. <Animated.View
  102. style={[
  103. {
  104. opacity: goodOpacity,
  105. },
  106. chooseValue === 'good' && chooseStyle,
  107. ]}
  108. >
  109. <Button
  110. bg="hide"
  111. disabled={chooseValue}
  112. onPress={() => changeValue('good')}
  113. >
  114. <Div alignItems="center">
  115. <SvgIcon name="veryGood" width={53} height={53} />
  116. {!chooseValue && (
  117. <Text color="gray500" mt={10} fontSize="xs">
  118. 超赞
  119. </Text>
  120. )}
  121. </Div>
  122. </Button>
  123. </Animated.View>
  124. </Div>
  125. <Div alignItems="center">
  126. <Div>
  127. {!!chooseValue && (
  128. <Tag
  129. suffix={<Icon name="close" color="black700" fontSize="caption" />}
  130. color="brand500"
  131. onPress={() => changeValue('')}
  132. >
  133. 当前已选择:{map.get(chooseValue).name}
  134. </Tag>
  135. )}
  136. </Div>
  137. </Div>
  138. </Div>
  139. );
  140. }