ListTop.jsx 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. import * as WebBrowser from 'expo-web-browser';
  2. import * as React from 'react';
  3. import { Animated, Dimensions } from 'react-native';
  4. import { Div, Button, Text, Icon } from 'react-native-magnus';
  5. import { useBoolean, useCreation } from '@umijs/hooks';
  6. import { useAnimation } from 'react-native-animation-hooks';
  7. import useModel from 'flooks';
  8. import HomeModel from './model';
  9. import { sortMap, filterMap, tagMap } from '../../../Utils/MerchantUtils';
  10. import Filter from './Filter';
  11. export default function ListTop({
  12. animatedScrollYValue,
  13. topHeight,
  14. setscrollEnabled,
  15. }) {
  16. const SortMenu = useBoolean(false);
  17. const filterMenu = useBoolean(false);
  18. const {
  19. sort,
  20. changeSort,
  21. merchantNatureList,
  22. getNature,
  23. clearFiliter,
  24. ChangeFiliter,
  25. filter,
  26. tag,
  27. natureId,
  28. endAmount,
  29. } = useModel(HomeModel, [
  30. 'sort',
  31. 'merchantNatureList',
  32. 'filter',
  33. 'tag',
  34. 'natureId',
  35. 'endAmount',
  36. ]);
  37. React.useEffect(() => {
  38. if (merchantNatureList.length === 0) {
  39. getNature();
  40. // setscrollEnabled(false);
  41. }
  42. }, [merchantNatureList]);
  43. const top = useCreation(() => {
  44. return topHeight ? topHeight + 56 : 200;
  45. }, [topHeight]);
  46. const translateY = animatedScrollYValue.interpolate({
  47. inputRange: [-1, 0, top, top + 1],
  48. outputRange: [0, 0, 0, 1],
  49. });
  50. const soltType = useCreation(() => {
  51. return 'first';
  52. }, [sort]);
  53. const sortInfo = useCreation(() => {
  54. return sortMap.get(sort);
  55. }, [sort]);
  56. const SortHeight = useAnimation({
  57. type: 'timing',
  58. initialValue: 0,
  59. duration: 100,
  60. toValue: SortMenu.state ? 230 : 0,
  61. });
  62. return (
  63. <>
  64. <Animated.View
  65. style={{
  66. zIndex: 100,
  67. backgroundColor: 'rgba(0,0,0,0)',
  68. transform: [{ translateY }],
  69. }}
  70. >
  71. <Div row bg="white">
  72. <Button
  73. onPress={SortMenu.setTrue}
  74. bg="hide"
  75. fontSize="xl"
  76. px={10}
  77. color={soltType === 'first' ? 'brand500' : 'gray600'}
  78. >
  79. 推荐商家
  80. </Button>
  81. {/* <View style={{ width: 33 }} /> */}
  82. <Button
  83. bg="hide"
  84. fontSize="xl"
  85. color="gray600"
  86. px={10}
  87. mx={10}
  88. onPress={() => {}}
  89. >
  90. 发现美食
  91. </Button>
  92. </Div>
  93. <Div row bg="white" alignItems="center">
  94. <Button
  95. onPress={() => {
  96. SortMenu.toggle();
  97. filterMenu.setFalse();
  98. }}
  99. bg="hide"
  100. px={10}
  101. >
  102. <Text
  103. fontSize="xs"
  104. color={
  105. sort && sortInfo.showType !== 'top' ? 'brand500' : 'gray600'
  106. }
  107. >
  108. {sortInfo.showType !== 'top'
  109. ? sortInfo.name
  110. : sortMap.get('').name}
  111. </Text>
  112. <Icon
  113. name="down"
  114. fontSize="xs"
  115. color={
  116. sort && sortInfo.showType !== 'top' ? 'brand500' : 'gray600'
  117. }
  118. />
  119. </Button>
  120. <Button
  121. fontSize="xs"
  122. bg="hide"
  123. color={sort === '7' ? 'brand500' : 'gray600'}
  124. px={10}
  125. onPress={() => {
  126. changeSort('7');
  127. SortMenu.setFalse();
  128. filterMenu.setFalse();
  129. }}
  130. >
  131. 距离
  132. </Button>
  133. <Button
  134. fontSize="xs"
  135. bg="hide"
  136. color={sort === '8' ? 'brand500' : 'gray600'}
  137. px={10}
  138. onPress={() => {
  139. changeSort('8');
  140. SortMenu.setFalse();
  141. filterMenu.setFalse();
  142. }}
  143. >
  144. 销量
  145. </Button>
  146. <Div flex={1} />
  147. <Button
  148. onPress={() => {
  149. filterMenu.toggle();
  150. SortMenu.setFalse();
  151. }}
  152. bg="hide"
  153. px={10}
  154. >
  155. <Text fontSize="xs" color="gray600">
  156. 筛选
  157. </Text>
  158. <Icon
  159. name="down"
  160. fontSize="xs"
  161. color={
  162. sort && sortInfo.showType !== 'top' ? 'brand500' : 'gray600'
  163. }
  164. />
  165. </Button>
  166. </Div>
  167. <Animated.View
  168. style={{
  169. height: SortHeight,
  170. overflow: 'hidden',
  171. backgroundColor: '#fff',
  172. }}
  173. >
  174. {[...sortMap.keys()].map((item, index) => {
  175. const info = sortMap.get(item);
  176. return info.showType !== 'top' ? (
  177. <Button
  178. key={index}
  179. block
  180. bg="white"
  181. rounded="none"
  182. onPress={() => {
  183. SortMenu.setFalse();
  184. changeSort(item);
  185. }}
  186. >
  187. <Text
  188. fontSize="xs"
  189. flex={1}
  190. color={sort === item ? 'brand500' : 'gray600'}
  191. >
  192. {info.name}
  193. </Text>
  194. </Button>
  195. ) : null;
  196. })}
  197. </Animated.View>
  198. <Filter
  199. show={filterMenu.state}
  200. merchantNatureList={merchantNatureList}
  201. filters={filter}
  202. tags={tag}
  203. natureId={natureId}
  204. endAmount={endAmount}
  205. clear={() => {
  206. filterMenu.setFalse();
  207. clearFiliter();
  208. }}
  209. submit={(filter, tag, natureId, endAmount) => {
  210. filterMenu.setFalse();
  211. ChangeFiliter(filter, tag, natureId, endAmount);
  212. }}
  213. />
  214. </Animated.View>
  215. {(SortMenu.state || filterMenu.state) && (
  216. <Button
  217. bg="black600"
  218. position="absolute"
  219. top={top + 60}
  220. left={0}
  221. right={0}
  222. bottom={0}
  223. zIndex={2}
  224. onPress={() => {
  225. SortMenu.setFalse();
  226. filterMenu.setFalse();
  227. }}
  228. />
  229. )}
  230. </>
  231. );
  232. }