exponea / exponea-ios-sdk

MIT License
19 stars 27 forks source link

Freeze UI using StaticInAppContentBlockView on SwiftUI. #72

Closed MRSorokinMaxim closed 2 weeks ago

MRSorokinMaxim commented 2 weeks ago

I use SwiftUI. I have problem. when I open screen with InAppContentView, I get a freeze view.

struct InAppContentView: View {
  let id: String
  @State private var height: CGFloat = 0
  @State private var isHidden = false

  var body: some View {
    if !isHidden {
      AppContentBlockView(
        id: id,
        height: $height,
        onClose: {
          isHidden = true
        })
      .frame(height: height)
    }
  }
}

struct AppContentBlockView: UIViewRepresentable {
  var id: String
  @Binding var height: CGFloat
  var onClose: () -> Void

  func makeUIView(context: Context) -> StaticInAppContentBlockView {
    let placeholder = StaticInAppContentBlockView(
      placeholder: id,
      deferredLoad: true,
      heightCompletion: { height in
          self.height = CGFloat(height)
    })
    placeholder.behaviourCallback = CustomBehaviourCallback(
      placeholder.behaviourCallback,
      context.coordinator
    )

    placeholder.reload()
    return placeholder
  }

  func updateUIView(_ uiView: StaticInAppContentBlockView, context: Context) {}

  func makeCoordinator() -> InAppCoordinator {
    InAppCoordinator(onClose: onClose)
  }
}
MRSorokinMaxim commented 2 weeks ago

The problem is no longer reproducible on version 2.26.2