How to use the react-native-fs.MainBundlePath function in react-native-fs

To help you get started, we’ve selected a few react-native-fs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github josephroquedev / campus-guide / src / util / Configuration.ts View on Github external
export async function setupDefaultConfiguration(os: PlatformOSType): Promise {
  let assetBasePath;
  let readDir;
  let copyFile;
  let configDetails: ConfigurationDetails;

  // Get functions and locations for Android vs iOS assets
  if (os === 'android') {
    assetBasePath = 'config';
    readDir = RNFS.readDirAssets;
    copyFile = RNFS.copyFileAssets;
    configDetails = JSON.parse(await RNFS.readFileAssets(`${assetBasePath}/base_config.json`));
  } else {
    assetBasePath = `${RNFS.MainBundlePath}/config.bundle`;
    readDir = RNFS.readDir;
    copyFile = RNFS.copyFile;
    configDetails = JSON.parse(await RNFS.readFile(`${assetBasePath}/base_config.json`));
  }

  // Create the config file directory
  await RNFS.mkdir(CONFIG_DIRECTORY);
  for (const type in CONFIG_SUBDIRECTORIES) {
    if (CONFIG_SUBDIRECTORIES.hasOwnProperty(type)) {
      await RNFS.mkdir(CONFIG_DIRECTORY + CONFIG_SUBDIRECTORIES[type]);
    }
  }

  // Copy base assets to config file directory
  const assetTypes = await readDir(assetBasePath);
  for (const type of assetTypes) {
github sonnylazuardi / bibleify-mobile / old / src / screens / Passage / PassageScreen.js View on Github external
() => {
        if (Platform.OS == "android") {
          RNFS.copyFileAssets(`${book}.realm.lock`, RNFS.DocumentDirectoryPath + `/${book}.realm.lock`);
          RNFS.copyFileAssets(`${book}.realm`, RNFS.DocumentDirectoryPath + `/${book}.realm`).then(() => {
            this.loadPassage();
            this._bottomSheet.close();
          });
        } else {
          try {
            RNFS.copyFile(
              RNFS.MainBundlePath + `/${book}.realm.lock`,
              RNFS.DocumentDirectoryPath + `/${book}.realm.lock`
            );
            RNFS.copyFile(
              RNFS.MainBundlePath + `/${book}.realm`,
              RNFS.DocumentDirectoryPath + `/${book}.realm`
            ).then(() => {
              this.loadPassage();
              this._bottomSheet.close();
            });
          } catch (e) {
            console.log("FILE ALREADY EXISTS");
          }
        }
      }
    );
github philipphecht / react-native-doc-viewer / example / DocViewerExample / index.ios.js View on Github external
* https://github.com/facebook/react-native
 * @flow
 */

import React, { Component } from 'react';
import {
  AppRegistry,
  StyleSheet,
  Text,
  View,
  Platform,
  Button
} from 'react-native';
import OpenFile from 'react-native-doc-viewer';
var RNFS = require('react-native-fs');
var SavePath = Platform.OS === 'ios' ? RNFS.MainBundlePath : RNFS.DocumentDirectoryPath;

export default class DocViewerExample extends Component {
  /*
  * Handle WWW File Method
  * fileType Default == "" you can use it, to set the File Extension (pdf,doc,xls,ppt etc) when in the Url the File Extension is missing.
  */
  handlePress = () => {
   OpenFile.openDoc([{
     url:"http://mail.hartl-haus.at/uploads/tx_hhhouses/htf13_classic153s(3_giebel_haus).jpg",
     fileName:"sample"
   }], (error, url) => {
      if (error) {
        console.error(error);
      } else {
        console.log(url)
      }
github PSPDFKit / react-native / samples / Catalog / Catalog.ios.js View on Github external
action: () => {
      const filename = "Annual Report.pdf";

      const path = RNFS.DocumentDirectoryPath + "/" + filename;
      const src = RNFS.MainBundlePath + "/PDFs/" + filename;

      RNFS.exists(path)
        .then(exists => {
          if (!exists) {
            return RNFS.copyFile(src, path);
          }
        })
        .then(() => {
          PSPDFKit.present(path, {});
          PSPDFKit.setPageIndex(3, false);
        })
        .catch(err => {
          console.log(err.message, err.code);
        });
    }
  },
github sonnylazuardi / bibleify-mobile / src / models / bible.ts View on Github external
loadVersion(payload, rootState) {
      const activeVersion = rootState.bible.activeVersion.value;
      if (Platform.OS == 'ios') {
        RNFS.copyFile(
          RNFS.MainBundlePath + `/${activeVersion}.realm`,
          RNFS.DocumentDirectoryPath + `/${activeVersion}.realm`,
        );
      } else {
        RNFS.copyFileAssets(`${activeVersion}.realm`, `${RNFS.DocumentDirectoryPath}/${activeVersion}.realm`);
      }
    },
    fetchVerses(payload, rootState) {
github phodal / growth / src / components / HtmlView.js View on Github external
componentDidMount() {
    if (this.props.type === NET) {
      Api.get(this.props.url)
        .then(response => this.setState({
          visible: false,
          html: MarkdownHelper.convert(response.data) }))
        .catch(err => this.setState({
          visible: false,
          html: err.message,
        }));
    } else {
      const basePath = Platform.OS === 'ios'
        ? RNFS.MainBundlePath
        : RNFS.ExternalDirectoryPath;
      if (basePath) {
        let slug = '';
        if (this.props.isFullSlug) {
          slug = this.props.slug;
        } else {
          slug = `/growth-content/${this.props.domain}/${this.props.slug}.html`;
        }

        RNFS.readFile(basePath.concat(slug), 'utf8')
          .then((result) => {
            this.setState({
              html: result,
              visible: false,
            });
          });
github philipshurpik / react-native-source-maps / index.js View on Github external
const createSourceMapper = async () => {
	const path = `${RNFS.MainBundlePath}/${options.sourceMapBundle}`;
	try {
		const fileExists = await RNFS.exists(path);
		if (!fileExists) {
			throw new Error(__DEV__ ?
				'Unable to read source maps in DEV mode' :
				`Unable to read source maps, possibly invalid sourceMapBundle file, please check that it exists here: ${RNFS.MainBundlePath}/${options.sourceMapBundle}`
			);
		}

		const mapContents = await RNFS.readFile(path, 'utf8');
		const sourceMaps = JSON.parse(mapContents);
		const mapConsumer = new SourceMap.SourceMapConsumer(sourceMaps);

		return sourceMapper = row => {
			return mapConsumer.originalPositionFor({
				line: row.lineNumber,
				column: row.columnNumber,
			});
		};
	}
	catch (error) {
		throw error;