@@ -13,6 +13,7 @@ import SwiftUI
1313 @Published var marker : NSString = " "
1414 @Published var themeId : NSString = " "
1515 @Published var stateMachineId : NSString = " "
16+ @Published var layoutConfig : NSDictionary ? = nil
1617 @Published var onPlay : RCTDirectEventBlock = { _ in }
1718 @Published var onLoad : RCTDirectEventBlock = { _ in }
1819 @Published var onLoadError : RCTDirectEventBlock = { _ in }
@@ -82,6 +83,28 @@ import SwiftUI
8283 _ = animation. stateMachineSubscribe ( stateMachineObserver)
8384 }
8485
86+ private func buildLayout( ) -> DotLottie . Layout ? {
87+ guard let dict = layoutConfig else { return nil }
88+ let fitString = ( dict [ " fit " ] as? String ) ?? " contain "
89+ let fit : Fit = {
90+ switch fitString {
91+ case " cover " : return . cover
92+ case " fill " : return . fill
93+ case " fit-width " : return . fitWidth
94+ case " fit-height " : return . fitHeight
95+ case " none " : return . none
96+ default : return . contain
97+ }
98+ } ( )
99+ var alignX : Float = 0.5
100+ var alignY : Float = 0.5
101+ if let alignArr = dict [ " align " ] as? [ NSNumber ] , alignArr. count == 2 {
102+ alignX = Float ( truncating: alignArr [ 0 ] )
103+ alignY = Float ( truncating: alignArr [ 1 ] )
104+ }
105+ return DotLottie . Layout ( fit: fit, alignX: alignX, alignY: alignY)
106+ }
107+
85108 func buildAnimationConfig( ) -> AnimationConfig {
86109 // Convert playMode to Mode enum
87110 let mode : Mode = {
@@ -113,7 +136,7 @@ import SwiftUI
113136 backgroundColor: nil ,
114137 width: nil , // Use default
115138 height: nil , // Use default
116- layout: nil , // Use default
139+ layout: buildLayout ( ) ,
117140 marker: marker != " " ? String ( marker) : " " ,
118141 themeId: themeId != " " ? String ( themeId) : " " ,
119142 stateMachineId: stateMachineId != " " ? String ( stateMachineId) : " "
@@ -721,6 +744,18 @@ class DotlottieReactNativeView: UIView {
721744 }
722745 }
723746
747+ @objc var layout : NSDictionary ? {
748+ didSet {
749+ performIfActive {
750+ dataStore. layoutConfig = layout
751+ // Recreate so the new layout applies whether or not the animation exists
752+ // yet. (The SDK also exposes a runtime setLayout if a no-reload path is
753+ // preferred later.)
754+ scheduleAnimationUpdate ( )
755+ }
756+ }
757+ }
758+
724759 @objc var stateMachineId : NSString = " " {
725760 didSet {
726761 performIfActive {
0 commit comments