HomeScreen.jsx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /* eslint-disable react/style-prop-object */
  2. import * as WebBrowser from 'expo-web-browser';
  3. import * as React from 'react';
  4. import { StyleSheet, View, Animated } from 'react-native';
  5. import { ScrollView } from 'react-native-gesture-handler';
  6. import { Div, Button } from 'react-native-magnus';
  7. import { FAB } from 'react-native-paper';
  8. import Constants from 'expo-constants';
  9. import useModel from 'flooks';
  10. import { useMount } from '@umijs/hooks';
  11. import { useAnimation } from 'react-native-animation-hooks';
  12. import { useTranslation } from 'react-i18next';
  13. import Header from './Home/HomeHeader';
  14. import Banner from './Home/Banner';
  15. import MenuCom from './Home/Menu';
  16. import List from './Home/List';
  17. import ListTop from './Home/ListTop';
  18. import RecommendStore from './Home/RecommendStore';
  19. import SpecialArea from './Home/SpecialArea';
  20. import HomeModel from './Home/model';
  21. import Icon from '../../components/SvgIcon';
  22. import TimScreen from '../../chat/TimScreen.tsx';
  23. export default function HomeScreen({ navigation }) {
  24. const { t } = useTranslation();
  25. const { initHome, list, loadingTop } = useModel(HomeModel, [
  26. 'list',
  27. 'loadingTop',
  28. ]);
  29. const [scrollEnabled, setscrollEnabled] = React.useState(true);
  30. const [topHeight, settopHeight] = React.useState(100);
  31. const animatedScrollYValue = React.useRef(new Animated.Value(0)).current;
  32. useMount(() => {
  33. initHome();
  34. });
  35. return (
  36. <>
  37. <Div h={Constants.statusBarHeight} bg="white" />
  38. <Animated.ScrollView
  39. contentContainerStyle={styles.container}
  40. scrollEventThrottle={16}
  41. onScroll={
  42. Animated.event(
  43. [
  44. {
  45. nativeEvent: {
  46. contentOffset: { y: animatedScrollYValue },
  47. }, // 记录滑动距离
  48. },
  49. ],
  50. { useNativeDriver: true }
  51. ) // 使用原生动画驱动}
  52. }
  53. stickyHeaderIndices={[1]}
  54. >
  55. <Header />
  56. <Div bg="white">
  57. <Button
  58. bg="gray200"
  59. color="gray500"
  60. block
  61. fontSize="xs"
  62. mx={15}
  63. my={10}
  64. onPress={() => navigation.navigate('Search')}
  65. >
  66. {t('sou-suo')}
  67. </Button>
  68. </Div>
  69. {!loadingTop && (
  70. <View
  71. onLayout={({ nativeEvent }) => {
  72. settopHeight(nativeEvent.layout.height);
  73. }}
  74. >
  75. <Banner />
  76. <MenuCom />
  77. <SpecialArea />
  78. <RecommendStore />
  79. </View>
  80. )}
  81. <ListTop
  82. animatedScrollYValue={animatedScrollYValue}
  83. topHeight={topHeight}
  84. setscrollEnabled={setscrollEnabled}
  85. />
  86. <List />
  87. </Animated.ScrollView>
  88. <FAB
  89. style={styles.fab}
  90. icon={({ size }) => (
  91. <Icon width={size} height={size} name="cart" type="info" />
  92. )}
  93. color="#fff"
  94. onPress={() => console.log('Pressed')}
  95. />
  96. <TimScreen />
  97. </>
  98. );
  99. }
  100. HomeScreen.navigationOptions = {
  101. header: null,
  102. };
  103. const styles = StyleSheet.create({
  104. container: {
  105. flexGrow: 1,
  106. backgroundColor: '#fff',
  107. },
  108. contentStyle: {
  109. height: 20,
  110. },
  111. text: {
  112. fontSize: 10,
  113. color: '#AAAAAA',
  114. },
  115. main: {
  116. flex: 1,
  117. paddingTop: 10,
  118. width: '100%',
  119. },
  120. fab: {
  121. position: 'absolute',
  122. margin: 16,
  123. right: 0,
  124. bottom: 0,
  125. backgroundColor: '#fff',
  126. },
  127. });