GithubHelp home page GithubHelp logo

smallnew / react-native-smartassets Goto Github PK

View Code? Open in Web Editor NEW
27.0 2.0 10.0 648 KB

smart load react native image resource both from apk(ipa) and jsbundle Dir.

License: MIT License

Java 40.82% JavaScript 32.06% Objective-C 18.83% Ruby 8.29%
react-native codepush hot-reload imageloader assets-management

react-native-smartassets's Introduction

react-native-smartassets

Getting started

Smartassets change the react native image load logic by hook defaultAsset method.

Smartassets let your app can load image form apk(ipa in iOS case) and filesystem with smart choose.

before after

$ npm install --save react-native-smartassets

Mostly automatic installation

$ react-native link react-native-smartassets

Manual installation

iOS

  1. In XCode, in the project navigator, right click LibrariesAdd Files to [your project's name]
  2. Go to node_modulesreact-native-smartassets and add RNSmartassets.xcodeproj
  3. In XCode, in the project navigator, select your project. Add libRNSmartassets.a to your project's Build PhasesLink Binary With Libraries
  4. Run your project (Cmd+R)<

Android

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

Usage

import {SmartAssets} from 'react-native-smartassets';
SmartAssets.initSmartAssets();
SmartAssets.setiOSRelateMainBundlePath(youOriginJsBundlePath);//optional

react-native-smartassets's People

Contributors

smallnew avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

react-native-smartassets's Issues

iOS 热更后找不到主bundle的图片

Hi,IOS 热更后,现象如题

环境
ios 12.4.3
iphone 6plus
react native 0.61.5

初始化
`import {AppRegistry} from 'react-native';
import App from './App';
import {name as appName} from './app.json';

import {SmartAssets} from 'react-native-smartassets';
SmartAssets.initSmartAssets();

AppRegistry.registerComponent(appName, () => App);`

测试后发现 android 能正常显示,ios 则不能,没有找到合适的调试方法,就直接alert,最后发现
是路径拼接的有问题 ,我自己改了下,改好了,
改的地方如下

const defaultMainBundePath = Smartassets.DefaultMainBundlePath; // 原来被注释掉了,加回来
...
...
let oriJsBundleUrl = 'file://'+defaultMainBundePath+'/'+iOSRelateMainBundlePath + "/"; // 默认缺了一个 / 符号,加上

改动后,一切正常了

看下是不是还有更合适的方法

Android 使用后图片显示,ios还是不行

SmartAssets.setiOSRelateMainBundlePath('./ios/platform.ios.bundle');
SmartAssets.setiOSRelateMainBundlePath('./ios/index.ios.bundle');
试了这两种写法,都不行,大神指点一下奥

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.