Skip to content

Commit b29b1dd

Browse files
used dotLottie player for different modes
1 parent fdc8050 commit b29b1dd

File tree

1 file changed

+44
-91
lines changed

1 file changed

+44
-91
lines changed

client/packages/lowcoder/src/comps/comps/jsonComp/jsonLottieComp.tsx

Lines changed: 44 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@ import { hiddenPropertyView, showDataLoadingIndicatorsPropertyView } from "comps
22
import {
33
ArrayOrJSONObjectControl,
44
NumberControl,
5-
StringControl,
65
} from "comps/controls/codeControl";
76
import { dropdownControl } from "comps/controls/dropdownControl";
87
import { BoolControl } from "comps/controls/boolControl";
98
import { styleControl } from "comps/controls/styleControl";
109
import { AnimationStyle, LottieStyle } from "comps/controls/styleControlConstants";
1110
import { trans } from "i18n";
1211
import { Section, sectionNames } from "lowcoder-design";
13-
import { useContext, lazy, useEffect } from "react";
12+
import { useContext, lazy, useEffect, useState } from "react";
1413
import { UICompBuilder, withDefault } from "../../generators";
1514
import {
1615
NameConfig,
@@ -19,15 +18,13 @@ import {
1918
} from "../../generators/withExposing";
2019
import { defaultLottie } from "./jsonConstants";
2120
import { EditorContext } from "comps/editorState";
22-
import { IconScoutAssetType, IconscoutControl } from "@lowcoder-ee/comps/controls/iconscoutControl";
23-
import { isEmpty } from "lodash";
24-
import IconscoutApi from "@lowcoder-ee/api/iconscoutApi";
25-
import { changeValueAction, multiChangeAction } from "lowcoder-core";
21+
import { AssetType, IconscoutControl } from "@lowcoder-ee/comps/controls/iconscoutControl";
22+
import { DotLottie } from "@lottiefiles/dotlottie-react";
2623

27-
const Player = lazy(
28-
() => import('@lottiefiles/react-lottie-player')
29-
.then(module => ({default: module.Player}))
30-
);
24+
// const Player = lazy(
25+
// () => import('@lottiefiles/react-lottie-player')
26+
// .then(module => ({default: module.Player}))
27+
// );
3128

3229
const DotLottiePlayer = lazy(
3330
() => import('@lottiefiles/dotlottie-react')
@@ -44,7 +41,7 @@ const animationStartOptions = [
4441
},
4542
{
4643
label: trans("jsonLottie.onHover"),
47-
value: "on hover",
44+
value: "hover",
4845
},
4946
] as const;
5047

@@ -96,8 +93,7 @@ const speedOptions = [
9693

9794
const ModeOptions = [
9895
{ label: "Lottie JSON", value: "standard" },
99-
{ label: "DotLottie", value: "dotLottie" },
100-
{ label: "IconScout", value: "advanced" },
96+
{ label: "Asset Library", value: "asset-library" }
10197
] as const;
10298

10399
let JsonLottieTmpComp = (function () {
@@ -107,10 +103,7 @@ let JsonLottieTmpComp = (function () {
107103
ArrayOrJSONObjectControl,
108104
JSON.stringify(defaultLottie, null, 2)
109105
),
110-
srcIconScout: IconscoutControl(IconScoutAssetType.LOTTIE),
111-
srcDotLottie: withDefault(StringControl, 'https://assets-v2.lottiefiles.com/a/9e7d8a50-1180-11ee-89a6-3b0ab1ca8a0e/hUfEwc6xNt.lottie'),
112-
uuidIconScout: StringControl,
113-
valueIconScout: withDefault(ArrayOrJSONObjectControl, JSON.stringify({})),
106+
iconScoutAsset: IconscoutControl(AssetType.LOTTIE),
114107
speed: dropdownControl(speedOptions, "1"),
115108
width: withDefault(NumberControl, 100),
116109
height: withDefault(NumberControl, 100),
@@ -121,32 +114,23 @@ let JsonLottieTmpComp = (function () {
121114
keepLastFrame: BoolControl.DEFAULT_TRUE,
122115
};
123116
return new UICompBuilder(childrenMap, (props, dispatch) => {
124-
125-
const downloadAsset = async (uuid: string) => {
126-
try {
127-
const result = await IconscoutApi.download(uuid, {
128-
format: 'ai',
129-
});
130-
if (result && result.download_url) {
131-
const json = await IconscoutApi.downloadJSON(result.download_url);
132-
dispatch(
133-
multiChangeAction({
134-
uuidIconScout: changeValueAction(uuid, true),
135-
valueIconScout: changeValueAction(JSON.stringify(json, null, 2), true)
136-
})
137-
)
138-
}
139-
} catch(error) {
140-
console.error(error);
117+
const [dotLottie, setDotLottie] = useState<DotLottie | null>(null);
118+
119+
useEffect(() => {
120+
const onComplete = () => {
121+
props.keepLastFrame && dotLottie?.setFrame(100);
141122
}
142123

143-
}
144-
useEffect(() => {
145-
if(props.srcIconScout?.uuid && props.srcIconScout?.uuid !== props.uuidIconScout) {
146-
// get asset download link
147-
downloadAsset(props.srcIconScout?.uuid);
124+
if (dotLottie) {
125+
dotLottie.addEventListener('complete', onComplete);
148126
}
149-
}, [props.srcIconScout]);
127+
128+
return () => {
129+
if (dotLottie) {
130+
dotLottie.removeEventListener('complete', onComplete);
131+
}
132+
};
133+
}, [dotLottie, props.keepLastFrame]);
150134

151135
return (
152136
<div
@@ -169,50 +153,25 @@ let JsonLottieTmpComp = (function () {
169153
rotate: props.container.rotation,
170154
}}
171155
>
172-
{props.sourceMode === 'dotLottie'
173-
? (
174-
<DotLottiePlayer
175-
key={
176-
[props.speed, props.animationStart, props.loop, props.value, props.keepLastFrame] as any
177-
}
178-
// keepLastFrame={props.keepLastFrame}
179-
autoplay={props.animationStart === "auto" && true}
180-
playOnHover={props.animationStart === "on hover" && true}
181-
loop={props.loop === "single" ? false : true}
182-
speed={Number(props.speed)}
183-
src={props.srcDotLottie}
184-
style={{
185-
height: "100%",
186-
width: "100%",
187-
maxWidth: "100%",
188-
maxHeight: "100%",
189-
}}
190-
/>
191-
)
192-
: (
193-
<Player
194-
key={
195-
[props.speed, props.animationStart, props.loop, props.value, props.keepLastFrame] as any
196-
}
197-
keepLastFrame={props.keepLastFrame}
198-
autoplay={props.animationStart === "auto" && true}
199-
hover={props.animationStart === "on hover" && true}
200-
loop={props.loop === "single" ? false : true}
201-
speed={Number(props.speed)}
202-
src={
203-
props.sourceMode === 'advanced'
204-
? (isEmpty(props.valueIconScout) ? '' : props.valueIconScout)
205-
: props.value
206-
}
207-
style={{
208-
height: "100%",
209-
width: "100%",
210-
maxWidth: "100%",
211-
maxHeight: "100%",
212-
}}
213-
/>
214-
)
215-
}
156+
<DotLottiePlayer
157+
key={
158+
[props.speed, props.animationStart, props.loop, props.value, props.keepLastFrame] as any
159+
}
160+
dotLottieRefCallback={setDotLottie}
161+
autoplay={props.animationStart === "auto"}
162+
loop={props.loop === "single" ? false : true}
163+
speed={Number(props.speed)}
164+
data={props.sourceMode === 'standard' ? props.value as Record<string, undefined> : undefined}
165+
src={props.sourceMode === 'asset-library' ? props.iconScoutAsset?.value : undefined}
166+
style={{
167+
height: "100%",
168+
width: "100%",
169+
maxWidth: "100%",
170+
maxHeight: "100%",
171+
}}
172+
onMouseEnter={() => props.animationStart === "hover" && dotLottie?.play()}
173+
onMouseLeave={() => props.animationStart === "hover" && dotLottie?.pause()}
174+
/>
216175
</div>
217176
</div>
218177
);
@@ -228,15 +187,9 @@ let JsonLottieTmpComp = (function () {
228187
{children.sourceMode.getView() === 'standard' && children.value.propertyView({
229188
label: trans("jsonLottie.lottieJson"),
230189
})}
231-
{children.sourceMode.getView() === 'dotLottie' && children.srcDotLottie.propertyView({
232-
label: "Source",
233-
})}
234-
{children.sourceMode.getView() === 'advanced' && children.srcIconScout.propertyView({
190+
{children.sourceMode.getView() === 'asset-library' && children.iconScoutAsset.propertyView({
235191
label: "Lottie Source",
236192
})}
237-
{children.sourceMode.getView() === 'advanced' && children.valueIconScout.propertyView({
238-
label: trans("jsonLottie.lottieJson"),
239-
})}
240193
</Section>
241194

242195
{(useContext(EditorContext).editorModeStatus === "logic" || useContext(EditorContext).editorModeStatus === "both") && (

0 commit comments

Comments
 (0)