Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: rpander93/react-native-document-opener
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.2.0
Choose a base ref
...
head repository: rpander93/react-native-document-opener
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
  • 3 commits
  • 2 files changed
  • 1 contributor

Commits on May 21, 2021

  1. Copy the full SHA
    230c272 View commit details

Commits on May 26, 2021

  1. Copy the full SHA
    18852f5 View commit details
  2. chore: release 1.0.0

    rpander93 committed May 26, 2021
    Copy the full SHA
    b635b68 View commit details
Showing with 14 additions and 20 deletions.
  1. +13 −19 ios/DocumentOpener.swift
  2. +1 −1 package.json
32 changes: 13 additions & 19 deletions ios/DocumentOpener.swift
Original file line number Diff line number Diff line change
@@ -2,45 +2,39 @@ import UIKit

@objc(DocumentOpener)
class DocumentOpener: NSObject, UIDocumentInteractionControllerDelegate {
var documentController: UIDocumentInteractionController?

@objc(openAsync:mimeType:resolve:reject:)
func openAsync(_ filePath: String, mimeType: String?, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
documentController = UIDocumentInteractionController(url: URL.init(fileURLWithPath: filePath))
documentController?.delegate = self
DispatchQueue.main.async { [weak self] in
if self?.documentController?.presentPreview(animated: true) == true {
let documentController = UIDocumentInteractionController(url: URL.init(fileURLWithPath: filePath))
documentController.delegate = self

DispatchQueue.main.async {
if documentController.presentPreview(animated: true) {
resolve(nil)
} else {
reject("EINVAL", "Document is not supported", nil)
}
}
}

@objc(presentOptionsAsync:resolve:reject:)
func presentOptionsAsync(_ filePath: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
documentController = UIDocumentInteractionController(url: URL.init(fileURLWithPath: filePath))
documentController?.delegate = self
DispatchQueue.main.async { [weak self] in
let documentController = UIDocumentInteractionController(url: URL.init(fileURLWithPath: filePath))
documentController.delegate = self

DispatchQueue.main.async {
let rectangle = CGRect(x: 0, y: 0, width: 0, height: 0)
let root = UIApplication.shared.delegate!.window!!.rootViewController!

if self?.documentController?.presentOptionsMenu(from: rectangle, in: root.view, animated: true) == true {
if documentController.presentOptionsMenu(from: rectangle, in: root.view, animated: true) {
resolve(nil)
} else {
reject("EINVAL", "Document is not supported", nil)
}
}
}

// MARK: -UIDocumentInteractionControllerDelegate
func documentInteractionControllerViewControllerForPreview(_ controller: UIDocumentInteractionController) -> UIViewController {
return UIApplication.shared.delegate!.window!!.rootViewController!
}

func documentInteractionControllerDidEndPreview(_ controller: UIDocumentInteractionController) {
self.documentController = nil
return RCTPresentedViewController()!
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-document-opener",
"version": "0.2.0",
"version": "1.0.0",
"description": "Opens documents with their native previewers on Android and iOS",
"main": "lib/commonjs/index",
"module": "lib/module/index",