HomeScreen.jsx 2.9 KB

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