Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitfd4e450

Browse files
added events + exposed play/pause/stop methods with json lottie comp
1 parente29a222 commitfd4e450

File tree

3 files changed

+87
-8
lines changed

3 files changed

+87
-8
lines changed

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

Lines changed: 80 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { AnimationStyle, LottieStyle } from "comps/controls/styleControlConstant
1111
import{trans}from"i18n";
1212
import{Section,sectionNames}from"lowcoder-design";
1313
import{useContext,lazy,useEffect,useState}from"react";
14-
import{UICompBuilder,withDefault}from"../../generators";
14+
import{stateComp,UICompBuilder,withDefault}from"../../generators";
1515
import{
1616
NameConfig,
1717
NameConfigHidden,
@@ -23,6 +23,9 @@ import { AssetType, IconscoutControl } from "@lowcoder-ee/comps/controls/iconsco
2323
import{DotLottie}from"@lottiefiles/dotlottie-react";
2424
import{AutoHeightControl}from"@lowcoder-ee/comps/controls/autoHeightControl";
2525
import{useResizeDetector}from"react-resize-detector";
26+
import{eventHandlerControl}from"@lowcoder-ee/comps/controls/eventHandlerControl";
27+
import{withMethodExposing}from"@lowcoder-ee/comps/generators/withMethodExposing";
28+
import{changeChildAction}from"lowcoder-core";
2629

2730
// const Player = lazy(
2831
// () => import('@lottiefiles/react-lottie-player')
@@ -46,6 +49,10 @@ const animationStartOptions = [
4649
label:trans("jsonLottie.onHover"),
4750
value:"hover",
4851
},
52+
{
53+
label:trans("jsonLottie.onTrigger"),
54+
value:"trigger",
55+
},
4956
]asconst;
5057

