|
| 1 | +import React from 'react'; |
| 2 | +import {Rect} from 'react-native-svg'; |
| 3 | +import useResponsiveLayout from '@hooks/useResponsiveLayout'; |
| 4 | +import useThemeStyles from '@hooks/useThemeStyles'; |
| 5 | +import useWindowDimensions from '@hooks/useWindowDimensions'; |
| 6 | +import variables from '@styles/variables'; |
| 7 | +import ItemListSkeletonView from './ItemListSkeletonView'; |
| 8 | + |
| 9 | +const barHeight = 7; |
| 10 | +const longBarWidth = 120; |
| 11 | +const shortBarWidth = 60; |
| 12 | +const leftPaneWidth = variables.navigationTabBarSize; |
| 13 | +const gapWidth = 12; |
| 14 | + |
| 15 | +type WorkspaceRowSkeletonProps = { |
| 16 | + shouldAnimate?: boolean; |
| 17 | + fixedNumItems?: number; |
| 18 | + gradientOpacityEnabled?: boolean; |
| 19 | +}; |
| 20 | + |
| 21 | +function WorkspaceRowSkeleton({shouldAnimate = true, fixedNumItems, gradientOpacityEnabled = false}: WorkspaceRowSkeletonProps) { |
| 22 | + const styles = useThemeStyles(); |
| 23 | + const {windowWidth} = useWindowDimensions(); |
| 24 | + const {shouldUseNarrowLayout} = useResponsiveLayout(); |
| 25 | + // We calculate the width of the sections on the skeleton by first calculating the skeleton view width |
| 26 | + // Then we subtract the width by 66, which is the x position of the first part. |
| 27 | + const partWidth = Math.floor((windowWidth - leftPaneWidth - gapWidth * 2 - 66) / 3); |
| 28 | + return ( |
| 29 | + <ItemListSkeletonView |
| 30 | + shouldAnimate={shouldAnimate} |
| 31 | + fixedNumItems={fixedNumItems} |
| 32 | + gradientOpacityEnabled={gradientOpacityEnabled} |
| 33 | + itemViewStyle={[styles.highlightBG, styles.mb2, styles.br3, styles.ml5]} |
| 34 | + renderSkeletonItem={() => ( |
| 35 | + <> |
| 36 | + <Rect |
| 37 | + x={12} |
| 38 | + y={12} |
| 39 | + rx={5} |
| 40 | + ry={5} |
| 41 | + width={36} |
| 42 | + height={40} |
| 43 | + /> |
| 44 | + <Rect |
| 45 | + x={66} |
| 46 | + y={22} |
| 47 | + width={longBarWidth} |
| 48 | + height={barHeight} |
| 49 | + /> |
| 50 | + <Rect |
| 51 | + x={66} |
| 52 | + y={36} |
| 53 | + width={shortBarWidth} |
| 54 | + height={barHeight} |
| 55 | + /> |
| 56 | + {!shouldUseNarrowLayout && ( |
| 57 | + <> |
| 58 | + <Rect |
| 59 | + x={66 + partWidth} |
| 60 | + y={22} |
| 61 | + width={longBarWidth} |
| 62 | + height={barHeight} |
| 63 | + /> |
| 64 | + <Rect |
| 65 | + x={66 + partWidth} |
| 66 | + y={36} |
| 67 | + width={shortBarWidth} |
| 68 | + height={barHeight} |
| 69 | + /> |
| 70 | + <Rect |
| 71 | + x={66 + partWidth * 2} |
| 72 | + y={22} |
| 73 | + width={longBarWidth} |
| 74 | + height={barHeight} |
| 75 | + /> |
| 76 | + <Rect |
| 77 | + x={66 + partWidth * 2} |
| 78 | + y={36} |
| 79 | + width={shortBarWidth} |
| 80 | + height={barHeight} |
| 81 | + /> |
| 82 | + </> |
| 83 | + )} |
| 84 | + </> |
| 85 | + )} |
| 86 | + /> |
| 87 | + ); |
| 88 | +} |
| 89 | +WorkspaceRowSkeleton.displayName = 'WorkspaceRowSkeleton'; |
| 90 | +export default WorkspaceRowSkeleton; |
0 commit comments