Skip to content

Commit 5a94095

Browse files
authored
Merge pull request #29975 from software-mansion-labs/@kosmydel/lottie-react-native-web-support
2 parents dee9b31 + 6c52316 commit 5a94095

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+138
-59
lines changed

__mocks__/fileMock.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = 'test-file-stub';

assets/animations/ExpensifyLounge.json

-1
This file was deleted.
305 KB
Binary file not shown.

assets/animations/FastMoney.json

-1
This file was deleted.

assets/animations/FastMoney.lottie

32.5 KB
Binary file not shown.

assets/animations/Fireworks.json

-1
This file was deleted.

assets/animations/Fireworks.lottie

35.4 KB
Binary file not shown.

assets/animations/Hands.json

-1
This file was deleted.

assets/animations/Hands.lottie

61 KB
Binary file not shown.

assets/animations/Magician.json

-1
This file was deleted.

assets/animations/Magician.lottie

17.1 KB
Binary file not shown.

assets/animations/PreferencesDJ.json

-1
This file was deleted.
44.7 KB
Binary file not shown.

assets/animations/ReviewingBankInfo.json

-1
This file was deleted.
9.88 KB
Binary file not shown.

assets/animations/Safe.json

-1
This file was deleted.

assets/animations/Safe.lottie

27.1 KB
Binary file not shown.

assets/animations/SaveTheWorld.json

-1
This file was deleted.

assets/animations/SaveTheWorld.lottie

43.9 KB
Binary file not shown.

assets/animations/WorkspacePlanet.json

-1
This file was deleted.
40.5 KB
Binary file not shown.

config/webpack/webpack.common.js

+4
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,10 @@ const webpackConfig = ({envFile = '.env', platform = 'web'}) => ({
180180
resourceQuery: /raw/,
181181
type: 'asset/source',
182182
},
183+
{
184+
test: /\.lottie$/,
185+
type: 'asset/resource',
186+
},
183187
],
184188
},
185189
resolve: {

jest.config.js

+3
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,7 @@ module.exports = {
2626
setupFiles: ['<rootDir>/jest/setup.js', './node_modules/@react-native-google-signin/google-signin/jest/build/setup.js'],
2727
setupFilesAfterEnv: ['@testing-library/jest-native/extend-expect', '<rootDir>/jest/setupAfterEnv.js'],
2828
cacheDirectory: '<rootDir>/.jest-cache',
29+
moduleNameMapper: {
30+
'\\.(lottie)$': '<rootDir>/__mocks__/fileMock.js',
31+
},
2932
};

metro.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const e2eSourceExts = ['e2e.js', 'e2e.ts'];
2323
*/
2424
const config = {
2525
resolver: {
26-
assetExts: _.filter(defaultAssetExts, (ext) => ext !== 'svg'),
26+
assetExts: [..._.filter(defaultAssetExts, (ext) => ext !== 'svg'), 'lottie'],
2727
// When we run the e2e tests we want files that have the extension e2e.js to be resolved as source files
2828
sourceExts: [...(isE2ETesting ? e2eSourceExts : []), ...defaultSourceExts, 'jsx', 'svg'],
2929
resolveRequest: (context, moduleName, platform) => {

package-lock.json

+10-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@
7070
"@invertase/react-native-apple-authentication": "^2.2.2",
7171
"@kie/act-js": "^2.0.1",
7272
"@kie/mock-github": "^1.0.0",
73-
"@lottiefiles/react-lottie-player": "^3.5.3",
7473
"@oguzhnatly/react-native-image-manipulator": "github:Expensify/react-native-image-manipulator#5cdae3d4455b03a04c57f50be3863e2fe6c92c52",
7574
"@onfido/react-native-sdk": "8.3.0",
7675
"@react-native-async-storage/async-storage": "^1.17.10",

src/components/ConfirmationPage.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import styles from '@styles/styles';
55
import Button from './Button';
66
import FixedFooter from './FixedFooter';
77
import Lottie from './Lottie';
8-
import * as LottieAnimations from './LottieAnimations';
8+
import LottieAnimations from './LottieAnimations';
99
import Text from './Text';
1010

1111
const propTypes = {

src/components/Lottie/Lottie.tsx

+31-14
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,39 @@
11
import LottieView, {LottieViewProps} from 'lottie-react-native';
2-
import React, {forwardRef} from 'react';
2+
import React, {ForwardedRef, forwardRef} from 'react';
33
import {View} from 'react-native';
4+
import DotLottieAnimation from '@components/LottieAnimations/types';
5+
import useNetwork from '@hooks/useNetwork';
46
import styles from '@styles/styles';
57

6-
const Lottie = forwardRef<LottieView, LottieViewProps>((props: LottieViewProps, ref) => {
7-
const aspectRatioStyle = styles.aspectRatioLottie(props.source);
8+
type Props = {
9+
source: DotLottieAnimation;
10+
} & Omit<LottieViewProps, 'source'>;
11+
12+
function Lottie({source, webStyle, ...props}: Props, ref: ForwardedRef<LottieView>) {
13+
const [isError, setIsError] = React.useState(false);
14+
15+
useNetwork({onReconnect: () => setIsError(false)});
16+
17+
const aspectRatioStyle = styles.aspectRatioLottie(source);
18+
19+
// If the image fails to load, we'll just render an empty view
20+
if (isError) {
21+
return <View style={aspectRatioStyle} />;
22+
}
823

924
return (
10-
<View style={[aspectRatioStyle, styles.w100]}>
11-
<LottieView
12-
// eslint-disable-next-line
13-
{...props}
14-
ref={ref}
15-
style={[aspectRatioStyle, props.style]}
16-
webStyle={{...aspectRatioStyle, ...props.webStyle}}
17-
/>
18-
</View>
25+
<LottieView
26+
// eslint-disable-next-line react/jsx-props-no-spreading
27+
{...props}
28+
source={source.file}
29+
ref={ref}
30+
style={[aspectRatioStyle, props.style]}
31+
webStyle={{...aspectRatioStyle, ...webStyle}}
32+
onAnimationFailure={() => setIsError(true)}
33+
/>
1934
);
20-
});
35+
}
36+
37+
Lottie.displayName = 'Lottie';
2138

22-
export default Lottie;
39+
export default forwardRef(Lottie);

src/components/LottieAnimations.ts

-12
This file was deleted.
+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import DotLottieAnimation from './types';
2+
3+
const DotLottieAnimations: Record<string, DotLottieAnimation> = {
4+
ExpensifyLounge: {
5+
file: require('@assets/animations/ExpensifyLounge.lottie'),
6+
w: 1920,
7+
h: 1080,
8+
},
9+
FastMoney: {
10+
file: require('@assets/animations/FastMoney.lottie'),
11+
w: 375,
12+
h: 240,
13+
},
14+
Fireworks: {
15+
file: require('@assets/animations/Fireworks.lottie'),
16+
w: 360,
17+
h: 360,
18+
},
19+
Hands: {
20+
file: require('@assets/animations/Hands.lottie'),
21+
w: 375,
22+
h: 375,
23+
},
24+
PreferencesDJ: {
25+
file: require('@assets/animations/PreferencesDJ.lottie'),
26+
w: 375,
27+
h: 240,
28+
},
29+
ReviewingBankInfo: {
30+
file: require('@assets/animations/ReviewingBankInfo.lottie'),
31+
w: 280,
32+
h: 280,
33+
},
34+
WorkspacePlanet: {
35+
file: require('@assets/animations/WorkspacePlanet.lottie'),
36+
w: 375,
37+
h: 240,
38+
},
39+
SaveTheWorld: {
40+
file: require('@assets/animations/SaveTheWorld.lottie'),
41+
w: 375,
42+
h: 240,
43+
},
44+
Safe: {
45+
file: require('@assets/animations/Safe.lottie'),
46+
w: 625,
47+
h: 400,
48+
},
49+
Magician: {
50+
file: require('@assets/animations/Magician.lottie'),
51+
w: 853,
52+
h: 480,
53+
},
54+
};
55+
56+
export default DotLottieAnimations;
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import {LottieViewProps} from 'lottie-react-native';
2+
3+
type DotLottieAnimation = {
4+
file: LottieViewProps['source'];
5+
w: number;
6+
h: number;
7+
};
8+
9+
export default DotLottieAnimation;

src/components/ReimbursementAccountLoadingIndicator.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import FullPageOfflineBlockingView from './BlockingViews/FullPageOfflineBlocking
77
import FullScreenLoadingIndicator from './FullscreenLoadingIndicator';
88
import HeaderWithBackButton from './HeaderWithBackButton';
99
import Lottie from './Lottie';
10-
import * as LottieAnimations from './LottieAnimations';
10+
import LottieAnimations from './LottieAnimations';
1111
import ScreenWrapper from './ScreenWrapper';
1212
import Text from './Text';
1313

src/pages/EnablePayments/ActivateStep.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {withOnyx} from 'react-native-onyx';
33
import _ from 'underscore';
44
import ConfirmationPage from '@components/ConfirmationPage';
55
import HeaderWithBackButton from '@components/HeaderWithBackButton';
6-
import * as LottieAnimations from '@components/LottieAnimations';
6+
import LottieAnimations from '@components/LottieAnimations';
77
import withLocalize, {withLocalizePropTypes} from '@components/withLocalize';
88
import compose from '@libs/compose';
99
import * as PaymentMethods from '@userActions/PaymentMethods';

src/pages/TeachersUnite/SaveTheWorldPage.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import React from 'react';
44
import {View} from 'react-native';
55
import {withOnyx} from 'react-native-onyx';
66
import IllustratedHeaderPageLayout from '@components/IllustratedHeaderPageLayout';
7-
import * as LottieAnimations from '@components/LottieAnimations';
7+
import LottieAnimations from '@components/LottieAnimations';
88
import MenuItem from '@components/MenuItem';
99
import Text from '@components/Text';
1010
import useLocalize from '@hooks/useLocalize';

src/pages/settings/Preferences/PreferencesPage.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import React from 'react';
44
import {View} from 'react-native';
55
import {withOnyx} from 'react-native-onyx';
66
import IllustratedHeaderPageLayout from '@components/IllustratedHeaderPageLayout';
7-
import * as LottieAnimations from '@components/LottieAnimations';
7+
import LottieAnimations from '@components/LottieAnimations';
88
import MenuItemWithTopDescription from '@components/MenuItemWithTopDescription';
99
import Switch from '@components/Switch';
1010
import TestToolMenu from '@components/TestToolMenu';

src/pages/settings/Profile/LoungeAccessPage.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
import {withOnyx} from 'react-native-onyx';
33
import IllustratedHeaderPageLayout from '@components/IllustratedHeaderPageLayout';
4-
import * as LottieAnimations from '@components/LottieAnimations';
4+
import LottieAnimations from '@components/LottieAnimations';
55
import Text from '@components/Text';
66
import withCurrentUserPersonalDetails, {withCurrentUserPersonalDetailsDefaultProps, withCurrentUserPersonalDetailsPropTypes} from '@components/withCurrentUserPersonalDetails';
77
import useLocalize from '@hooks/useLocalize';

src/pages/settings/Security/SecuritySettingsPage.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {withOnyx} from 'react-native-onyx';
55
import _ from 'underscore';
66
import * as Expensicons from '@components/Icon/Expensicons';
77
import IllustratedHeaderPageLayout from '@components/IllustratedHeaderPageLayout';
8-
import * as LottieAnimations from '@components/LottieAnimations';
8+
import LottieAnimations from '@components/LottieAnimations';
99
import MenuItemList from '@components/MenuItemList';
1010
import withLocalize, {withLocalizePropTypes} from '@components/withLocalize';
1111
import useWaitForNavigation from '@hooks/useWaitForNavigation';

src/pages/settings/Security/TwoFactorAuth/Steps/SuccessStep.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import ConfirmationPage from '@components/ConfirmationPage';
3-
import * as LottieAnimations from '@components/LottieAnimations';
3+
import LottieAnimations from '@components/LottieAnimations';
44
import useLocalize from '@hooks/useLocalize';
55
import StepWrapper from '@pages/settings/Security/TwoFactorAuth/StepWrapper/StepWrapper';
66
import useTwoFactorAuthContext from '@pages/settings/Security/TwoFactorAuth/TwoFactorAuthContext/useTwoFactorAuth';

src/pages/settings/Wallet/ActivatePhysicalCardPage.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import _ from 'underscore';
77
import BigNumberPad from '@components/BigNumberPad';
88
import Button from '@components/Button';
99
import IllustratedHeaderPageLayout from '@components/IllustratedHeaderPageLayout';
10-
import * as LottieAnimations from '@components/LottieAnimations';
10+
import LottieAnimations from '@components/LottieAnimations';
1111
import MagicCodeInput from '@components/MagicCodeInput';
1212
import Text from '@components/Text';
1313
import useLocalize from '@hooks/useLocalize';

src/pages/settings/Wallet/WalletEmptyState.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import Button from '@components/Button';
44
import FeatureList from '@components/FeatureList';
55
import * as Illustrations from '@components/Icon/Illustrations';
66
import IllustratedHeaderPageLayout from '@components/IllustratedHeaderPageLayout';
7-
import * as LottieAnimations from '@components/LottieAnimations';
7+
import LottieAnimations from '@components/LottieAnimations';
88
import useLocalize from '@hooks/useLocalize';
99
import Navigation from '@libs/Navigation/Navigation';
1010
import themeColors from '@styles/themes/default';

src/pages/signin/SignInHeroImage.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import Lottie from '@components/Lottie';
3-
import * as LottieAnimations from '@components/LottieAnimations';
3+
import LottieAnimations from '@components/LottieAnimations';
44
import withWindowDimensions, {windowDimensionsPropTypes} from '@components/withWindowDimensions';
55
import styles from '@styles/styles';
66
import variables from '@styles/variables';

src/pages/workspace/WorkspacesListPage.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import FeatureList from '@components/FeatureList';
77
import * as Expensicons from '@components/Icon/Expensicons';
88
import * as Illustrations from '@components/Icon/Illustrations';
99
import IllustratedHeaderPageLayout from '@components/IllustratedHeaderPageLayout';
10-
import * as LottieAnimations from '@components/LottieAnimations';
10+
import LottieAnimations from '@components/LottieAnimations';
1111
import MenuItem from '@components/MenuItem';
1212
import OfflineWithFeedback from '@components/OfflineWithFeedback';
1313
import useLocalize from '@hooks/useLocalize';

src/styles/styles.ts

+2-6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {AnimatableNumericValue, Animated, ImageStyle, TextStyle, ViewStyle} from
66
import {CustomAnimation} from 'react-native-animatable';
77
import {PickerStyle} from 'react-native-picker-select';
88
import {MixedStyleDeclaration, MixedStyleRecord} from 'react-native-render-html';
9+
import DotLottieAnimation from '@components/LottieAnimations/types';
910
import * as Browser from '@libs/Browser';
1011
import CONST from '@src/CONST';
1112
import addOutlineWidth from './addOutlineWidth';
@@ -3976,12 +3977,7 @@ const styles = (theme: ThemeColors) =>
39763977
lineHeight: variables.lineHeightXLarge,
39773978
},
39783979

3979-
aspectRatioLottie: (source) => {
3980-
if (!source.uri && typeof source === 'object' && source.w && source.h) {
3981-
return {aspectRatio: source.w / source.h};
3982-
}
3983-
return {};
3984-
},
3980+
aspectRatioLottie: (animation: DotLottieAnimation) => ({aspectRatio: animation.w / animation.h, width: '100%'}),
39853981

39863982
receiptDropHeaderGap: {
39873983
backgroundColor: theme.receiptDropUIBG,

src/types/global.d.ts

+5
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,9 @@ declare module '*.svg' {
1616
export default content;
1717
}
1818

19+
declare module '*.lottie' {
20+
const value: import('lottie-react-native').LottieViewProps.source;
21+
export default value;
22+
}
23+
1924
declare module 'react-native-device-info/jest/react-native-device-info-mock';

web/index.html

+4
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@
123123
transition-duration: 250ms;
124124
transition-property: opacity;
125125
}
126+
127+
.animation {
128+
display: flex;
129+
}
126130
</style>
127131
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1, interactive-widget=resizes-content">
128132
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">

0 commit comments

Comments
 (0)