Socket
Socket
Sign inDemoInstall

react-native-file-selector

Package Overview
Dependencies
0
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    react-native-file-selector

React Native: Native File Selector


Version published
Weekly downloads
29
decreased by-14.71%
Maintainers
1
Install size
404 kB
Created
Weekly downloads
 

Readme

Source

PRs Welcome

ReactNative: Native File Selector (Android/iOS)

If this project has helped you out, please support us with a star 🌟

This library is a ReactNative Bridge around native libraries. It allows you to natively select/pick file from device file system:

Android: nbsp-team/MaterialFilePicker/

Note: It allows you to pick file without using Intent/Third Party Software

iOS: marmelroy/FileBrowser

Note: It allows you to select only local files associate to app sandbox.

📖 Getting started

$ npm install react-native-file-selector --save

RN60 >= RNFS V1 >

RN60 above please use react-native-file-selector V1 and above

  • iOS

iOS Prerequisite: Please make sure CocoaPods is installed on your system

- Add the following to your `Podfile` -> `ios/Podfile` and run pod update:
  use_native_modules!

  pod 'RNFileSelector', :path => '../node_modules/react-native-file-selector/ios'

  use_frameworks! :linkage => :static

  pod 'FileBrowser', :git => 'https://github.com/prscX/FileBrowser'

  # Follow [Flipper iOS Setup Guidelines](https://fbflipper.com/docs/getting-started/ios-native)
  # This is required because iOSPhotoEditor is implemented using Swift and we have to use use_frameworks! in Podfile
  $static_framework = ['FlipperKit', 'Flipper', 'Flipper-Folly',
    'CocoaAsyncSocket', 'ComponentKit', 'Flipper-DoubleConversion',
    'Flipper-Glog', 'Flipper-PeerTalk', 'Flipper-RSocket', 'Yoga', 'YogaKit',
    'CocoaLibEvent', 'OpenSSL-Universal', 'boost-for-react-native']
  
  pre_install do |installer|
    Pod::Installer::Xcode::TargetValidator.send(:define_method, :verify_no_static_framework_transitive_dependencies) {}
    installer.pod_targets.each do |pod|
        if $static_framework.include?(pod.name)
          def pod.build_type;
            Pod::BuildType.static_library
          end
        end
      end
  end
  • Please make sure Flipper iOS Setup Guidelines steps are added to Podfile, since iOSPhotoEditor is implemented using Swift and we have to use use_frameworks! in Podfile

  • Android

  • Add below color attributes in your app's android/app/src/main/res/values/color.xml file. You can provide your own color codes.

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
        <color name="colorPrimary">#3F51B5</color>
        <color name="colorPrimaryDark">#303F9F</color>
        <color name="colorAccent">#FF4081</color>
    </resources>

RN60 < RNFS V1 <

RN60 below please use react-native-file-selector V.0.*

$ react-native link react-native-file-selector

Android
  • Add below snippet in your app build.gradle file
repositories {
    maven {
        url  "http://dl.bintray.com/lukaville/maven"
    }
    maven { url "https://maven.google.com" }
    ...
}

allprojects {
    repositories {
        mavenLocal()
        jcenter()
        maven { url "https://maven.google.com" }
        ...
    }
}

Note: This library is supported Android 27 > above

  • Add below color attributes in your app res/color.xml. You can provide your own color codes
    <color name="colorPrimary">#3F51B5</color>
    <color name="colorPrimaryDark">#303F9F</color>
    <color name="colorAccent">#FF4081</color>
iOS
  • After react-native link react-native-file-selector, please verify node_modules/react-native-file-selector/ios/ contains Pods folder. If does not exist please execute pod install command on node_modules/react-native-file-selector/ios/, if any error => try pod repo update then pod install

  • After verification, open your project and create a folder 'RNFileSelector' under Libraries.

  • Drag node_modules/react-native-file-selector/ios/pods/Pods.xcodeproject into RNFileSelector, as well as the RNFileSelector.xcodeproject if it does not exist.

  • Add the FileBrowser.framework into your project's Embedded Binaries and make sure the framework is also in linked libraries.

  • Go to your project's Build Settings -> Frameworks Search Path and add ${BUILT_PRODUCTS_DIR}/FileBrowser non-recursive.

  • Add below snippet in your app AppDelegate.m. This basically adds navigation controller in order to push list of files screen

  UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:rootViewController];
  navigationController.navigationBar.hidden = YES;

  self.window.rootViewController = navigationController;

//  self.window.rootViewController = rootViewController;

  • Now build your iOS app through Xcode

💻 Usage

import RNFileSelector from 'react-native-file-selector';

  • API Way
RNFileSelector.Show(
    {
        title: 'Select File',
        onDone: (path) => {
            console.log('file selected: ' + path)
        },
        onCancel: () => {
            console.log('cancelled')
        }
    }
)
  • React Way
<RNFileSelector title={"Select File"} visible={this.state.visible} onDone={() => {
    console.log("file selected: " + path);
}} onCancel={() => {
    console.log("cancelled");
}}/>

💡 Props

PropTypeDefaultNote
titlestringTitle on the toolbar
closeMenustringtrueColor of tint
hiddenFiles: AndroidboolfalseIf true it shows hidden files as well
pathstringPath of directory
filterstringFilter to sort the files
filterDirectories: AndroidboolFilter should be applied on directories or not
onDonefuncFunction called when file is selected
onCancelfuncFunction called when file selector is closed without selecting any file
visibleboolfalseTo invoke file selector

Note

  • Filter
    • Android: Please find regex/Pattern for defining filter
    • iOS: Array of file extension needs to be ignore

✨ Credits

🤔 How to contribute

Have an idea? Found a bug? Please raise to ISSUES. Contributions are welcome and are greatly appreciated! Every little bit helps, and credit will always be given.

💫 Where is this library used?

If you are using this library in one of your projects, add it in this list below. ✨

📜 License

This library is provided under the Apache License.

RNFileSelector @ prscX

💖 Support my projects

I open-source almost everything I can, and I try to reply everyone needing help using these projects. Obviously, this takes time. You can integrate and use these projects in your applications for free! You can even change the source code and redistribute (even resell it).

However, if you get some profit from this or just want to encourage me to continue creating stuff, there are few ways you can do it:

  • Starring and sharing the projects you like 🚀

  • If you're feeling especially charitable, please follow prscX on GitHub.

    Buy Me A Coffee

    Thanks! ❤️
    prscX.github.io
    </ Pranav >

Keywords

FAQs

Last updated on 01 Jul 2021

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc