RCTCPDFViewManager.swift 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. //
  2. // RCTCPDFViewManager.swift
  3. // react-native-compdfkit-pdf
  4. //
  5. // Copyright © 2014-2024 PDF Technologies, Inc. All Rights Reserved.
  6. //
  7. // THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
  8. // AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT.
  9. // UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
  10. // This notice may not be removed from this file.
  11. //
  12. import UIKit
  13. import ComPDFKit
  14. @objc(RCTCPDFReaderView)
  15. class RCTCPDFReaderView: RCTViewManager, RCTCPDFViewDelegate {
  16. @objc override static func requiresMainQueueSetup() -> Bool {
  17. return true
  18. }
  19. var cpdfViews: Dictionary<Int, RCTCPDFView> = [:]
  20. @objc override func view() -> UIView! {
  21. let rtcCPDFView = RCTCPDFView()
  22. rtcCPDFView.delegate = self
  23. return rtcCPDFView
  24. }
  25. func saveDocument(forCPDFViewTag tag: Int, completionHandler: @escaping (Bool) -> Void) {
  26. let rtcCPDFView = cpdfViews[tag]
  27. rtcCPDFView?.saveDocument(completionHandler: { success in
  28. completionHandler(success)
  29. })
  30. }
  31. // MARK: - RCTCPDFViewDelegate
  32. func cpdfViewAttached(_ cpdfView: RCTCPDFView) {
  33. cpdfViews[cpdfView.reactTag.intValue] = cpdfView
  34. }
  35. }