5158
constloopOptions=[
@@ -120,6 +127,14 @@ const ModeOptions = [
120127
{label:"Asset Library",value:"asset-library"}
121128
]asconst;
122129

130+
constEventOptions=[
131+
{label:trans("jsonLottie.load"),value:"load",description:trans("jsonLottie.load")},
132+
{label:trans("jsonLottie.play"),value:"play",description:trans("jsonLottie.play")},
133+
{label:trans("jsonLottie.pause"),value:"pause",description:trans("jsonLottie.pause")},
134+
{label:trans("jsonLottie.stop"),value:"stop",description:trans("jsonLottie.stop")},
135+
{label:trans("jsonLottie.complete"),value:"complete",description:trans("jsonLottie.complete")},
136+
]asconst;;
137+
123138
letJsonLottieTmpComp=(function(){
124139
constchildrenMap={
125140
sourceMode:dropdownControl(ModeOptions,"standard"),
@@ -140,6 +155,8 @@ let JsonLottieTmpComp = (function () {
140155
aspectRatio:withDefault(StringControl,"1/1"),
141156
fit:dropdownControl(alignOptions,"contain"),
142157
align:dropdownControl(fitOptions,"0.5,0.5"),
158+
onEvent:eventHandlerControl(EventOptions),
159+
dotLottieRef:stateComp<any|null>(null),
143160
};
144161
returnnewUICompBuilder(childrenMap,(props,dispatch)=>{
145162
const[dotLottie,setDotLottie]=useState<DotLottie|null>(null);
@@ -161,21 +178,41 @@ let JsonLottieTmpComp = (function () {
161178
useEffect(()=>{
162179
constonComplete=()=>{
163180
props.keepLastFrame&&dotLottie?.setFrame(100);
181+
props.onEvent('complete');
164182
}
165183

166184
constonLoad=()=>{
167185
setLayoutAndResize();
186+
props.onEvent('load');
187+
}
188+
189+
constonPlay=()=>{
190+
props.onEvent('play');
191+
}
192+
193+
constonPause=()=>{
194+
props.onEvent('pause');
195+
}
196+
197+
constonStop=()=>{
198+
props.onEvent('stop');
168199
}
169200

170201
if(dotLottie){
171202
dotLottie.addEventListener('complete',onComplete);
172203
dotLottie.addEventListener('load',onLoad);
204+
dotLottie.addEventListener('play',onPlay);
205+
dotLottie.addEventListener('pause',onPause);
206+
dotLottie.addEventListener('stop',onStop);
173207
}
174208

175209
return()=>{
176210
if(dotLottie){
177211
dotLottie.removeEventListener('complete',onComplete);
178212
dotLottie.removeEventListener('load',onLoad);
213+
dotLottie.removeEventListener('play',onPlay);
214+
dotLottie.removeEventListener('pause',onPause);
215+
dotLottie.removeEventListener('stop',onStop);
179216
}
180217
};
181218
},[dotLottie,props.keepLastFrame]);
@@ -212,17 +249,18 @@ let JsonLottieTmpComp = (function () {
212249
key={
213250
[props.speed,props.animationStart,props.loop,props.value,props.keepLastFrame]asany
214251
}
215-
dotLottieRefCallback={setDotLottie}
252+
dotLottieRefCallback={(lottieRef)=>{
253+
setDotLottie(lottieRef);
254+
dispatch(
255+
changeChildAction("dotLottieRef",lottieRefasany,false)
256+
)
257+
}}
216258
autoplay={props.animationStart==="auto"}
217259
loop={props.loop==="single" ?false :true}
218260
speed={Number(props.speed)}
219261
data={props.sourceMode==='standard' ?props.valueasRecord<string,undefined> :undefined}
220262
src={props.sourceMode==='asset-library' ?props.iconScoutAsset?.value :undefined}
221263
style={{
222-
height:"100%",
223-
width:"100%",
224-
maxWidth:"100%",
225-
maxHeight:"100%",
226264
aspectRatio:props.aspectRatio,
227265
}}
228266
onMouseEnter={()=>props.animationStart==="hover"&&dotLottie?.play()}
@@ -250,11 +288,12 @@ let JsonLottieTmpComp = (function () {
250288

251289
{(useContext(EditorContext).editorModeStatus==="logic"||useContext(EditorContext).editorModeStatus==="both")&&(
252290
<><Sectionname={sectionNames.interaction}>
291+
{children.onEvent.getPropertyView()}
253292
{children.speed.propertyView({label:trans("jsonLottie.speed")})}
254293
{children.loop.propertyView({label:trans("jsonLottie.loop")})}
255294
{children.animationStart.propertyView({label:trans("jsonLottie.animationStart")})}
256-
{children.keepLastFrame.propertyView({label:trans("jsonLottie.keepLastFrame")})}
257295
{hiddenPropertyView(children)}
296+
{children.keepLastFrame.propertyView({label:trans("jsonLottie.keepLastFrame")})}
258297
{showDataLoadingIndicatorsPropertyView(children)}
259298
</Section>
260299
</>
@@ -291,6 +330,40 @@ JsonLottieTmpComp = class extends JsonLottieTmpComp {
291330
returnthis.children.autoHeight.getView();
292331
}
293332
};
333+
334+
JsonLottieTmpComp=withMethodExposing(JsonLottieTmpComp,[
335+
{
336+
method:{
337+
name:"play",
338+
description:trans("jsonLottie.play"),
339+
params:[],
340+
},
341+
execute:(comp)=>{
342+
(comp.children.dotLottieRef.valueasunknownasDotLottie)?.play();
343+
},
344+
},
345+
{
346+
method:{
347+
name:"pause",
348+
description:trans("jsonLottie.pause"),
349+
params:[],
350+
},
351+
execute:(comp)=>{
352+
(comp.children.dotLottieRef.valueasunknownasDotLottie)?.pause();
353+
},
354+
},
355+
{
356+
method:{
357+
name:"stop",
358+
description:trans("jsonLottie.stop"),
359+
params:[],
360+
},
361+
execute:(comp)=>{
362+
(comp.children.dotLottieRef.valueasunknownasDotLottie)?.stop();
363+
},
364+
},
365+
]);
366+
294367
exportconstJsonLottieComp=withExposingConfigs(JsonLottieTmpComp,[
295368
newNameConfig("value",trans("jsonLottie.valueDesc")),
296369
NameConfigHidden,

‎client/packages/lowcoder/src/comps/controls/iconscoutControl.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import styled from "styled-components";
1717
importPopoverfrom"antd/es/popover";
1818
import{CloseIcon,SearchIcon}from"icons";
1919
importDraggablefrom"react-draggable";
20-
importIconScoutApifrom"@lowcoder-ee/api/iconScoutApi";
20+
importIconScoutApifrom"@lowcoder-ee/api/iconscoutApi";
2121
import{searchAssets,getAssetLinks,SearchParams}from"@lowcoder-ee/api/iconFlowApi";
2222
importList,{ListRowProps}from"react-virtualized/dist/es/List";
2323
import{debounce}from"lodash";

‎client/packages/lowcoder/src/i18n/locales/en.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3761,11 +3761,17 @@ export const en = {
37613761
"loop":"Loop",
37623762
"auto":"Auto",
37633763
"onHover":"On Hover",
3764+
"onTrigger":"On Trigger",
37643765
"singlePlay":"Single Play",
37653766
"endlessLoop":"Endless Loop",
37663767
"keepLastFrame":"Keep Last Frame displayed",
37673768
"fit":"Fit",
37683769
"align":"Align",
3770+
"load":"On Load",
3771+
"play":"On Play",
3772+
"pause":"On Pause",
3773+
"stop":"On Stop",
3774+
"complete":"On Complete",
37693775
},
37703776
"timeLine":{
37713777
"titleColor":"Title Color",

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp