Skip to content

Commit

Permalink
Merge pull request Expensify#29975 from software-mansion-labs/@kosmyd…
Browse files Browse the repository at this point in the history
…el/lottie-react-native-web-support
  • Loading branch information
roryabraham authored Nov 9, 2023
2 parents dee9b31 + 6c52316 commit 5a94095
Show file tree
Hide file tree
Showing 45 changed files with 138 additions and 59 deletions.
1 change: 1 addition & 0 deletions __mocks__/fileMock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = 'test-file-stub';
1 change: 0 additions & 1 deletion assets/animations/ExpensifyLounge.json

This file was deleted.

Binary file added assets/animations/ExpensifyLounge.lottie
Binary file not shown.
1 change: 0 additions & 1 deletion assets/animations/FastMoney.json

This file was deleted.

Binary file added assets/animations/FastMoney.lottie
Binary file not shown.
1 change: 0 additions & 1 deletion assets/animations/Fireworks.json

This file was deleted.

Binary file added assets/animations/Fireworks.lottie
Binary file not shown.
1 change: 0 additions & 1 deletion assets/animations/Hands.json

This file was deleted.

Binary file added assets/animations/Hands.lottie
Binary file not shown.
1 change: 0 additions & 1 deletion assets/animations/Magician.json

This file was deleted.

Binary file added assets/animations/Magician.lottie
Binary file not shown.
1 change: 0 additions & 1 deletion assets/animations/PreferencesDJ.json

This file was deleted.

Binary file added assets/animations/PreferencesDJ.lottie
Binary file not shown.
1 change: 0 additions & 1 deletion assets/animations/ReviewingBankInfo.json

This file was deleted.

Binary file added assets/animations/ReviewingBankInfo.lottie
Binary file not shown.
1 change: 0 additions & 1 deletion assets/animations/Safe.json

This file was deleted.

Binary file added assets/animations/Safe.lottie
Binary file not shown.
1 change: 0 additions & 1 deletion assets/animations/SaveTheWorld.json

This file was deleted.

Binary file added assets/animations/SaveTheWorld.lottie
Binary file not shown.
1 change: 0 additions & 1 deletion assets/animations/WorkspacePlanet.json

This file was deleted.

