ChooseMerchant.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. 'good',
  15. {
  16. name: '好评',
  17. },
  18. ],
  19. ]);
  20. export default function Choose(props) {
  21. const { chooseValue, changeValue } = props;
  22. const badOpacity = useAnimation({
  23. type: 'timing',
  24. initialValue: 1,
  25. duration: 100,
  26. toValue: chooseValue && chooseValue !== 'bad' ? 0 : 1,
  27. });
  28. const goodOpacity = useAnimation({
  29. type: 'timing',
  30. initialValue: 1,
  31. duration: 100,
  32. toValue: chooseValue && chooseValue !== 'good' ? 0 : 1,
  33. });
  34. const chooseStyle = {
  35. position: 'absolute',
  36. left: '50%',
  37. transform: [{ translateX: 0 - 53 / 2 }],
  38. top: 12,
  39. };
  40. return (
  41. <Div>
  42. <Div row justifyContent="space-around" py={12} px={15}>
  43. <Animated.View
  44. style={[
  45. {
  46. opacity: badOpacity,
  47. },
  48. chooseValue === 'bad' && chooseStyle,
  49. ]}
  50. >
  51. <Button
  52. bg="hide"
  53. disabled={chooseValue}
  54. onPress={() => changeValue('bad')}
  55. >
  56. <Div alignItems="center">
  57. <SvgIcon name="bad" width={53} height={53} />
  58. </Div>
  59. </Button>
  60. </Animated.View>
  61. <Animated.View
  62. style={[
  63. {
  64. opacity: goodOpacity,
  65. },
  66. chooseValue === 'good' && chooseStyle,
  67. ]}
  68. >
  69. <Button
  70. bg="hide"
  71. disabled={chooseValue}
  72. onPress={() => changeValue('good')}
  73. >
  74. <Div alignItems="center">
  75. <SvgIcon name="good" width={53} height={53} />
  76. </Div>
  77. </Button>
  78. </Animated.View>
  79. </Div>
  80. <Div alignItems="center">
  81. <Div>
  82. {!!chooseValue && (
  83. <Tag
  84. suffix={<Icon name="close" color="black700" fontSize="caption" />}
  85. color="brand500"
  86. onPress={() => changeValue('')}
  87. >
  88. 当前已选择:{map.get(chooseValue).name}
  89. </Tag>
  90. )}
  91. </Div>
  92. </Div>
  93. </Div>
  94. );
  95. }