HomeScreen.jsx 3.3 KB

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