Binary file added assets/animations/WorkspacePlanet.lottie
Binary file not shown.
4 changes: 4 additions & 0 deletions config/webpack/webpack.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,10 @@ const webpackConfig = ({envFile = '.env', platform = 'web'}) => ({
resourceQuery: /raw/,
type: 'asset/source',
},
{
test: /\.lottie$/,
type: 'asset/resource',
},
],
},
resolve: {
Expand Down
3 changes: 3 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,7 @@ module.exports = {
setupFiles: ['<rootDir>/jest/setup.js', './node_modules/@react-native-google-signin/google-signin/jest/build/setup.js'],
setupFilesAfterEnv: ['@testing-library/jest-native/extend-expect', '<rootDir>/jest/setupAfterEnv.js'],
cacheDirectory: '<rootDir>/.jest-cache',
moduleNameMapper: {
'\\.(lottie)$': '<rootDir>/__mocks__/fileMock.js',
},
};
2 changes: 1 addition & 1 deletion metro.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const e2eSourceExts = ['e2e.js', 'e2e.ts'];
*/
const config = {
resolver: {
assetExts: _.filter(defaultAssetExts, (ext) => ext !== 'svg'),
assetExts: [..._.filter(defaultAssetExts, (ext) => ext !== 'svg'), 'lottie'],
// When we run the e2e tests we want files that have the extension e2e.js to be resolved as source files
sourceExts: [...(isE2ETesting ? e2eSourceExts : []), ...defaultSourceExts, 'jsx', 'svg'],
resolveRequest: (context, moduleName, platform) => {
Expand Down
13 changes: 10 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@
"@invertase/react-native-apple-authentication": "^2.2.2",
"@kie/act-js": "^2.0.1",
"@kie/mock-github": "^1.0.0",
"@lottiefiles/react-lottie-player": "^3.5.3",
"@oguzhnatly/react-native-image-manipulator": "github:Expensify/react-native-image-manipulator#5cdae3d4455b03a04c57f50be3863e2fe6c92c52",
"@onfido/react-native-sdk": "8.3.0",
"@react-native-async-storage/async-storage": "^1.17.10",
Expand Down
2 changes: 1 addition & 1 deletion src/components/ConfirmationPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import styles from '@styles/styles';
import Button from './Button';
import FixedFooter from './FixedFooter';
import Lottie from './Lottie';
import * as LottieAnimations from './LottieAnimations';
import LottieAnimations from './LottieAnimations';
import Text from './Text';

const propTypes = {
Expand Down
45 changes: 31 additions & 14 deletions src/components/Lottie/Lottie.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,39 @@
import LottieView, {LottieViewProps} from 'lottie-react-native';
import React, {forwardRef} from 'react';
import React, {ForwardedRef, forwardRef} from 'react';
import {View} from 'react-native';
import DotLottieAnimation from '@components/LottieAnimations/types';
import useNetwork from '@hooks/useNetwork';
import styles from '@styles/styles';

const Lottie = forwardRef<LottieView, LottieViewProps>((props: LottieViewProps, ref) => {
const aspectRatioStyle = styles.aspectRatioLottie(props.source);
type Props = {
source: DotLottieAnimation;
} & Omit<LottieViewProps, 'source'>;

function Lottie({source, webStyle, ...props}: Props, ref: ForwardedRef<LottieView>) {
const [isError, setIsError] = React.useState(false);

useNetwork({onReconnect: () => setIsError(false)});

const aspectRatioStyle = styles.aspectRatioLottie(source);

// If the image fails to load, we'll just render an empty view
if (isError) {
return <View style={aspectRatioStyle} />;
}

return (
<View style={[aspectRatioStyle, styles.w100]}>
<LottieView
// eslint-disable-next-line
{...props}
ref={ref}
style={[aspectRatioStyle, props.style]}
webStyle={{...aspectRatioStyle, ...props.webStyle}}
/>
</View>
<LottieView
// eslint-disable-next-line react/jsx-props-no-spreading
{...props}
source={source.file}
ref={ref}
style={[aspectRatioStyle, props.style]}
webStyle={{...aspectRatioStyle, ...webStyle}}
onAnimationFailure={() => setIsError(true)}
/>
);
});
}

Lottie.displayName = 'Lottie';

export default Lottie;
export default forwardRef(Lottie);
12 changes: 0 additions & 12 deletions src/components/LottieAnimations.ts

This file was deleted.

56 changes: 56 additions & 0 deletions src/components/LottieAnimations/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import DotLottieAnimation from './types';

const DotLottieAnimations: Record<string, DotLottieAnimation> = {
ExpensifyLounge: {
file: require('@assets/animations/ExpensifyLounge.lottie'),
w: 1920,
h: 1080,
},
FastMoney: {
file: require('@assets/animations/FastMoney.lottie'),
w: 375,
h: 240,
},
Fireworks: {
file: require('@assets/animations/Fireworks.lottie'),
w: 360,
h: 360,
},
Hands: {
file: require('@assets/animations/Hands.lottie'),
w: 375,
h: 375,
},
PreferencesDJ: {
file: require('@assets/animations/PreferencesDJ.lottie'),
w: 375,
h: 240,
},
ReviewingBankInfo: {
file: require('@assets/animations/ReviewingBankInfo.lottie'),
w: 280,
h: 280,
},
WorkspacePlanet: {
file: require('@assets/animations/WorkspacePlanet.lottie'),
w: 375,
h: 240,
},
SaveTheWorld: {
file: require('@assets/animations/SaveTheWorld.lottie'),
w: 375,
h: 240,
},
Safe: {
file: require('@assets/animations/Safe.lottie'),
w: 625,
h: 400,
},
Magician: {
file: require('@assets/animations/Magician.lottie'),
w: 853,
h: 480,
},
};

export default DotLottieAnimations;
9 changes: 9 additions & 0 deletions src/components/LottieAnimations/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import {LottieViewProps} from 'lottie-react-native';

type DotLottieAnimation = {
file: LottieViewProps['source'];
w: number;
h: number;
};

export default DotLottieAnimation;
2 changes: 1 addition & 1 deletion src/components/ReimbursementAccountLoadingIndicator.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import FullPageOfflineBlockingView from './BlockingViews/FullPageOfflineBlocking
import FullScreenLoadingIndicator from './FullscreenLoadingIndicator';
import HeaderWithBackButton from './HeaderWithBackButton';
import Lottie from './Lottie';
import * as LottieAnimations from './LottieAnimations';
import LottieAnimations from './LottieAnimations';
import ScreenWrapper from './ScreenWrapper';
import Text from './Text';

Expand Down
2 changes: 1 addition & 1 deletion src/pages/EnablePayments/ActivateStep.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {withOnyx} from 'react-native-onyx';
import _ from 'underscore';
import ConfirmationPage from '@components/ConfirmationPage';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
import * as LottieAnimations from '@components/LottieAnimations';
import LottieAnimations from '@components/LottieAnimations';
import withLocalize, {withLocalizePropTypes} from '@components/withLocalize';
import compose from '@libs/compose';
import * as PaymentMethods from '@userActions/PaymentMethods';
Expand Down
2 changes: 1 addition & 1 deletion src/pages/TeachersUnite/SaveTheWorldPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import React from 'react';
import {View} from 'react-native';
import {withOnyx} from 'react-native-onyx';
import IllustratedHeaderPageLayout from '@components/IllustratedHeaderPageLayout';
import * as LottieAnimations from '@components/LottieAnimations';
import LottieAnimations from '@components/LottieAnimations';
import MenuItem from '@components/MenuItem';
import Text from '@components/Text';
import useLocalize from '@hooks/useLocalize';
Expand Down
2 changes: 1 addition & 1 deletion src/pages/settings/Preferences/PreferencesPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import React from 'react';
import {View} from 'react-native';
import {withOnyx} from 'react-native-onyx';
import IllustratedHeaderPageLayout from '@components/IllustratedHeaderPageLayout';
import * as LottieAnimations from '@components/LottieAnimations';
import LottieAnimations from '@components/LottieAnimations';
import MenuItemWithTopDescription from '@components/MenuItemWithTopDescription';
import Switch from '@components/Switch';
import TestToolMenu from '@components/TestToolMenu';
Expand Down
2 changes: 1 addition & 1 deletion src/pages/settings/Profile/LoungeAccessPage.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import {withOnyx} from 'react-native-onyx';
import IllustratedHeaderPageLayout from '@components/IllustratedHeaderPageLayout';
import * as LottieAnimations from '@components/LottieAnimations';
import LottieAnimations from '@components/LottieAnimations';
import Text from '@components/Text';
import withCurrentUserPersonalDetails, {withCurrentUserPersonalDetailsDefaultProps, withCurrentUserPersonalDetailsPropTypes} from '@components/withCurrentUserPersonalDetails';
import useLocalize from '@hooks/useLocalize';
Expand Down
2 changes: 1 addition & 1 deletion src/pages/settings/Security/SecuritySettingsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {withOnyx} from 'react-native-onyx';
import _ from 'underscore';
import * as Expensicons from '@components/Icon/Expensicons';
import IllustratedHeaderPageLayout from '@components/IllustratedHeaderPageLayout';
import * as LottieAnimations from '@components/LottieAnimations';
import LottieAnimations from '@components/LottieAnimations';
import MenuItemList from '@components/MenuItemList';
import withLocalize, {withLocalizePropTypes} from '@components/withLocalize';
import useWaitForNavigation from '@hooks/useWaitForNavigation';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import ConfirmationPage from '@components/ConfirmationPage';
import * as LottieAnimations from '@components/LottieAnimations';
import LottieAnimations from '@components/LottieAnimations';
import useLocalize from '@hooks/useLocalize';
import StepWrapper from '@pages/settings/Security/TwoFactorAuth/StepWrapper/StepWrapper';
import useTwoFactorAuthContext from '@pages/settings/Security/TwoFactorAuth/TwoFactorAuthContext/useTwoFactorAuth';
Expand Down
2 changes: 1 addition & 1 deletion src/pages/settings/Wallet/ActivatePhysicalCardPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import _ from 'underscore';
import BigNumberPad from '@components/BigNumberPad';
import Button from '@components/Button';
import IllustratedHeaderPageLayout from '@components/IllustratedHeaderPageLayout';
import * as LottieAnimations from '@components/LottieAnimations';
import LottieAnimations from '@components/LottieAnimations';
import MagicCodeInput from '@components/MagicCodeInput';
import Text from '@components/Text';
import useLocalize from '@hooks/useLocalize';
Expand Down
2 changes: 1 addition & 1 deletion src/pages/settings/Wallet/WalletEmptyState.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Button from '@components/Button';
import FeatureList from '@components/FeatureList';
import * as Illustrations from '@components/Icon/Illustrations';
import IllustratedHeaderPageLayout from '@components/IllustratedHeaderPageLayout';
import * as LottieAnimations from '@components/LottieAnimations';
import LottieAnimations from '@components/LottieAnimations';
import useLocalize from '@hooks/useLocalize';
import Navigation from '@libs/Navigation/Navigation';
import themeColors from '@styles/themes/default';
Expand Down
2 changes: 1 addition & 1 deletion src/pages/signin/SignInHeroImage.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import Lottie from '@components/Lottie';
import * as LottieAnimations from '@components/LottieAnimations';
import LottieAnimations from '@components/LottieAnimations';
import withWindowDimensions, {windowDimensionsPropTypes} from '@components/withWindowDimensions';
import styles from '@styles/styles';
import variables from '@styles/variables';
Expand Down
2 changes: 1 addition & 1 deletion src/pages/workspace/WorkspacesListPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import FeatureList from '@components/FeatureList';
import * as Expensicons from '@components/Icon/Expensicons';
import * as Illustrations from '@components/Icon/Illustrations';
import IllustratedHeaderPageLayout from '@components/IllustratedHeaderPageLayout';
import * as LottieAnimations from '@components/LottieAnimations';
import LottieAnimations from '@components/LottieAnimations';
import MenuItem from '@components/MenuItem';
import OfflineWithFeedback from '@components/OfflineWithFeedback';
import useLocalize from '@hooks/useLocalize';
Expand Down
8 changes: 2 additions & 6 deletions src/styles/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {AnimatableNumericValue, Animated, ImageStyle, TextStyle, ViewStyle} from
import {CustomAnimation} from 'react-native-animatable';
import {PickerStyle} from 'react-native-picker-select';
import {MixedStyleDeclaration, MixedStyleRecord} from 'react-native-render-html';
import DotLottieAnimation from '@components/LottieAnimations/types';
import * as Browser from '@libs/Browser';
import CONST from '@src/CONST';
import addOutlineWidth from './addOutlineWidth';
Expand Down Expand Up @@ -3976,12 +3977,7 @@ const styles = (theme: ThemeColors) =>
lineHeight: variables.lineHeightXLarge,
},

aspectRatioLottie: (source) => {
if (!source.uri && typeof source === 'object' && source.w && source.h) {
return {aspectRatio: source.w / source.h};
}
return {};
},
aspectRatioLottie: (animation: DotLottieAnimation) => ({aspectRatio: animation.w / animation.h, width: '100%'}),

receiptDropHeaderGap: {
backgroundColor: theme.receiptDropUIBG,
Expand Down
5 changes: 5 additions & 0 deletions src/types/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,9 @@ declare module '*.svg' {
export default content;
}

declare module '*.lottie' {
const value: import('lottie-react-native').LottieViewProps.source;
export default value;
}

declare module 'react-native-device-info/jest/react-native-device-info-mock';
4 changes: 4 additions & 0 deletions web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@
transition-duration: 250ms;
transition-property: opacity;
}

.animation {
display: flex;
}
</style>
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1, interactive-widget=resizes-content">
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
Expand Down

0 comments on commit 5a94095

Please sign in to comment.