Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

rax-image

Package Overview
Dependencies
Maintainers
8
Versions
121
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rax-image

Image component for Rax.

  • 1.1.2-1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
299
decreased by-24.69%
Maintainers
8
Weekly downloads
 
Created
Source

Image

npm

描述: Image用于展示图片

安装

$ npm install rax-image --save

引用

import Image from 'rax-image';

属性

注: 1、支持列表中的 browser代表h5 weex代表weex miniApp代表小程序

属性类型默认值** 必填 **描述** 支持 **
sourceObject: {uri: String}-true设置图片的 uriALL
styleObject: { width: Number height: Number }-true图片样式 width和height为必填属性,否则图片无法正常展示,可以补充其他属性ALL
fallbackSourceObject: {uri: String}-false备用图片的uri(当主图加载失败是加载)ALL
resizeModeString: 'contain' 'cover' 'stretch'-false决定当组件尺寸和图片尺寸不成比例的时候如何调整图片的大小ALL
qualityString: 'original' 'normal' 'low' 'high' 'auto'-false图片质量weex
placeholderString-false占位图的 URL,在图片下载过程中将展示占位图,图片下载完成后将显示source中指定的图片。weex
onLoadFunction-false图片加载成功的回调函数ALL
onErrorFunction-false图片加载失败的回调函数ALL

onLoad onError 返回

当完成图片加载成功/失败时,将分别触发onLoad/onError中的回调函数 function(event) => {}

weex下(iOS/Android)

成员类型** 描述**
successboolean标记图片是否成功加载,成功为1/true,失败为0/false
sizeobject加载的图片大小对象
size.naturalWidthnumber图片宽度,如果图片加载失败则为0/-1
size.naturalHeightnumber图片高度,如果图片加载失败则为0/-1

h5下是web原生的Event事件

成员类型** 描述**
targetDom图片自身元素
target.naturalWidthnumber图片宽度
target.naturalHeightnumber图片高度

示例

普通示例

import {createElement, render} from 'rax';
import DU from 'driver-universal';
import Image from '../src/index';

const App = () => {
  const imageRef = useRef(null);
  return (
    <Image
      ref={imageRef}
      source={{
        uri: 'https://gw.alicdn.com/tfs/TB1bBD0zCzqK1RjSZFpXXakSXXa-68-67.png',
      }}
      style={{
        height: '68',
        width: '67'
      }}
   />
  );
};

render(<App />, document.body, { driver: DU });

使用fallbackSource和resizeMode

import {createElement, render} from 'rax';
import DU from 'driver-universal';
import Image from '../src/index';

const App = () => {
  return (
    <Image
      source={{
        uri: 'https://gw.alicdn.com/tfs/TB1g6AvPVXXXXa7XpXXXXXXXXXX-215-215.png'
      }}
      fallbackSource={{
        uri: 'https://gw.alicdn.com/tps/i3/TB1yeWeIFXXXXX5XFXXuAZJYXXX-210-210.png_70x70.jpg'
      }}
      style={{
        width: 100,
        height: 100,
      }}
      resizeMode="cover"
    />
  );
};

render(<App />, document.body, { driver: DU });

Keywords

FAQs

Package last updated on 21 Sep 2019

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc