mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-08-20 10:30:07 +00:00
zoom
This commit is contained in:
@@ -810,7 +810,7 @@ fileprivate struct GetStakeView: View {
|
||||
@EnvironmentObject var chatModel: ChatModel
|
||||
|
||||
var body: some View {
|
||||
ScrollView {
|
||||
ZoomablePageView {
|
||||
VStack(alignment: .leading, spacing: 18) {
|
||||
Text("Get a stake in SimpleX Chat")
|
||||
.font(.largeTitle)
|
||||
|
||||
@@ -58,3 +58,54 @@ struct ZoomableScrollView<Content: View>: UIViewRepresentable {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct ZoomablePageView<Content: View>: UIViewRepresentable {
|
||||
private var content: Content
|
||||
|
||||
init(@ViewBuilder content: () -> Content) {
|
||||
self.content = content()
|
||||
}
|
||||
|
||||
func makeUIView(context: Context) -> UIScrollView {
|
||||
let scrollView = UIScrollView()
|
||||
scrollView.delegate = context.coordinator
|
||||
scrollView.maximumZoomScale = 5
|
||||
scrollView.minimumZoomScale = 1
|
||||
scrollView.bouncesZoom = true
|
||||
scrollView.backgroundColor = .clear
|
||||
|
||||
let hostedView = context.coordinator.hostingController.view!
|
||||
hostedView.backgroundColor = .clear
|
||||
hostedView.translatesAutoresizingMaskIntoConstraints = false
|
||||
scrollView.addSubview(hostedView)
|
||||
NSLayoutConstraint.activate([
|
||||
hostedView.leadingAnchor.constraint(equalTo: scrollView.contentLayoutGuide.leadingAnchor),
|
||||
hostedView.trailingAnchor.constraint(equalTo: scrollView.contentLayoutGuide.trailingAnchor),
|
||||
hostedView.topAnchor.constraint(equalTo: scrollView.contentLayoutGuide.topAnchor),
|
||||
hostedView.bottomAnchor.constraint(equalTo: scrollView.contentLayoutGuide.bottomAnchor),
|
||||
hostedView.widthAnchor.constraint(equalTo: scrollView.frameLayoutGuide.widthAnchor)
|
||||
])
|
||||
|
||||
return scrollView
|
||||
}
|
||||
|
||||
func makeCoordinator() -> Coordinator {
|
||||
Coordinator(hostingController: UIHostingController(rootView: self.content))
|
||||
}
|
||||
|
||||
func updateUIView(_ uiView: UIScrollView, context: Context) {
|
||||
context.coordinator.hostingController.rootView = self.content
|
||||
}
|
||||
|
||||
class Coordinator: NSObject, UIScrollViewDelegate {
|
||||
var hostingController: UIHostingController<Content>
|
||||
|
||||
init(hostingController: UIHostingController<Content>) {
|
||||
self.hostingController = hostingController
|
||||
}
|
||||
|
||||
func viewForZooming(in scrollView: UIScrollView) -> UIView? {
|
||||
hostingController.view
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user