@@ -72,6 +72,7 @@ public class VirtusizeInPageView: UIView, VirtusizeView, VirtusizeViewEventProto
7272 internal var isLoading : Bool = false
7373 internal var isError : Bool = false
7474 internal var invalidProduct : Bool = false
75+ private var heightConstraint : NSLayoutConstraint ?
7576
7677 private func addSubviews( ) {
7778 // Add loading GIF image view
@@ -104,6 +105,19 @@ public class VirtusizeInPageView: UIView, VirtusizeView, VirtusizeViewEventProto
104105 isLoading = show
105106 loadingGifImageView. isHidden = !show
106107 contentContainerView. isHidden = show
108+
109+ // Set height to 0 for invalid product or error
110+ if invalidProduct || isError {
111+ if heightConstraint == nil {
112+ heightConstraint = heightAnchor. constraint ( equalToConstant: 0 )
113+ heightConstraint? . priority = . defaultHigh
114+ heightConstraint? . isActive = true
115+ }
116+ } else {
117+ // Remove height constraint for valid product
118+ heightConstraint? . isActive = false
119+ heightConstraint = nil
120+ }
107121 }
108122
109123 /// Add observers to listen to notification data from the sender (Virtusize.self)
@@ -155,6 +169,8 @@ public class VirtusizeInPageView: UIView, VirtusizeView, VirtusizeViewEventProto
155169 @objc internal func didReceiveProductCheckData( _ notification: Notification ) {
156170 shouldUpdateProductCheckData ( notification) { productWithPDCData in
157171 self . clientProduct = productWithPDCData
172+ self . invalidProduct = false
173+ self . isError = false
158174 showLoadingGif ( false )
159175 setLoadingScreen ( loading: true )
160176 isLoading = true
@@ -171,10 +187,18 @@ public class VirtusizeInPageView: UIView, VirtusizeView, VirtusizeViewEventProto
171187 @objc internal func didReceiveSizeRecommendationData( _ notification: Notification ) {
172188 isLoading = false
173189 isError = false
190+ // Remove height constraint when data is successfully loaded
191+ heightConstraint? . isActive = false
192+ heightConstraint = nil
174193 }
175194
176195 @objc func productCheckDidFail( _ notification: Notification ) {
177196 invalidProduct = true
197+ showLoadingGif ( false )
198+ // Notify SwiftUI wrappers to update height
199+ DispatchQueue . main. async {
200+ self . contentViewListener ? ( self )
201+ }
178202 }
179203
180204 internal func shouldUpdateInPageRecommendation(
@@ -204,6 +228,16 @@ public class VirtusizeInPageView: UIView, VirtusizeView, VirtusizeViewEventProto
204228 /// A parent function for showing the error screen
205229 @objc internal func didReceiveInPageError( _ notification: Notification ) {
206230 isError = true
231+ // Update height constraint for error state
232+ if heightConstraint == nil {
233+ heightConstraint = heightAnchor. constraint ( equalToConstant: 0 )
234+ heightConstraint? . priority = . defaultHigh
235+ heightConstraint? . isActive = true
236+ }
237+ // Notify SwiftUI wrappers to update height
238+ DispatchQueue . main. async {
239+ self . contentViewListener ? ( self )
240+ }
207241 }
208242
209243 /// Sets up the styles for the loading screen and the screen after finishing loading
@@ -212,6 +246,9 @@ public class VirtusizeInPageView: UIView, VirtusizeView, VirtusizeViewEventProto
212246 /// - loading: Pass true when it's loading, and pass false when finishing loading
213247 internal func setLoadingScreen( loading: Bool ) {
214248 isError = false
249+ // Remove height constraint when loading valid product
250+ heightConstraint? . isActive = false
251+ heightConstraint = nil
215252 }
216253
217254 internal func setup( ) { }
0 commit comments