@@ -2,15 +2,14 @@ import { hiddenPropertyView, showDataLoadingIndicatorsPropertyView } from "comps
2
2
import {
3
3
ArrayOrJSONObjectControl ,
4
4
NumberControl ,
5
- StringControl ,
6
5
} from "comps/controls/codeControl" ;
7
6
import { dropdownControl } from "comps/controls/dropdownControl" ;
8
7
import { BoolControl } from "comps/controls/boolControl" ;
9
8
import { styleControl } from "comps/controls/styleControl" ;
10
9
import { AnimationStyle , LottieStyle } from "comps/controls/styleControlConstants" ;
11
10
import { trans } from "i18n" ;
12
11
import { Section , sectionNames } from "lowcoder-design" ;
13
- import { useContext , lazy , useEffect } from "react" ;
12
+ import { useContext , lazy , useEffect , useState } from "react" ;
14
13
import { UICompBuilder , withDefault } from "../../generators" ;
15
14
import {
16
15
NameConfig ,
@@ -19,15 +18,13 @@ import {
19
18
} from "../../generators/withExposing" ;
20
19
import { defaultLottie } from "./jsonConstants" ;
21
20
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" ;
26
23
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
+ // );
31
28
32
29
const DotLottiePlayer = lazy (
33
30
( ) => import ( '@lottiefiles/dotlottie-react' )
@@ -44,7 +41,7 @@ const animationStartOptions = [
44
41
} ,
45
42
{
46
43
label : trans ( "jsonLottie.onHover" ) ,
47
- value : "on hover" ,
44
+ value : "hover" ,
48
45
} ,
49
46
] as const ;
50
47
@@ -96,8 +93,7 @@ const speedOptions = [
96
93
97
94
const ModeOptions = [
98
95
{ label : "Lottie JSON" , value : "standard" } ,
99
- { label : "DotLottie" , value : "dotLottie" } ,
100
- { label : "IconScout" , value : "advanced" } ,
96
+ { label : "Asset Library" , value : "asset-library" }
101
97
] as const ;
102
98
103
99
let JsonLottieTmpComp = ( function ( ) {
@@ -107,10 +103,7 @@ let JsonLottieTmpComp = (function () {
107
103
ArrayOrJSONObjectControl ,
108
104
JSON . stringify ( defaultLottie , null , 2 )
109
105
) ,
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 ) ,
114
107
speed : dropdownControl ( speedOptions , "1" ) ,
115
108
width : withDefault ( NumberControl , 100 ) ,
116
109
height : withDefault ( NumberControl , 100 ) ,
@@ -121,32 +114,23 @@ let JsonLottieTmpComp = (function () {
121
114
keepLastFrame : BoolControl . DEFAULT_TRUE ,
122
115
} ;
123
116
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 ) ;
141
122
}
142
123
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 ) ;
148
126
}
149
- } , [ props . srcIconScout ] ) ;
127
+
128
+ return ( ) => {
129
+ if ( dotLottie ) {
130
+ dotLottie . removeEventListener ( 'complete' , onComplete ) ;
131
+ }
132
+ } ;
133
+ } , [ dotLottie , props . keepLastFrame ] ) ;
150
134
151
135
return (
152
136
< div
@@ -169,50 +153,25 @@ let JsonLottieTmpComp = (function () {
169
153
rotate : props . container . rotation ,
170
154
} }
171
155
>
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
+ />
216
175
</ div >
217
176
</ div >
218
177
) ;
@@ -228,15 +187,9 @@ let JsonLottieTmpComp = (function () {
228
187
{ children . sourceMode . getView ( ) === 'standard' && children . value . propertyView ( {
229
188
label : trans ( "jsonLottie.lottieJson" ) ,
230
189
} ) }
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 ( {
235
191
label : "Lottie Source" ,
236
192
} ) }
237
- { children . sourceMode . getView ( ) === 'advanced' && children . valueIconScout . propertyView ( {
238
- label : trans ( "jsonLottie.lottieJson" ) ,
239
- } ) }
240
193
</ Section >
241
194
242
195
{ ( useContext ( EditorContext ) . editorModeStatus === "logic" || useContext ( EditorContext ) . editorModeStatus === "both" ) && (
0 commit comments