@@ -11,7 +11,7 @@ import { AnimationStyle, LottieStyle } from "comps/controls/styleControlConstant
11
11
import { trans } from "i18n" ;
12
12
import { Section , sectionNames } from "lowcoder-design" ;
13
13
import { useContext , lazy , useEffect , useState } from "react" ;
14
- import { UICompBuilder , withDefault } from "../../generators" ;
14
+ import { stateComp , UICompBuilder , withDefault } from "../../generators" ;
15
15
import {
16
16
NameConfig ,
17
17
NameConfigHidden ,
@@ -23,6 +23,9 @@ import { AssetType, IconscoutControl } from "@lowcoder-ee/comps/controls/iconsco
23
23
import { DotLottie } from "@lottiefiles/dotlottie-react" ;
24
24
import { AutoHeightControl } from "@lowcoder-ee/comps/controls/autoHeightControl" ;
25
25
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" ;
26
29
27
30
// const Player = lazy(
28
31
// () => import('@lottiefiles/react-lottie-player')
@@ -46,6 +49,10 @@ const animationStartOptions = [
46
49
label : trans ( "jsonLottie.onHover" ) ,
47
50
value : "hover" ,
48
51
} ,
52
+ {
53
+ label : trans ( "jsonLottie.onTrigger" ) ,
54
+ value : "trigger" ,
55
+ } ,
49
56
] as const ;
50
57
51
58
const loopOptions = [
@@ -120,6 +127,14 @@ const ModeOptions = [
120
127
{ label : "Asset Library" , value : "asset-library" }
121
128
] as const ;
122
129
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
+
123
138
let JsonLottieTmpComp = ( function ( ) {
124
139
const childrenMap = {
125
140
sourceMode : dropdownControl ( ModeOptions , "standard" ) ,
@@ -140,6 +155,8 @@ let JsonLottieTmpComp = (function () {
140
155
aspectRatio : withDefault ( StringControl , "1/1" ) ,
141
156
fit : dropdownControl ( alignOptions , "contain" ) ,
142
157
align : dropdownControl ( fitOptions , "0.5,0.5" ) ,
158
+ onEvent : eventHandlerControl ( EventOptions ) ,
159
+ dotLottieRef : stateComp < any | null > ( null ) ,
143
160
} ;
144
161
return new UICompBuilder ( childrenMap , ( props , dispatch ) => {
145
162
const [ dotLottie , setDotLottie ] = useState < DotLottie | null > ( null ) ;
@@ -161,21 +178,41 @@ let JsonLottieTmpComp = (function () {
161
178
useEffect ( ( ) => {
162
179
const onComplete = ( ) => {
163
180
props . keepLastFrame && dotLottie ?. setFrame ( 100 ) ;
181
+ props . onEvent ( 'complete' ) ;
164
182
}
165
183
166
184
const onLoad = ( ) => {
167
185
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' ) ;
168
199
}
169
200
170
201
if ( dotLottie ) {
171
202
dotLottie . addEventListener ( 'complete' , onComplete ) ;
172
203
dotLottie . addEventListener ( 'load' , onLoad ) ;
204
+ dotLottie . addEventListener ( 'play' , onPlay ) ;
205
+ dotLottie . addEventListener ( 'pause' , onPause ) ;
206
+ dotLottie . addEventListener ( 'stop' , onStop ) ;
173
207
}
174
208
175
209
return ( ) => {
176
210
if ( dotLottie ) {
177
211
dotLottie . removeEventListener ( 'complete' , onComplete ) ;
178
212
dotLottie . removeEventListener ( 'load' , onLoad ) ;
213
+ dotLottie . removeEventListener ( 'play' , onPlay ) ;
214
+ dotLottie . removeEventListener ( 'pause' , onPause ) ;
215
+ dotLottie . removeEventListener ( 'stop' , onStop ) ;
179
216
}
180
217
} ;
181
218
} , [ dotLottie , props . keepLastFrame ] ) ;
@@ -212,17 +249,18 @@ let JsonLottieTmpComp = (function () {
212
249
key = {
213
250
[ props . speed , props . animationStart , props . loop , props . value , props . keepLastFrame ] as any
214
251
}
215
- dotLottieRefCallback = { setDotLottie }
252
+ dotLottieRefCallback = { ( lottieRef ) => {
253
+ setDotLottie ( lottieRef ) ;
254
+ dispatch (
255
+ changeChildAction ( "dotLottieRef" , lottieRef as any , false )
256
+ )
257
+ } }
216
258
autoplay = { props . animationStart === "auto" }
217
259
loop = { props . loop === "single" ? false : true }
218
260
speed = { Number ( props . speed ) }
219
261
data = { props . sourceMode === 'standard' ? props . value as Record < string , undefined > : undefined }
220
262
src = { props . sourceMode === 'asset-library' ? props . iconScoutAsset ?. value : undefined }
221
263
style = { {
222
- height : "100%" ,
223
- width : "100%" ,
224
- maxWidth : "100%" ,
225
- maxHeight : "100%" ,
226
264
aspectRatio : props . aspectRatio ,
227
265
} }
228
266
onMouseEnter = { ( ) => props . animationStart === "hover" && dotLottie ?. play ( ) }
@@ -250,11 +288,12 @@ let JsonLottieTmpComp = (function () {
250
288
251
289
{ ( useContext ( EditorContext ) . editorModeStatus === "logic" || useContext ( EditorContext ) . editorModeStatus === "both" ) && (
252
290
< > < Section name = { sectionNames . interaction } >
291
+ { children . onEvent . getPropertyView ( ) }
253
292
{ children . speed . propertyView ( { label : trans ( "jsonLottie.speed" ) } ) }
254
293
{ children . loop . propertyView ( { label : trans ( "jsonLottie.loop" ) } ) }
255
294
{ children . animationStart . propertyView ( { label : trans ( "jsonLottie.animationStart" ) } ) }
256
- { children . keepLastFrame . propertyView ( { label : trans ( "jsonLottie.keepLastFrame" ) } ) }
257
295
{ hiddenPropertyView ( children ) }
296
+ { children . keepLastFrame . propertyView ( { label : trans ( "jsonLottie.keepLastFrame" ) } ) }
258
297
{ showDataLoadingIndicatorsPropertyView ( children ) }
259
298
</ Section >
260
299
</ >
@@ -291,6 +330,40 @@ JsonLottieTmpComp = class extends JsonLottieTmpComp {
291
330
return this . children . autoHeight . getView ( ) ;
292
331
}
293
332
} ;
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
+
294
367
export const JsonLottieComp = withExposingConfigs ( JsonLottieTmpComp , [
295
368
new NameConfig ( "value" , trans ( "jsonLottie.valueDesc" ) ) ,
296
369
NameConfigHidden ,
0 commit comments