All Projects → IgorBelyayev → React-Native-Local-Resource

IgorBelyayev / React-Native-Local-Resource

Licence: MIT license
Easily load string files in React-Native

Programming Languages

objective c
16641 projects - #2 most used programming language
java
68154 projects - #9 most used programming language
javascript
184084 projects - #8 most used programming language
python
139335 projects - #7 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to React-Native-Local-Resource

Create React Native App
Create React Native apps that run on iOS, Android, and web
Stars: ✭ 12,846 (+42720%)
Mutual labels:  react-native-web
react-native-web-expo-boilerplate
I am no longer in maintenance
Stars: ✭ 64 (+113.33%)
Mutual labels:  react-native-web
react-native-expo-web
All-in-one React Native project (Expo + react-native-web)
Stars: ✭ 16 (-46.67%)
Mutual labels:  react-native-web
Margarita
[not actively maintained] Mobile and Web application implementing Kiwi.com Tequila API
Stars: ✭ 213 (+610%)
Mutual labels:  react-native-web
react-bones
💀 Dead simple content loading components for React and React-Native. 💀
Stars: ✭ 42 (+40%)
Mutual labels:  react-native-web
create-react-native-dapp
Your next Ethereum application starts here. ⚛️ 💪 🦄
Stars: ✭ 410 (+1266.67%)
Mutual labels:  react-native-web
Svgs
svgs is a compatiblity layer between svg and react-native-svg
Stars: ✭ 182 (+506.67%)
Mutual labels:  react-native-web
react-native-hybrid-storybook
Showcase your react native components in the browser
Stars: ✭ 18 (-40%)
Mutual labels:  react-native-web
react-native-web-playground
A React Native Web app with bunch of other stuffs and challenging UI's
Stars: ✭ 19 (-36.67%)
Mutual labels:  react-native-web
moox
MoOx personal website
Stars: ✭ 33 (+10%)
Mutual labels:  react-native-web
Awesome React Native Web
💙 React Native Web patterns, techniques, tips, and tricks ✨
Stars: ✭ 215 (+616.67%)
Mutual labels:  react-native-web
Pillar Valley
👾A cross-platform video game built with Expo, three.js, and Firebase! 🎮🕹
Stars: ✭ 242 (+706.67%)
Mutual labels:  react-native-web
expo-next-monorepo-example
Create a universal React app using Expo and Next.js in a monorepo
Stars: ✭ 268 (+793.33%)
Mutual labels:  react-native-web
Fullstack
React/ApolloGraphQL/Node/Mongo demo written in Typescript
Stars: ✭ 12,653 (+42076.67%)
Mutual labels:  react-native-web
react-native-swag-toggle
A Swag Toggle for React Native and Expo Web
Stars: ✭ 14 (-53.33%)
Mutual labels:  react-native-web
React Native Confetti Cannon
React Native confetti explosion and fall like iOS does.
Stars: ✭ 149 (+396.67%)
Mutual labels:  react-native-web
pulsar-core
🚀 Handy dynamic styles utilities for React Native and React Native Web.
Stars: ✭ 27 (-10%)
Mutual labels:  react-native-web
paramount
React Component Library for React Native and React Web
Stars: ✭ 23 (-23.33%)
Mutual labels:  react-native-web
razzle-afterjs-redux-rnw-example
Razzle + After.js + Redux + React Native Web (RNW) Example
Stars: ✭ 21 (-30%)
Mutual labels:  react-native-web
apple-notes
A clone of the Apple Notes app but made universally with Expo
Stars: ✭ 53 (+76.67%)
Mutual labels:  react-native-web

React-Native-Local-Resource

This library allows you to include resources of any type in your javascript source folders and load them without having to do anything special. It supports iOS and Android, including Android release mode.

Getting started

$ yarn add react-native-local-resource

or

$ npm install react-native-local-resource --save

Mostly automatic installation

Native installation is required to support Android release mode.

$ react-native link react-native-local-resource

Manual installation

Android

  1. Open up android/app/src/main/java/[...]/MainActivity.java
  • Add import com.igorbelyayev.rnlocalresource.RNLocalResourcePackage; to the imports at the top of the file
  • Add new RNLocalResourcePackage() to the list returned by the getPackages() method
  1. Append the following lines to android/settings.gradle:
    include ':react-native-local-resource'
    project(':react-native-local-resource').projectDir = new File(rootProject.projectDir, 	'../node_modules/react-native-local-resource/android')
    
  2. Insert the following lines inside the dependencies block in android/app/build.gradle:
      compile project(':react-native-local-resource')
    

iOS

Not required.

Usage

Specify file extensions

Specifying which file extensions you want to support is slightly different depending on which version of React Native your project is using.

React Native versions >= 0.59

You will need a metro.config.js file in order to use this library. You should already probably have this file in your root project directory, but if you don't, create it.

Then, inside a module.exports object, create a key called resolver with another object with a key called assetExts. The value of assetExts should be an array of the resource file extensions you want to support.

For example, if you want to support md and txt files, your metro.config.js would like like this:

module.exports = {
    resolver: {
        assetExts: ["md", "txt"]
    }
}
React Native versions >= 0.57 and < 0.59

You will need a rn-cli.config.js file in order to use this library. Check your root project directory to see if you already have this file and if you don't, create it.

Then, inside a module.exports object, create a key called resolver with another object with a key called assetExts. The value of assetExts should be an array of the resource file extensions you want to support.

For example, if you want to support md and txt files, your rn-cli.config.js would like like this:

module.exports = {
    resolver: {
        assetExts: ["md", "txt"]
    }
}
React Native versions < 0.57

You will need a rn-cli.config.js file in order to use this library. Check your root project directory to see if you already have this file and if you don't, create it.

Then, inside a module.exports object, create a function called getAssetExts which returns an array of the resource file extensions you want to support.

For example, if you want to support md and txt files, your rn-cli.config.js would like like this:

module.exports = {
    getAssetExts() {
        return ["md", "txt"]
    }
}

Calling the library

The library exposes a single async function which accepts the source of the resource as the argument and returns the string content of the resource.

Example usage:

import loadLocalResource from 'react-native-local-resource'
import myResource from './my_resource.txt'

function example() {
    loadLocalResource(myResource).then((myResourceContent) => {
            console.log("myResource was loaded: " + myResourceContent)
        }
    )
}

Demo Project

This repo contains a demo project in the demo_project folder.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].