Banner.jsx 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import * as WebBrowser from 'expo-web-browser';
  2. import * as React from 'react';
  3. import { StyleSheet } from 'react-native';
  4. import { Carousel } from '@ant-design/react-native';
  5. import { Image } from 'react-native-magnus';
  6. import { useCreation } from '@umijs/hooks';
  7. import useModel from 'flooks';
  8. import HomeModel from './model';
  9. export default function Banner({ type, height, round, noDots }) {
  10. const { bannerList } = useModel(HomeModel, ['bannerList']);
  11. const [index, setIndex] = React.useState(0);
  12. const showList = useCreation(() => {
  13. if (type) {
  14. return bannerList.filter((item) => {
  15. return item.type === type;
  16. });
  17. } else {
  18. return bannerList;
  19. }
  20. }, [type, bannerList]);
  21. React.useEffect(() => {
  22. setIndex(0);
  23. }, [type]);
  24. if (showList.length > 0) {
  25. return (
  26. <Carousel
  27. style={styles.wrapper}
  28. selectedIndex={index}
  29. autoplay
  30. infinite
  31. afterChange={setIndex}
  32. dots={!noDots}
  33. >
  34. {showList.map(
  35. (item) =>
  36. !!item.pic && (
  37. <Image
  38. key={item.id}
  39. rounded={round ? 'xs' : 'none'}
  40. source={{
  41. uri: item.pic,
  42. }}
  43. w="100%"
  44. h={height || 80}
  45. />
  46. )
  47. )}
  48. </Carousel>
  49. );
  50. } else {
  51. return null;
  52. }
  53. }
  54. const styles = StyleSheet.create({
  55. wrapper: {
  56. // height: 80,
  57. },
  58. });