Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | import React from 'react'; import { css } from '@emotion/react'; import PageComponent from '@lib/components/Game/Screen/FreeForm/Page'; import { Swiper, SwiperSlide } from 'swiper/react'; import { Pagination } from 'swiper'; import { PaginationOptions } from 'swiper/types'; import { SwipeScreen as SwipeScreenModel } from '@uniquegood/realworld-web-interface/lib/models/game/Screen/Swipe'; import { useContentAnalyticsContext } from '@lib/providers/ContentAnalytics'; import { MAX_HEIGHT_DP, MAX_WIDTH_DP } from '@uniquegood/realworld-web-interface/lib/constants/game'; import { useGameStateContext } from '@lib/providers/GameState'; import { color } from '@uniquegood/realworld-studio-design'; export default function SwipeScreen({ id, type, name, pageList, initial }: SwipeScreenModel) { const pagination: PaginationOptions = { clickable: true, renderBullet(index, className) { return `<div class="${className}"></div>`; } }; const { gameStateRef, saveOnServer } = useGameStateContext(); const initialPageIndex = React.useMemo(() => { return ( gameStateRef.current.gameMeta.screen?.[gameStateRef.current.currentScreenId] ?.swipePageIndex ?? initial?.pageIndex ?? 0 ); }, []); const handleSliderMove = (swiper: any) => { gameStateRef.current = { ...gameStateRef.current, gameMeta: { ...gameStateRef.current.gameMeta, screen: { ...gameStateRef.current.gameMeta.screen, [gameStateRef.current.currentScreenId]: { ...gameStateRef.current.gameMeta.screen?.[gameStateRef.current.currentScreenId], swipePageIndex: swiper.activeIndex } } } }; saveOnServer(); }; const { consumeEvent } = useContentAnalyticsContext(); const handleSwiperSlideChange = (swiper: any) => { const prevPageId = swiper.activeIndex > 0 ? pageList[swiper.activeIndex - 1].id : ''; const nextPageId = swiper.activeIndex < pageList.length - 1 ? pageList[swiper.activeIndex + 1].id : ''; // CA: 페이지 이동 이벤트 consumeEvent({ eventType: 'MovePage', metadata: { currentScreen: id, fromPage: prevPageId, toPage: nextPageId } }); }; return ( <div css={screenContainer}> <Swiper initialSlide={initialPageIndex} onActiveIndexChange={handleSliderMove} pagination={pagination} modules={[Pagination]} css={slideContainer} onSlideChange={handleSwiperSlideChange} touchStartPreventDefault={false} > {pageList.map((pageData) => { return ( <SwiperSlide key={pageData.id}> <PageComponent {...pageData} /> </SwiperSlide> ); })} </Swiper> </div> ); } const screenContainer = css` position: absolute; top: 0; left: 0; width: ${MAX_WIDTH_DP}px; height: ${MAX_HEIGHT_DP}px; .swiper { position: relative; } .swiper .swiper-pagination { position: absolute; top: 6px; left: 0; right: 0; display: flex; flex-direction: row; justify-content: space-between; width: 100%; height: 4px; } .swiper .swiper-pagination-bullet { background-color: #000000; border-radius: 4px; width: 100%; height: 4px; opacity: 0.2; } .swiper .swiper-pagination-bullet-active { background-color: ${color.palette_primary_purple_100}; opacity: 0.5; } `; const slideContainer = css` width: 100%; height: 100%; `; |