-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into @Skalakid/bump-react-native-live-markdown
- Loading branch information
Showing
31 changed files
with
578 additions
and
87 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
102 changes: 102 additions & 0 deletions
102
assets/images/simple-illustrations/simple-illustration__empty-state.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,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; | ||
|
||
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; |
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,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}; |
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
Oops, something went wrong.