-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40682 from software-mansion-labs/kicu/search-v1/s…
…earch-skeleton [Search v1] Add empty search List skeleton
- Loading branch information
Showing
6 changed files
with
177 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import React, {useMemo, useState} from 'react'; | ||
import {View} from 'react-native'; | ||
import SkeletonViewContentLoader from '@components/SkeletonViewContentLoader'; | ||
import useTheme from '@hooks/useTheme'; | ||
import useThemeStyles from '@hooks/useThemeStyles'; | ||
import CONST from '@src/CONST'; | ||
|
||
type ListItemSkeletonProps = { | ||
shouldAnimate?: boolean; | ||
renderSkeletonItem: (args: {itemIndex: number}) => React.ReactNode; | ||
}; | ||
|
||
function ItemListSkeletonView({shouldAnimate = true, renderSkeletonItem}: ListItemSkeletonProps) { | ||
const theme = useTheme(); | ||
const themeStyles = useThemeStyles(); | ||
|
||
const [numItems, setNumItems] = useState(0); | ||
const skeletonViewItems = useMemo(() => { | ||
const items = []; | ||
for (let i = 0; i < numItems; i++) { | ||
items.push( | ||
<SkeletonViewContentLoader | ||
key={`skeletonViewItems${i}`} | ||
animate={shouldAnimate} | ||
height={CONST.LHN_SKELETON_VIEW_ITEM_HEIGHT} | ||
backgroundColor={theme.skeletonLHNIn} | ||
foregroundColor={theme.skeletonLHNOut} | ||
style={themeStyles.mr5} | ||
> | ||
{renderSkeletonItem({itemIndex: i})} | ||
</SkeletonViewContentLoader>, | ||
); | ||
} | ||
return items; | ||
}, [numItems, shouldAnimate, theme, themeStyles, renderSkeletonItem]); | ||
|
||
return ( | ||
<View | ||
style={[themeStyles.flex1, themeStyles.overflowHidden]} | ||
onLayout={(event) => { | ||
const newNumItems = Math.ceil(event.nativeEvent.layout.height / CONST.LHN_SKELETON_VIEW_ITEM_HEIGHT); | ||
if (newNumItems === numItems) { | ||
return; | ||
} | ||
setNumItems(newNumItems); | ||
}} | ||
> | ||
<View>{skeletonViewItems}</View> | ||
</View> | ||
); | ||
} | ||
|
||
ItemListSkeletonView.displayName = 'ListItemSkeleton'; | ||
|
||
export default ItemListSkeletonView; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import React from 'react'; | ||
import {Rect} from 'react-native-svg'; | ||
import ItemListSkeletonView from './ItemListSkeletonView'; | ||
|
||
type TableListItemSkeletonProps = { | ||
shouldAnimate?: boolean; | ||
}; | ||
|
||
const barHeight = '10'; | ||
const shortBarWidth = '40'; | ||
const longBarWidth = '120'; | ||
|
||
function TableListItemSkeleton({shouldAnimate = true}: TableListItemSkeletonProps) { | ||
return ( | ||
<ItemListSkeletonView | ||
shouldAnimate={shouldAnimate} | ||
renderSkeletonItem={() => ( | ||
<> | ||
<Rect | ||
x="20" | ||
y="10" | ||
rx="5" | ||
ry="5" | ||
width="40" | ||
height="40" | ||
/> | ||
<Rect | ||
x="80" | ||
y="25" | ||
width={shortBarWidth} | ||
height={barHeight} | ||
/> | ||
<Rect | ||
x="150" | ||
y="25" | ||
width={longBarWidth} | ||
height={barHeight} | ||
/> | ||
<Rect | ||
x="320" | ||
y="25" | ||
width={longBarWidth} | ||
height={barHeight} | ||
/> | ||
<Rect | ||
x="480" | ||
y="25" | ||
width={longBarWidth} | ||
height={barHeight} | ||
/> | ||
<Rect | ||
x="660" | ||
y="25" | ||
width="100%" | ||
height={barHeight} | ||
/> | ||
</> | ||
)} | ||
/> | ||
); | ||
} | ||
|
||
TableListItemSkeleton.displayName = 'TableListItemSkeleton'; | ||
|
||
export default TableListItemSkeleton; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import React from 'react'; | ||
import TableListItemSkeleton from '@components/Skeletons/TableListItemSkeleton'; | ||
|
||
function EmptySearchView() { | ||
return <TableListItemSkeleton shouldAnimate />; | ||
} | ||
|
||
EmptySearchView.displayName = 'EmptySearchView'; | ||
|
||
export default EmptySearchView; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters