import SwiftUI import UIKit struct RefreshableScrollView: UIViewRepresentable { var content: Content var onRefresh: (UIRefreshControl) -> Void var isRefreshing: Binding init(isRefreshing: Binding, onRefresh: @escaping (UIRefreshControl) -> Void, @ViewBuilder content: () -> Content) { self.content = content() self.onRefresh = onRefresh self.isRefreshing = isRefreshing } func makeUIView(context: Context) -> UIScrollView { let scrollView = UIScrollView() // Создаем UIRefreshControl и добавляем его let refreshControl = UIRefreshControl() refreshControl.addTarget(context.coordinator, action: #selector(Coordinator.handleRefresh), for: .valueChanged) scrollView.refreshControl = refreshControl // Создаем хостинг для нашего SwiftUI контента let hostingController = UIHostingController(rootView: content) hostingController.view.translatesAutoresizingMaskIntoConstraints = false scrollView.addSubview(hostingController.view) // Настраиваем Auto Layout NSLayoutConstraint.activate([ hostingController.view.leadingAnchor.constraint(equalTo: scrollView.contentLayoutGuide.leadingAnchor), hostingController.view.trailingAnchor.constraint(equalTo: scrollView.contentLayoutGuide.trailingAnchor), hostingController.view.topAnchor.constraint(equalTo: scrollView.contentLayoutGuide.topAnchor), hostingController.view.bottomAnchor.constraint(equalTo: scrollView.contentLayoutGuide.bottomAnchor), hostingController.view.widthAnchor.constraint(equalTo: scrollView.frameLayoutGuide.widthAnchor) ]) context.coordinator.hostingController = hostingController return scrollView } func updateUIView(_ uiView: UIScrollView, context: Context) { // Обновляем состояние индикатора if isRefreshing.wrappedValue { uiView.refreshControl?.beginRefreshing() } else { uiView.refreshControl?.endRefreshing() } // Обновляем SwiftUI View, если нужно context.coordinator.hostingController?.rootView = content } func makeCoordinator() -> Coordinator { Coordinator(self) } class Coordinator: NSObject { var parent: RefreshableScrollView var hostingController: UIHostingController? init(_ parent: RefreshableScrollView) { self.parent = parent } @objc func handleRefresh(_ sender: UIRefreshControl) { parent.isRefreshing.wrappedValue = true parent.onRefresh(sender) } } }