diff --git a/App/common/constants/StringConstant.ts b/App/common/constants/StringConstant.ts index 0131a053cf..20d178617d 100644 --- a/App/common/constants/StringConstant.ts +++ b/App/common/constants/StringConstant.ts @@ -57,6 +57,7 @@ export const NETWORK_ERROR = "Network Error"; export const HOME = "home"; export const ADVERSE = "adverse"; export const HARDWARE_BACK_PRESS = "hardwareBackPress"; +export const LOTTIE_VIEW = "LottieView"; export enum SeparatorType { DASHED = "dashed", SOLID = "solid", diff --git a/App/common/interface/widgets/widgetData/TitleWidgetData.ts b/App/common/interface/widgets/widgetData/TitleWidgetData.ts index b487fa8c21..2d984e232d 100644 --- a/App/common/interface/widgets/widgetData/TitleWidgetData.ts +++ b/App/common/interface/widgets/widgetData/TitleWidgetData.ts @@ -1,4 +1,4 @@ -import { ImageStyle, TextStyle, ViewStyle } from "react-native"; +import { ImageStyle, StyleProp, TextStyle, ViewStyle } from "react-native"; import { CtaData } from "../.."; import { GenericActionPayload } from "../../../actions/GenericAction"; import { GenericWidgetData } from "../Widget"; @@ -56,3 +56,13 @@ export interface LottieFieldData { delayAnimationBy?: number; actions?: GenericActionPayload; } + +export type LottieViewProps = { + style?: StyleProp; + animationName?: string; + url: string; + lottieStyle?: StyleProp; + autoPlay?: boolean; + loop?: boolean; + delayAnimation: number; +}; diff --git a/components/reusable/cta-button/CtaButton.tsx b/components/reusable/cta-button/CtaButton.tsx index 62c11f6367..6b061712d2 100644 --- a/components/reusable/cta-button/CtaButton.tsx +++ b/components/reusable/cta-button/CtaButton.tsx @@ -6,7 +6,6 @@ import { StyledLottie } from "../../widgets/styled-lottie/StyledLottie"; import styles from "./CtaButtonStyle"; import { Platform } from "react-native"; import { OsTypeConstants } from "../../../App/common/constants/BuildConfigConstants"; -import LottieView from "../../widgets/styled-lottie/StyledLottieIos"; const CtaButton = ({ onPress, @@ -32,11 +31,7 @@ const CtaButton = ({ style={[styles.footerButtonContainer, style]} > {state === ButtonState.LOADING ? ( - Platform.OS === OsTypeConstants.IOS ? ( - - ) : ( - - ) + ) : ( children )} diff --git a/components/widgets/select-card-with-footer-widget/SelectCardWithFooterWidgetStyles.ts b/components/widgets/select-card-with-footer-widget/SelectCardWithFooterWidgetStyles.ts index 50b0d45907..67a345324d 100644 --- a/components/widgets/select-card-with-footer-widget/SelectCardWithFooterWidgetStyles.ts +++ b/components/widgets/select-card-with-footer-widget/SelectCardWithFooterWidgetStyles.ts @@ -24,7 +24,7 @@ export const styles = StyleSheet.create({ backgroundColor: Colors.white, shadowColor: Colors.black, shadowOffset: { width: 3, height: 3 }, - shadowOpacity: 0.3, + shadowOpacity: 0.2, shadowRadius: 16, elevation: 5, }, diff --git a/components/widgets/styled-lottie/GenericLottieView.tsx b/components/widgets/styled-lottie/GenericLottieView.tsx new file mode 100644 index 0000000000..c29f01caf4 --- /dev/null +++ b/components/widgets/styled-lottie/GenericLottieView.tsx @@ -0,0 +1,55 @@ +import React, { useEffect, useRef } from "react"; +import { + requireNativeComponent, + ViewStyle, + NativeModules, + Platform, +} from "react-native"; +import type { StyleProp } from "react-native"; +import LottieView from "lottie-react-native"; +import styles from "./StyledLottieComponentStyle"; +import { LOTTIE_VIEW, OsTypeConstants } from "../../../App/common/constants"; +import { LottieViewProps } from "../../../App/common/interface/widgets/widgetData/TitleWidgetData"; + +const { LottieViewManager } = NativeModules; + +const LottieViewNative = requireNativeComponent(LOTTIE_VIEW); + +const GenericLottieView = ({ + url, + lottieStyle, + autoPlay = true, + loop = true, + delayAnimation, + style, +}: LottieViewProps) => { + const animationRef = useRef(null); + useEffect(() => { + if (Platform.OS === OsTypeConstants.IOS && url) { + LottieViewManager.updateAnimation(url); + } else { + const timeoutId = setTimeout(() => { + animationRef.current?.play(); + }, delayAnimation ?? 0); + return () => clearTimeout(timeoutId); + } + }, [url]); + + return Platform.OS === OsTypeConstants.IOS ? ( + + ) : ( + + ); +}; + +export default GenericLottieView; diff --git a/components/widgets/styled-lottie/StyledLottie.tsx b/components/widgets/styled-lottie/StyledLottie.tsx index 007af2e617..7566ab7bbd 100644 --- a/components/widgets/styled-lottie/StyledLottie.tsx +++ b/components/widgets/styled-lottie/StyledLottie.tsx @@ -1,10 +1,11 @@ -import LottieView from "lottie-react-native"; import React, { useEffect, useRef } from "react"; -import { TouchableOpacity } from "react-native"; +import { Platform, TouchableOpacity } from "react-native"; import { GenericActionPayload } from "../../../App/common/actions/GenericAction"; import { CtaData } from "../../../App/common/interface"; import { LottieFieldData } from "../../../App/common/interface/widgets/widgetData/TitleWidgetData"; import styles from "./StyledLottieComponentStyle"; +import { OsTypeConstants } from "../../../App/common/constants"; +import GenericLottieView from "./GenericLottieView"; export const StyledLottie = ({ lottieFieldData, @@ -18,8 +19,6 @@ export const StyledLottie = ({ actionPayloadList: GenericActionPayload | undefined, ) => void; }) => { - const animationRef = useRef(null); - const handleLottieClick = () => { const { cta, actions } = lottieFieldData; if (actions && handleActions) { @@ -29,38 +28,32 @@ export const StyledLottie = ({ } }; - useEffect(() => { - const timeoutId = setTimeout(() => { - animationRef.current?.play(); - }, lottieFieldData?.delayAnimationBy ?? 0); + if (!lottieFieldData?.url) return null; - return () => clearTimeout(timeoutId); - }, [lottieFieldData]); - - if (!lottieFieldData?.url) return <>; - const { cta, actions } = lottieFieldData; + const { cta, actions, lottieStyle, url, autoPlay, loop } = lottieFieldData; const isInteractive = (cta && handleClick) || (actions && handleActions); + return isInteractive ? ( - ) : ( - ); }; diff --git a/components/widgets/styled-lottie/StyledLottieIos.tsx b/components/widgets/styled-lottie/StyledLottieIos.tsx deleted file mode 100644 index 1195dd207b..0000000000 --- a/components/widgets/styled-lottie/StyledLottieIos.tsx +++ /dev/null @@ -1,16 +0,0 @@ -import React from "react"; -import { requireNativeComponent, ViewStyle } from "react-native"; -import type { StyleProp } from "react-native"; -import styles from "./StyledLottieComponentStyle"; - -type LottieViewProps = { - style?: StyleProp; -}; - -const LottieViewNative = requireNativeComponent("LottieView"); - -const LottieView = () => { - return ; -}; - -export default LottieView; diff --git a/components/widgets/styled-lottie/StyledLottieRN.tsx b/components/widgets/styled-lottie/StyledLottieRN.tsx new file mode 100644 index 0000000000..9f07a24f98 --- /dev/null +++ b/components/widgets/styled-lottie/StyledLottieRN.tsx @@ -0,0 +1,55 @@ +import React, { useEffect, useRef } from "react"; +import { + requireNativeComponent, + ViewStyle, + NativeModules, + Platform, +} from "react-native"; +import type { StyleProp } from "react-native"; +import LottieView from "lottie-react-native"; +import styles from "./StyledLottieComponentStyle"; +import { LOTTIE_VIEW, OsTypeConstants } from "../../../App/common/constants"; +import { LottieViewProps } from "../../../App/common/interface/widgets/widgetData/TitleWidgetData"; + +const { LottieViewManager } = NativeModules; + +const LottieViewNative = requireNativeComponent(LOTTIE_VIEW); + +const LottieViewRN = ({ + url, + lottieStyle, + autoPlay = true, + loop = true, + delayAnimation, + style, +}: LottieViewProps) => { + const animationRef = useRef(null); + useEffect(() => { + if (Platform.OS === OsTypeConstants.IOS && url) { + LottieViewManager.updateAnimation(url); + } else { + const timeoutId = setTimeout(() => { + animationRef.current?.play(); + }, delayAnimation ?? 0); + return () => clearTimeout(timeoutId); + } + }, [url]); + + return Platform.OS === OsTypeConstants.IOS ? ( + + ) : ( + + ); +}; + +export default LottieViewRN;