forked from Expensify/App
-
Notifications
You must be signed in to change notification settings - Fork 0
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
[Wave9] Welcome Video as separate Screen #73
Merged
Merged
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
ddd6c4e
add base welcome video modal
cdOut 14f867b
remove symbol and fix light mode
cdOut 27158b9
fix styling for smaller displays
cdOut 063d0d3
fix backdrop for native
cdOut 8e27d62
add video player element with correct styling
cdOut 7971274
add offline support for switching between animation and video
cdOut f94bc11
add isLooping attrib
cdOut 2a27a6b
add spanish translations
cdOut bb7baa9
Merge remote-tracking branch 'origin/main' into @cdOut/welcome-video
cdOut 75a2b35
add fixes and updates for video player
cdOut 0659d56
Merge branch 'wave9/onboarding-flow' into @cdOut/welcome-video
MaciejSWM 39ed308
Drop -Modal suffix from name
MaciejSWM 1543ce0
Welcome video as separate screen
MaciejSWM 7f6194c
Add texts; desktop vs mobile styles
MaciejSWM 58e1fb2
Drop useless array
MaciejSWM e218e36
Merge branch 'wave9/onboarding-flow' into wave9/welcome-video-cdOut
MaciejSWM 0725435
Fix translation key conflict
MaciejSWM 018654e
Fix video aspect ratio mobile+desktop
MaciejSWM 9e9a5ec
Root route for onboarding
MaciejSWM b956dae
Set max height
MaciejSWM 900527c
Rename methods; clean code
MaciejSWM e703a14
New navigator - WelcomeVideoNavigator
MaciejSWM c1d6c96
Drop cardStyle
MaciejSWM b886fea
Video layout improvements
MaciejSWM 671d923
Separate styles for welcome video navigator
MaciejSWM 76961f8
Rewrite to use Modal
MaciejSWM 3bba5f1
Web styling for modal
MaciejSWM bb2e9b8
Drop unnecessary styles
MaciejSWM b43027a
Apply modal dimensions
MaciejSWM 8795e1c
Move stack declarations down
MaciejSWM 1297a40
Drop default path
MaciejSWM 80bafbc
Pixel perfect styles - native and web
MaciejSWM File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,161 @@ | ||
import type {VideoReadyForDisplayEvent} from 'expo-av'; | ||
import React, {useCallback, useEffect, useRef, useState} from 'react'; | ||
import type {LayoutChangeEvent, LayoutRectangle} from 'react-native'; | ||
import {View} from 'react-native'; | ||
import useLocalize from '@hooks/useLocalize'; | ||
import useNetwork from '@hooks/useNetwork'; | ||
import useOnboardingLayout from '@hooks/useOnboardingLayout'; | ||
import useThemeStyles from '@hooks/useThemeStyles'; | ||
import useWindowDimensions from '@hooks/useWindowDimensions'; | ||
import Navigation from '@libs/Navigation/Navigation'; | ||
import variables from '@styles/variables'; | ||
import CONST from '@src/CONST'; | ||
import Button from './Button'; | ||
import Lottie from './Lottie'; | ||
import LottieAnimations from './LottieAnimations'; | ||
import Modal from './Modal'; | ||
import Text from './Text'; | ||
import VideoPlayer from './VideoPlayer'; | ||
|
||
// Aspect ratio and height of the video. | ||
// Useful before video loads to reserve space. | ||
const VIDEO_ASPECT_RATIO = 484 / 272.25; | ||
const VIDEO_HEIGHT = 320; | ||
|
||
const MODAL_PADDING = variables.spacing2; | ||
|
||
type VideoLoadedEventType = { | ||
srcElement: { | ||
videoWidth: number; | ||
videoHeight: number; | ||
}; | ||
}; | ||
|
||
type VideoPlaybackStatusEventType = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here the same |
||
isLoaded: boolean; | ||
}; | ||
|
||
type VideoStatus = 'video' | 'animation'; | ||
|
||
function OnboardingWelcomeVideo() { | ||
const {translate} = useLocalize(); | ||
const styles = useThemeStyles(); | ||
const containerDimensions = useRef<LayoutRectangle>({width: 0, height: 0, x: 0, y: 0}); | ||
const [isModalVisible, setIsModalVisible] = useState(true); | ||
const {isSmallScreenWidth} = useWindowDimensions(); | ||
const {shouldUseNarrowLayout} = useOnboardingLayout(); | ||
const [welcomeVideoStatus, setWelcomeVideoStatus] = useState<VideoStatus>('video'); | ||
const [isWelcomeVideoStatusLocked, setIsWelcomeVideoStatusLocked] = useState(false); | ||
const [isVideoLoaded, setIsVideoLoaded] = useState(false); | ||
const [videoAspectRatio, setVideoAspectRatio] = useState(VIDEO_ASPECT_RATIO); | ||
const {isOffline} = useNetwork(); | ||
|
||
useEffect(() => { | ||
if (isWelcomeVideoStatusLocked) { | ||
return; | ||
} | ||
|
||
if (isOffline) { | ||
setWelcomeVideoStatus('animation'); | ||
setIsWelcomeVideoStatusLocked(true); | ||
} else if (!isOffline && isVideoLoaded) { | ||
setWelcomeVideoStatus('video'); | ||
setIsWelcomeVideoStatusLocked(true); | ||
} | ||
}, [isOffline, isVideoLoaded, isWelcomeVideoStatusLocked]); | ||
|
||
const storeContainerDimensions = (event: LayoutChangeEvent) => { | ||
containerDimensions.current = event.nativeEvent.layout; | ||
}; | ||
|
||
const closeModal = useCallback(() => { | ||
setIsModalVisible(false); | ||
Navigation.goBack(); | ||
}, []); | ||
|
||
const setAspectRatio = (e: VideoReadyForDisplayEvent | VideoLoadedEventType | undefined) => { | ||
if (!e) { | ||
return; | ||
} | ||
|
||
// TODO: Figure out why on mobile there's e.naturalSize and on web it's e.srcElement | ||
if ('naturalSize' in e) { | ||
setVideoAspectRatio(e.naturalSize.width / e.naturalSize.height); | ||
} else { | ||
setVideoAspectRatio(e.srcElement.videoWidth / e.srcElement.videoHeight); | ||
} | ||
}; | ||
|
||
const setVideoStatus = (e: VideoPlaybackStatusEventType) => { | ||
setIsVideoLoaded(e.isLoaded); | ||
}; | ||
|
||
const getWelcomeVideo = () => { | ||
if (welcomeVideoStatus === 'video') { | ||
const videoWidth = containerDimensions.current.width - 2 * MODAL_PADDING; | ||
|
||
return ( | ||
<View | ||
style={[ | ||
// Prevent layout jumps by reserving height for the video | ||
{height: VIDEO_HEIGHT - 2 * MODAL_PADDING}, | ||
]} | ||
> | ||
<VideoPlayer | ||
// Temporary file supplied for testing purposes, to | ||
// be changed when correct one gets uploaded on backend | ||
url="https://d23dyxeqlo5psv.cloudfront.net/big_buck_bunny.mp4" | ||
videoPlayerStyle={[styles.onboardingVideoPlayer, {width: videoWidth, height: videoWidth / videoAspectRatio}]} | ||
onVideoLoaded={setAspectRatio} | ||
onPlaybackStatusUpdate={setVideoStatus} | ||
shouldShowProgressVolumeOnly | ||
shouldPlay | ||
isLooping | ||
/> | ||
</View> | ||
); | ||
} | ||
|
||
return ( | ||
<Lottie | ||
source={LottieAnimations.Hands} | ||
style={styles.w100} | ||
webStyle={isSmallScreenWidth ? styles.h100 : styles.w100} | ||
autoPlay | ||
loop | ||
/> | ||
); | ||
}; | ||
|
||
return ( | ||
<Modal | ||
isVisible={isModalVisible} | ||
type={shouldUseNarrowLayout ? CONST.MODAL.MODAL_TYPE.CENTERED_SMALL : CONST.MODAL.MODAL_TYPE.BOTTOM_DOCKED} | ||
onClose={closeModal} | ||
innerContainerStyle={shouldUseNarrowLayout ? {} : {paddingTop: MODAL_PADDING, paddingBottom: MODAL_PADDING}} | ||
> | ||
<View | ||
style={[shouldUseNarrowLayout ? {width: 500, height: 500} : {}, {maxHeight: '100%'}]} | ||
onLayout={storeContainerDimensions} | ||
> | ||
<View style={shouldUseNarrowLayout ? {padding: MODAL_PADDING} : {paddingHorizontal: MODAL_PADDING}}>{getWelcomeVideo()}</View> | ||
<View style={[shouldUseNarrowLayout ? [styles.mt5, styles.mh8] : [styles.mt3, styles.mh5]]}> | ||
<View style={[shouldUseNarrowLayout ? [styles.gap1, styles.mb8] : [styles.gap2, styles.mb10]]}> | ||
<Text style={styles.textHeroSmall}>{translate('onboarding.welcomeVideo.title')}</Text> | ||
<Text style={styles.textSupporting}>{translate('onboarding.welcomeVideo.description')}</Text> | ||
</View> | ||
<Button | ||
success | ||
pressOnEnter | ||
onPress={closeModal} | ||
text={translate('onboarding.welcomeVideo.button')} | ||
/> | ||
</View> | ||
</View> | ||
</Modal> | ||
); | ||
} | ||
|
||
OnboardingWelcomeVideo.displayName = 'OnboardingWelcomeVideo'; | ||
|
||
export default OnboardingWelcomeVideo; |
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's not use
Type
suffix for types if it's not absolutely necessary 😄