@@ -22,6 +22,7 @@ import { EditorContext } from "comps/editorState";
22
22
import { AssetType , IconscoutControl } from "@lowcoder-ee/comps/controls/iconscoutControl" ;
23
23
import { DotLottie } from "@lottiefiles/dotlottie-react" ;
24
24
import { AutoHeightControl } from "@lowcoder-ee/comps/controls/autoHeightControl" ;
25
+ import { useResizeDetector } from "react-resize-detector" ;
25
26
26
27
// const Player = lazy(
27
28
// () => import('@lottiefiles/react-lottie-player')
@@ -93,6 +94,27 @@ const speedOptions = [
93
94
} ,
94
95
] as const ;
95
96
97
+ const alignOptions = [
98
+ { label :"None" , value :"none" } ,
99
+ { label :"Fill" , value :"fill" } ,
100
+ { label :"Cover" , value :"cover" } ,
101
+ { label :"Contain" , value :"contain" } ,
102
+ { label :"Fit Width" , value :"fit-width" } ,
103
+ { label :"Fit Height" , value :"fit-height" } ,
104
+ ] as const ;
105
+
106
+ const fitOptions = [
107
+ { label :"Top Left" , value :"0,0" } ,
108
+ { label :"Top Center" , value :"0.5,0" } ,
109
+ { label :"Top Right" , value :"1,0" } ,
110
+ { label :"Center Left" , value :"0,0.5" } ,
111
+ { label :"Center" , value :"0.5,0.5" } ,
112
+ { label :"Center Right" , value :"1,0.5" } ,
113
+ { label :"Bottom Left" , value :"0,1" } ,
114
+ { label :"Bottom Center" , value :"0.5,1" } ,
115
+ { label :"Bottom Right" , value :"1,1" } ,
116
+ ] as const ;
117
+
96
118
const ModeOptions = [
97
119
{ label :"Lottie JSON" , value :"standard" } ,
98
120
{ label :"Asset Library" , value :"asset-library" }
@@ -114,30 +136,59 @@ let JsonLottieTmpComp = (function () {
114
136
animationStart :dropdownControl ( animationStartOptions , "auto" ) ,
115
137
loop :dropdownControl ( loopOptions , "single" ) ,
116
138
keepLastFrame :BoolControl . DEFAULT_TRUE ,
117
- autoHeight :withDefault ( AutoHeightControl , "fixed" ) ,
118
- aspectRatio :withDefault ( StringControl , "16 / 9" ) ,
139
+ autoHeight :withDefault ( AutoHeightControl , "auto" ) ,
140
+ aspectRatio :withDefault ( StringControl , "1/1" ) ,
141
+ fit :dropdownControl ( alignOptions , "contain" ) ,
142
+ align :dropdownControl ( fitOptions , "0.5,0.5" ) ,
119
143
} ;
120
144
return new UICompBuilder ( childrenMap , ( props , dispatch ) => {
121
145
const [ dotLottie , setDotLottie ] = useState < DotLottie | null > ( null ) ;
122
-
146
+
147
+ const setLayoutAndResize = ( ) => {
148
+ const align = props . align . split ( ',' ) ;
149
+ dotLottie ?. setLayout ( { fit :props . fit , align :[ Number ( align [ 0 ] ) , Number ( align [ 1 ] ) ] } )
150
+ dotLottie ?. resize ( ) ;
151
+ }
152
+
153
+ const { ref :wrapperRef } = useResizeDetector ( {
154
+ onResize :( ) => {
155
+ if ( dotLottie ) {
156
+ setLayoutAndResize ( ) ;
157
+ }
158
+ }
159
+ } ) ;
160
+
123
161
useEffect ( ( ) => {
124
162
const onComplete = ( ) => {
125
163
props . keepLastFrame && dotLottie ?. setFrame ( 100 ) ;
126
164
}
127
165
166
+ const onLoad = ( ) => {
167
+ setLayoutAndResize ( ) ;
168
+ }
169
+
128
170
if ( dotLottie ) {
129
171
dotLottie . addEventListener ( 'complete' , onComplete ) ;
172
+ dotLottie . addEventListener ( 'load' , onLoad ) ;
130
173
}
131
174
132
175
return ( ) => {
133
176
if ( dotLottie ) {
134
177
dotLottie . removeEventListener ( 'complete' , onComplete ) ;
178
+ dotLottie . removeEventListener ( 'load' , onLoad ) ;
135
179
}
136
180
} ;
137
181
} , [ dotLottie , props . keepLastFrame ] ) ;
138
182
183
+ useEffect ( ( ) => {
184
+ if ( dotLottie ) {
185
+ setLayoutAndResize ( ) ;
186
+ }
187
+ } , [ dotLottie , props . fit , props . align , props . autoHeight ] ) ;
188
+
139
189
return (
140
190
< div
191
+ ref = { wrapperRef }
141
192
style = { {
142
193
height :'100%' ,
143
194
padding :`${ props . container . margin } ` ,
@@ -155,7 +206,6 @@ let JsonLottieTmpComp = (function () {
155
206
background :`${ props . container . background } ` ,
156
207
padding :`${ props . container . padding } ` ,
157
208
rotate :props . container . rotation ,
158
- aspectRatio :props . aspectRatio ,
159
209
} }
160
210
>
161
211
< DotLottiePlayer
@@ -173,12 +223,10 @@ let JsonLottieTmpComp = (function () {
173
223
width :"100%" ,
174
224
maxWidth :"100%" ,
175
225
maxHeight :"100%" ,
226
+ aspectRatio :props . aspectRatio ,
176
227
} }
177
228
onMouseEnter = { ( ) => props . animationStart === "hover" && dotLottie ?. play ( ) }
178
229
onMouseLeave = { ( ) => props . animationStart === "hover" && dotLottie ?. pause ( ) }
179
- renderConfig = { {
180
- autoResize :props . autoHeight ,
181
- } }
182
230
/>
183
231
</ div >
184
232
</ div >
@@ -218,6 +266,8 @@ let JsonLottieTmpComp = (function () {
218
266
{ children . aspectRatio . propertyView ( {
219
267
label :trans ( "style.aspectRatio" ) ,
220
268
} ) }
269
+ { children . align . propertyView ( { label :trans ( "jsonLottie.align" ) } ) }
270
+ { children . fit . propertyView ( { label :trans ( "jsonLottie.fit" ) } ) }
221
271
</ Section >
222
272
) }
223
273