@@ -11,7 +11,7 @@ import { AnimationStyle, LottieStyle } from "comps/controls/styleControlConstant
1111import { trans } from "i18n" ;
1212import { Section , sectionNames } from "lowcoder-design" ;
1313import { useContext , lazy , useEffect , useState } from "react" ;
14- import { UICompBuilder , withDefault } from "../../generators" ;
14+ import { stateComp , UICompBuilder , withDefault } from "../../generators" ;
1515import {
1616 NameConfig ,
1717 NameConfigHidden ,
@@ -23,6 +23,9 @@ import { AssetType, IconscoutControl } from "@lowcoder-ee/comps/controls/iconsco
2323import { DotLottie } from "@lottiefiles/dotlottie-react" ;
2424import { AutoHeightControl } from "@lowcoder-ee/comps/controls/autoHeightControl" ;
2525import { 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] as const ;
5057
5158const loopOptions = [
@@ -120,6 +127,14 @@ const ModeOptions = [
120127 { label : "Asset Library" , value : "asset-library" }
121128] as const ;
122129
130+ const EventOptions = [
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+ ] as const ; ;
137+
123138let JsonLottieTmpComp = ( function ( ) {
124139 const childrenMap = {
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 return new UICompBuilder ( childrenMap , ( props , dispatch ) => {
145162 const [ dotLottie , setDotLottie ] = useState < DotLottie | null > ( null ) ;
@@ -161,21 +178,41 @@ let JsonLottieTmpComp = (function () {
161178 useEffect ( ( ) => {
162179 const onComplete = ( ) => {
163180 props . keepLastFrame && dotLottie ?. setFrame ( 100 ) ;
181+ props . onEvent ( 'complete' ) ;
164182 }
165183
166184 const onLoad = ( ) => {
167185 setLayoutAndResize ( ) ;
186+ props . onEvent ( 'load' ) ;
187+ }
188+
189+ const onPlay = ( ) => {
190+ props . onEvent ( 'play' ) ;
191+ }
192+
193+ const onPause = ( ) => {
194+ props . onEvent ( 'pause' ) ;
195+ }
196+
197+ const onStop = ( ) => {
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 ] as any
214251 }
215- dotLottieRefCallback = { setDotLottie }
252+ dotLottieRefCallback = { ( lottieRef ) => {
253+ setDotLottie ( lottieRef ) ;
254+ dispatch (
255+ changeChildAction ( "dotLottieRef" , lottieRef as any , 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 . value as Record < 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 < > < Section name = { 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 return this . 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 . value as unknown as DotLottie ) ?. play ( ) ;
343+ } ,
344+ } ,
345+ {
346+ method : {
347+ name : "pause" ,
348+ description : trans ( "jsonLottie.pause" ) ,
349+ params : [ ] ,
350+ } ,
351+ execute : ( comp ) => {
352+ ( comp . children . dotLottieRef . value as unknown as DotLottie ) ?. pause ( ) ;
353+ } ,
354+ } ,
355+ {
356+ method : {
357+ name : "stop" ,
358+ description : trans ( "jsonLottie.stop" ) ,
359+ params : [ ] ,
360+ } ,
361+ execute : ( comp ) => {
362+ ( comp . children . dotLottieRef . value as unknown as DotLottie ) ?. stop ( ) ;
363+ } ,
364+ } ,
365+ ] ) ;
366+
294367export const JsonLottieComp = withExposingConfigs ( JsonLottieTmpComp , [
295368 new NameConfig ( "value" , trans ( "jsonLottie.valueDesc" ) ) ,
296369 NameConfigHidden ,
0 commit comments