Skip to content
This repository has been archived by the owner on Apr 25, 2023. It is now read-only.

Replace file selector with home-grown dep #24

Closed
crutchcorn opened this issue Jun 20, 2020 · 3 comments
Closed

Replace file selector with home-grown dep #24

crutchcorn opened this issue Jun 20, 2020 · 3 comments
Labels
bug Something isn't working design Updates or fixes to the UI / UX enhancement New feature or request
Milestone

Comments

@crutchcorn
Copy link
Member

crutchcorn commented Jun 20, 2020

We currently have a dependency on react-native-file-selector. However, there are numerous issues with the dependency for what we're looking for.

First: The package does not support directory picking currently. You may wonder how this can be if we have a working dialog picker. This is because I've forked the package, which I am using in the package.json of this app. This fork simply merges in this PR of an upstream dependency, and hosts it via GitHub and uses JitPack to install it as an Android dependency

This wouldn't inherently be a problem on it's own (despite its hacky nature), however there serves two additional problem:

  • It breaks on iOS. Plain and simply, I have no idea how to work around this issue. This is the single reason we're unable to build GitShark for iOS currently.

  • It doesn't respect system dark mode currently. While there is likely work I could do upstream to solve for this, it wouldn't be a pretty solution.

  • Finally, and this is a big one, @PrattiDev doesn't like the design of the selector on Android.

As such, I intend to create a new react-native- package that will provide only a single functionality: Selecting directories.

It seems that there are respective APIs for iOS:

As well as on Android:

(although the Android API includes remote sources. This can be worked around using Intent(Intent.ACTION_OPEN_DOCUMENT_TREE).apply { setExtra(Intent.EXTRA_LOCAL_ONLY, true) }

@crutchcorn crutchcorn added bug Something isn't working enhancement New feature or request design Updates or fixes to the UI / UX labels Jun 20, 2020
@crutchcorn crutchcorn added this to the Mobile Beta 1 milestone Jun 20, 2020
@crutchcorn crutchcorn pinned this issue Jul 4, 2020
@crutchcorn
Copy link
Member Author

Saving Swift example code that I was given on the Swift Discord:

class SharkDirectoryPicker: NSObject, UIDocumentPickerDelegate {
  fileprivate var resultClosure: ((Result<[URL], NSError>) -> ())? = nil
  fileprivate static var shared: SharkDirectoryPicker = .init()
    
  func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) {
        resultClosure?(.success(urls))
  }
  
  func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentAt url: URL) {
  }

  func documentPickerWasCancelled(_ controller: UIDocumentPickerViewController) {
        let cancelError = NSError(domain: "", code: 0, userInfo: nil)
        resultClosure?(.failure(cancelError))
  }

  public static func pickFolder(completion: @escaping ((Result<[URL], NSError>) -> ())) {

    let documentPicker =
        UIDocumentPickerViewController(documentTypes: [kUTTypeFolder as String],
                                       in: .open)
        shared.resultClosure = completion
        documentPicker.delegate = shared
        topMostViewController()?.present(documentPicker, animated: true, completion: nil)
   }
    
   fileprivate static func topMostViewController() -> UIViewController? {
        var ret: UIViewController? = UIApplication.shared.keyWindow?.rootViewController
        repeat {
            if let presented = ret?.presentedViewController {
                ret = presented
            } else {
                break
            }
        } while(true)
        return ret
    }
}
  SharkDirectoryPicker.pickFolder { result in
            switch result {
            case .success(let urls):
                print("\(urls)")
            case .failure(let error):
                print("\(error)")
            }
        }

@crutchcorn crutchcorn unpinned this issue Aug 15, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working design Updates or fixes to the UI / UX enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant