@@ -22,6 +22,7 @@ import { EditorContext } from "comps/editorState";
2222import { AssetType , IconscoutControl } from "@lowcoder-ee/comps/controls/iconscoutControl" ;
2323import { DotLottie } from "@lottiefiles/dotlottie-react" ;
2424import { AutoHeightControl } from "@lowcoder-ee/comps/controls/autoHeightControl" ;
25+ import { useResizeDetector } from "react-resize-detector" ;
2526
2627// const Player = lazy(
2728// () => import('@lottiefiles/react-lottie-player')
@@ -93,6 +94,27 @@ const speedOptions = [
9394 } ,
9495] as const ;
9596
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+
96118const ModeOptions = [
97119 { label : "Lottie JSON" , value : "standard" } ,
98120 { label : "Asset Library" , value : "asset-library" }
@@ -114,30 +136,59 @@ let JsonLottieTmpComp = (function () {
114136 animationStart : dropdownControl ( animationStartOptions , "auto" ) ,
115137 loop : dropdownControl ( loopOptions , "single" ) ,
116138 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" ) ,
119143 } ;
120144 return new UICompBuilder ( childrenMap , ( props , dispatch ) => {
121145 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+
123161 useEffect ( ( ) => {
124162 const onComplete = ( ) => {
125163 props . keepLastFrame && dotLottie ?. setFrame ( 100 ) ;
126164 }
127165
166+ const onLoad = ( ) => {
167+ setLayoutAndResize ( ) ;
168+ }
169+
128170 if ( dotLottie ) {
129171 dotLottie . addEventListener ( 'complete' , onComplete ) ;
172+ dotLottie . addEventListener ( 'load' , onLoad ) ;
130173 }
131174
132175 return ( ) => {
133176 if ( dotLottie ) {
134177 dotLottie . removeEventListener ( 'complete' , onComplete ) ;
178+ dotLottie . removeEventListener ( 'load' , onLoad ) ;
135179 }
136180 } ;
137181 } , [ dotLottie , props . keepLastFrame ] ) ;
138182
183+ useEffect ( ( ) => {
184+ if ( dotLottie ) {
185+ setLayoutAndResize ( ) ;
186+ }
187+ } , [ dotLottie , props . fit , props . align , props . autoHeight ] ) ;
188+
139189 return (
140190 < div
191+ ref = { wrapperRef }
141192 style = { {
142193 height : '100%' ,
143194 padding : `${ props . container . margin } ` ,
@@ -155,7 +206,6 @@ let JsonLottieTmpComp = (function () {
155206 background : `${ props . container . background } ` ,
156207 padding : `${ props . container . padding } ` ,
157208 rotate : props . container . rotation ,
158- aspectRatio : props . aspectRatio ,
159209 } }
160210 >
161211 < DotLottiePlayer
@@ -173,12 +223,10 @@ let JsonLottieTmpComp = (function () {
173223 width : "100%" ,
174224 maxWidth : "100%" ,
175225 maxHeight : "100%" ,
226+ aspectRatio : props . aspectRatio ,
176227 } }
177228 onMouseEnter = { ( ) => props . animationStart === "hover" && dotLottie ?. play ( ) }
178229 onMouseLeave = { ( ) => props . animationStart === "hover" && dotLottie ?. pause ( ) }
179- renderConfig = { {
180- autoResize : props . autoHeight ,
181- } }
182230 />
183231 </ div >
184232 </ div >
@@ -218,6 +266,8 @@ let JsonLottieTmpComp = (function () {
218266 { children . aspectRatio . propertyView ( {
219267 label : trans ( "style.aspectRatio" ) ,
220268 } ) }
269+ { children . align . propertyView ( { label : trans ( "jsonLottie.align" ) } ) }
270+ { children . fit . propertyView ( { label : trans ( "jsonLottie.fit" ) } ) }
221271 </ Section >
222272 ) }
223273
0 commit comments