MerchantDetailScreen.jsx 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. import * as WebBrowser from 'expo-web-browser';
  2. import * as React from 'react';
  3. import {
  4. ImageBackground,
  5. StyleSheet,
  6. Animated,
  7. Dimensions,
  8. View,
  9. } from 'react-native';
  10. import { Flex } from '@ant-design/react-native';
  11. import { ScrollView } from 'react-native-gesture-handler';
  12. import { Div, Text, Button } from 'react-native-magnus';
  13. import Constants from 'expo-constants';
  14. import { createMaterialTopTabNavigator } from '@react-navigation/material-top-tabs';
  15. import { useRoute } from '@react-navigation/native';
  16. import { useDebounceFn } from '@umijs/hooks';
  17. // import { useAnimation } from 'react-native-animation-hooks';
  18. import useModel from 'flooks';
  19. import Detail from './model'; // detail模块通用方法
  20. // import Text from '../../components/Text';
  21. // import Button from '../../components/Button';
  22. import Header from './Header';
  23. import Center from './Center';
  24. import Order from './Order';
  25. import Cart from './Cart'; // order 页面的选购
  26. import Comment from './Comment'; // order 页面的选购
  27. import Merchant from './Merchant'; // order 页面的选购
  28. import SelectSpecification from './SelectSpecification'; // order 页面的选购
  29. const Tab = createMaterialTopTabNavigator();
  30. export default function MerchantDetail({ navigation }) {
  31. const route = useRoute();
  32. const { params } = route;
  33. const { init, merchantInfo, setHeaderColor } = useModel(Detail, ['id']);
  34. const [tabTop, settabTop] = React.useState(0);
  35. const [screenName, setscreenName] = React.useState('Order');
  36. const { banner } = merchantInfo;
  37. const scorellRef = React.createRef();
  38. const { run } = useDebounceFn(() => {
  39. scorellRef.current.scrollTo({
  40. x: 0,
  41. y: tabTop,
  42. animated: true,
  43. });
  44. }, 1200);
  45. React.useEffect(() => {
  46. if (params.merchantId) {
  47. init(params.merchantId);
  48. }
  49. if (params.screen) {
  50. setscreenName(params.screen);
  51. } else {
  52. setscreenName('Order');
  53. }
  54. }, [params]);
  55. return (
  56. <>
  57. <Header />
  58. <ScrollView
  59. ref={scorellRef}
  60. stickyHeaderIndices={[1]}
  61. style={{
  62. flexGrow: 1,
  63. }}
  64. contentContainerStyle={{ backgroundColor: '#eee' }}
  65. keyboardDismissMode="on-drag"
  66. onScroll={({ nativeEvent }) => {
  67. const { contentOffset } = nativeEvent;
  68. const topHeight = 118 + Constants.statusBarHeight;
  69. if (contentOffset.y >= 5 && contentOffset.y <= topHeight) {
  70. const op = (contentOffset.y / topHeight).toFixed(1);
  71. setHeaderColor(`rgba(255, 194, 28, ${Number(op)})`);
  72. } else if (contentOffset.y < 5) {
  73. setHeaderColor('');
  74. }
  75. }}
  76. scrollEventThrottle={16}
  77. >
  78. <Div
  79. onLayout={(e) => {
  80. settabTop(e.nativeEvent.layout.height);
  81. }}
  82. zIndex={12}
  83. >
  84. <ImageBackground
  85. style={{
  86. height: 118 + Constants.statusBarHeight,
  87. }}
  88. resizeMode="cover"
  89. source={{ uri: banner }}
  90. >
  91. <View style={{ flex: 1, backgroundColor: 'rgba(0,0,0,.1)' }} />
  92. </ImageBackground>
  93. <Center />
  94. </Div>
  95. <Div bg="brand500" pt={56 + Constants.statusBarHeight}>
  96. <Div row bg="gray200">
  97. <Button
  98. flex={1}
  99. bg="hide"
  100. color={screenName === 'Order' ? 'brand500' : 'gray600'}
  101. h={60}
  102. onPress={() => {
  103. run();
  104. navigation.navigate('MerchantDetail', {
  105. screen: 'Order',
  106. });
  107. }}
  108. >
  109. 订单
  110. </Button>
  111. <Button
  112. flex={1}
  113. bg="hide"
  114. color={screenName === 'Comment' ? 'brand500' : 'gray600'}
  115. h={60}
  116. onPress={() => {
  117. run();
  118. navigation.navigate('MerchantDetail', {
  119. screen: 'Comment',
  120. });
  121. }}
  122. >
  123. 评论
  124. </Button>
  125. <Button
  126. flex={1}
  127. bg="hide"
  128. color={screenName === 'Merchant' ? 'brand500' : 'gray600'}
  129. h={60}
  130. onPress={() => {
  131. run();
  132. navigation.navigate('MerchantDetail', {
  133. screen: 'Merchant',
  134. });
  135. }}
  136. >
  137. 商家
  138. </Button>
  139. </Div>
  140. </Div>
  141. <Div minH={Dimensions.get('window').height}>
  142. <Tab.Navigator
  143. initialRouteName="Order"
  144. tabBarOptions={{ showLabel: false, style: { height: 0 } }}
  145. initialLayout={{
  146. height: Dimensions.get('window').height,
  147. width: Dimensions.get('window').width,
  148. }}
  149. backBehavior="initialRoute"
  150. >
  151. <Tab.Screen name="Order" component={Order} />
  152. <Tab.Screen name="Comment" component={Comment} />
  153. <Tab.Screen name="Merchant" component={Merchant} />
  154. </Tab.Navigator>
  155. </Div>
  156. </ScrollView>
  157. <Cart />
  158. <SelectSpecification />
  159. </>
  160. );
  161. }
  162. const styles = StyleSheet.create({});