Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty State Component for Search #44137

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
f0ba486
Empty State Component for Search
filip-solecki Jun 20, 2024
a995861
Remove backgroundColor
filip-solecki Jun 21, 2024
9f3a62c
Animation case
filip-solecki Jun 24, 2024
01333bc
Add animation and implement on Search page
filip-solecki Jun 24, 2024
d1ad016
Merge branch 'main' into filip-solecki/empty-state-component
filip-solecki Jun 25, 2024
9c09664
Small fixes on search empty page, add new empty component on tags and…
filip-solecki Jun 25, 2024
87c69fa
Small fixes
filip-solecki Jun 25, 2024
a19228a
remove unnecessary expensicon
filip-solecki Jun 25, 2024
094a373
Adjust to final design
filip-solecki Jun 25, 2024
31f04c7
Fix video styling
filip-solecki Jun 25, 2024
77fc807
remove unnecessary styles
filip-solecki Jun 25, 2024
0b8b124
self review fixes
filip-solecki Jun 25, 2024
a4bbb64
Add height for illustrations
filip-solecki Jun 25, 2024
ed66059
Fix lint
filip-solecki Jun 25, 2024
2676725
Use RN StyleSheet flatten function
filip-solecki Jun 25, 2024
774345b
cr fixes
filip-solecki Jun 25, 2024
4ee0ab8
Remove redundant margin
filip-solecki Jun 25, 2024
d29b846
Add displayName
filip-solecki Jun 26, 2024
4e54f88
Add double negation for checks
filip-solecki Jun 26, 2024
df19d03
remove empty line
filip-solecki Jun 26, 2024
0526ef3
Merge branch 'main' into filip-solecki/empty-state-component
filip-solecki Jun 26, 2024
370310a
rename to gradientOpacityEnabled
filip-solecki Jun 26, 2024
a0244ab
Remove redundant empty lines
filip-solecki Jun 26, 2024
5d75244
Move headerMediaType values to CONST
filip-solecki Jun 26, 2024
8e0b43f
Fix lint
filip-solecki Jun 26, 2024
8a9748d
Adjust Search desktop skeleton
filip-solecki Jun 26, 2024
2257f30
Merge branch 'main' into filip-solecki/empty-state-component
filip-solecki Jul 2, 2024
54e6dd4
Fix overflowing modal
filip-solecki Jul 3, 2024
e5bab71
Merge branch 'main' into filip-solecki/empty-state-component
filip-solecki Jul 3, 2024
3651cb1
Merge branch 'main' into filip-solecki/empty-state-component
filip-solecki Jul 4, 2024
3ddfee2
Merge branch 'main' into filip-solecki/empty-state-component
filip-solecki Jul 9, 2024
9e0f407
Remove unnecessary empty string
filip-solecki Jul 9, 2024
e89aeb8
Move calcuations values to consts
filip-solecki Jul 9, 2024
742e197
Merge branch 'main' into filip-solecki/empty-state-component
filip-solecki Jul 10, 2024
f52dfd6
Fix styling
filip-solecki Jul 10, 2024
5ffc2bc
Fix skeleton styling
filip-solecki Jul 10, 2024
9a5c4b5
Fix padding for empty state modal
filip-solecki Jul 10, 2024
544bb4c
Use variables for LHP width calculations
filip-solecki Jul 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5250,6 +5250,13 @@ const CONST = {
},

EXCLUDE_FROM_LAST_VISITED_PATH: [SCREENS.NOT_FOUND, SCREENS.SAML_SIGN_IN, SCREENS.VALIDATE_LOGIN] as string[],

EMPTY_STATE_MEDIA: {
ANIMATION: 'animation',
ILLUSTRATION: 'illustration',
VIDEO: 'video',
},

UPGRADE_FEATURE_INTRO_MAPPING: [
{
id: 'reportFields',
Expand All @@ -5260,6 +5267,7 @@ const CONST = {
icon: 'Pencil',
},
],

REPORT_FIELD_TYPES: {
TEXT: 'text',
DATE: 'date',
Expand Down
4 changes: 3 additions & 1 deletion src/components/AccountingListSkeletonView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import ItemListSkeletonView from './Skeletons/ItemListSkeletonView';

type AccountingListSkeletonViewProps = {
shouldAnimate?: boolean;
gradientOpacityEnabled?: boolean;
};

function AccountingListSkeletonView({shouldAnimate = true}: AccountingListSkeletonViewProps) {
function AccountingListSkeletonView({shouldAnimate = true, gradientOpacityEnabled = false}: AccountingListSkeletonViewProps) {
return (
<ItemListSkeletonView
shouldAnimate={shouldAnimate}
gradientOpacityEnabled={gradientOpacityEnabled}
renderSkeletonItem={() => (
<>
<Circle
Expand Down
100 changes: 100 additions & 0 deletions src/components/EmptyStateComponent/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import type {VideoReadyForDisplayEvent} from 'expo-av';
import React, {useMemo, useState} from 'react';
import {View} from 'react-native';
import Button from '@components/Button';
import ImageSVG from '@components/ImageSVG';
import Lottie from '@components/Lottie';
import ScrollView from '@components/ScrollView';
import Text from '@components/Text';
import VideoPlayer from '@components/VideoPlayer';
import useThemeStyles from '@hooks/useThemeStyles';
import useWindowDimensions from '@hooks/useWindowDimensions';
import CONST from '@src/CONST';
import type {EmptyStateComponentProps, VideoLoadedEventType} from './types';

const VIDEO_ASPECT_RATIO = 400 / 225;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure, but shouldn't it be included in CONSTs?

Will the aspect ratio always be the same?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may be different for each usage. Here it is adjusted to the "Modal" size

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be great to leave a comment about this, how did we get to this ratio?


function EmptyStateComponent({SkeletonComponent, headerMediaType, headerMedia, buttonText, buttonAction, title, subtitle, headerStyles, headerContentStyles}: EmptyStateComponentProps) {
const styles = useThemeStyles();
const {isSmallScreenWidth} = useWindowDimensions();
const [videoAspectRatio, setVideoAspectRatio] = useState(VIDEO_ASPECT_RATIO);

const setAspectRatio = (event: VideoReadyForDisplayEvent | VideoLoadedEventType | undefined) => {
if (!event) {
return;
}

if ('naturalSize' in event) {
setVideoAspectRatio(event.naturalSize.width / event.naturalSize.height);
} else {
setVideoAspectRatio(event.srcElement.videoWidth / event.srcElement.videoHeight);
}
};

const HeaderComponent = useMemo(() => {
switch (headerMediaType) {
case CONST.EMPTY_STATE_MEDIA.VIDEO:
return (
<VideoPlayer
url={headerMedia}
videoPlayerStyle={[headerContentStyles, {aspectRatio: videoAspectRatio}]}
videoStyle={styles.emptyStateVideo}
onVideoLoaded={setAspectRatio}
controlsStatus={CONST.VIDEO_PLAYER.CONTROLS_STATUS.SHOW}
shouldUseControlsBottomMargin={false}
shouldPlay
isLooping
/>
);
case CONST.EMPTY_STATE_MEDIA.ANIMATION:
return (
<Lottie
source={headerMedia}
autoPlay
loop
style={headerContentStyles}
/>
);
case CONST.EMPTY_STATE_MEDIA.ILLUSTRATION:
return (
<ImageSVG
style={headerContentStyles}
src={headerMedia}
/>
);
default:
return null;
}
}, [headerMedia, headerMediaType, headerContentStyles, videoAspectRatio, styles.emptyStateVideo]);

return (
<ScrollView contentContainerStyle={styles.emptyStateScrollView}>
<View style={styles.skeletonBackground}>
<SkeletonComponent
gradientOpacityEnabled
shouldAnimate={false}
/>
</View>
<View style={styles.emptyStateForeground(isSmallScreenWidth)}>
<View style={styles.emptyStateContent}>
<View style={[styles.emptyStateHeader(headerMediaType === CONST.EMPTY_STATE_MEDIA.ILLUSTRATION), headerStyles]}>{HeaderComponent}</View>
<View style={styles.p8}>
<Text style={[styles.textAlignCenter, styles.textHeadlineH1, styles.mb2]}>{title}</Text>
<Text style={[styles.textAlignCenter, styles.textSupporting, styles.textNormal]}>{subtitle}</Text>
{!!buttonText && !!buttonAction && (
<Button
success
onPress={buttonAction}
>
{buttonText}
</Button>
)}
</View>
</View>
</View>
</ScrollView>
);
}

EmptyStateComponent.displayName = 'EmptyStateComponent';
export default EmptyStateComponent;
filip-solecki marked this conversation as resolved.
Show resolved Hide resolved
41 changes: 41 additions & 0 deletions src/components/EmptyStateComponent/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import type {ImageStyle} from 'expo-image';
import type {StyleProp, ViewStyle} from 'react-native';
import type {ValueOf} from 'type-fest';
import type DotLottieAnimation from '@components/LottieAnimations/types';
import type SearchRowSkeleton from '@components/Skeletons/SearchRowSkeleton';
import type TableRowSkeleton from '@components/Skeletons/TableRowSkeleton';
import type CONST from '@src/CONST';
import type IconAsset from '@src/types/utils/IconAsset';

type ValidSkeletons = typeof SearchRowSkeleton | typeof TableRowSkeleton;
type MediaTypes = ValueOf<typeof CONST.EMPTY_STATE_MEDIA>;

type SharedProps<T> = {
SkeletonComponent: ValidSkeletons;
title: string;
subtitle: string;
buttonText?: string;
buttonAction?: () => void;
headerStyles?: StyleProp<ViewStyle>;
headerMediaType: T;
headerContentStyles?: StyleProp<ViewStyle & ImageStyle>;
};

type MediaType<HeaderMedia, T extends MediaTypes> = SharedProps<T> & {
headerMedia: HeaderMedia;
};

type VideoProps = MediaType<string, 'video'>;
type IllustrationProps = MediaType<IconAsset, 'illustration'>;
type AnimationProps = MediaType<DotLottieAnimation, 'animation'>;

type EmptyStateComponentProps = VideoProps | IllustrationProps | AnimationProps;

type VideoLoadedEventType = {
srcElement: {
videoWidth: number;
videoHeight: number;
};
};

export type {EmptyStateComponentProps, VideoLoadedEventType};
2 changes: 2 additions & 0 deletions src/components/Icon/Illustrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import ConciergeNew from '@assets/images/simple-illustrations/simple-illustratio
import CreditCardsNew from '@assets/images/simple-illustrations/simple-illustration__credit-cards.svg';
import CreditCardEyes from '@assets/images/simple-illustrations/simple-illustration__creditcardeyes.svg';
import EmailAddress from '@assets/images/simple-illustrations/simple-illustration__email-address.svg';
import EmptyState from '@assets/images/simple-illustrations/simple-illustration__empty-state.svg';
import FolderOpen from '@assets/images/simple-illustrations/simple-illustration__folder-open.svg';
import Gears from '@assets/images/simple-illustrations/simple-illustration__gears.svg';
import HandCard from '@assets/images/simple-illustrations/simple-illustration__handcard.svg';
Expand Down Expand Up @@ -198,6 +199,7 @@ export {
CheckmarkCircle,
CreditCardEyes,
LockClosedOrange,
EmptyState,
FolderWithPapers,
VirtualCard,
};
4 changes: 3 additions & 1 deletion src/components/OptionsListSkeletonView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,18 @@ function getLinedWidth(index: number): string {

type OptionsListSkeletonViewProps = {
shouldAnimate?: boolean;
gradientOpacityEnabled?: boolean;
shouldStyleAsTable?: boolean;
};

function OptionsListSkeletonView({shouldAnimate = true, shouldStyleAsTable = false}: OptionsListSkeletonViewProps) {
function OptionsListSkeletonView({shouldAnimate = true, shouldStyleAsTable = false, gradientOpacityEnabled = false}: OptionsListSkeletonViewProps) {
const styles = useThemeStyles();

return (
<ItemListSkeletonView
shouldAnimate={shouldAnimate}
itemViewStyle={shouldStyleAsTable && [styles.highlightBG, styles.mb3, styles.mh5, styles.br2]}
gradientOpacityEnabled={gradientOpacityEnabled}
renderSkeletonItem={({itemIndex}) => {
const lineWidth = getLinedWidth(itemIndex);

Expand Down
6 changes: 3 additions & 3 deletions src/components/Search/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type {OnyxEntry} from 'react-native-onyx';
import {useOnyx} from 'react-native-onyx';
import SearchTableHeader from '@components/SelectionList/SearchTableHeader';
import type {ReportListItemType, TransactionListItemType} from '@components/SelectionList/types';
import TableListItemSkeleton from '@components/Skeletons/TableListItemSkeleton';
import SearchRowSkeleton from '@components/Skeletons/SearchRowSkeleton';
import useNetwork from '@hooks/useNetwork';
import useThemeStyles from '@hooks/useThemeStyles';
import useWindowDimensions from '@hooks/useWindowDimensions';
Expand Down Expand Up @@ -101,7 +101,7 @@ function Search({query, policyIDs, sortBy, sortOrder}: SearchProps) {
query={query}
hash={hash}
/>
<TableListItemSkeleton shouldAnimate />
<SearchRowSkeleton shouldAnimate />
</>
);
}
Expand Down Expand Up @@ -207,7 +207,7 @@ function Search({query, policyIDs, sortBy, sortOrder}: SearchProps) {
onEndReached={fetchMoreResults}
listFooterContent={
isLoadingMoreItems ? (
<TableListItemSkeleton
<SearchRowSkeleton
shouldAnimate
fixedNumItems={5}
/>
Expand Down
Loading
Loading