ladas-larry/react-native-responsive-image
关于
适用于 React Native 的响应式图像组件
网站与应用开发实测星标增长
- 24小时
- 0
- 7天
- 0
- 15天
- 0
- 1个月
- 正在收集历史
各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。
README.md
原文React Native Responsive Image
Why?
React Native's Image size is rendered with the same dimensions regardless of device screen size and screen resolution. That's bad. This component scales itself seemlesly on all iOS and Android devices.
Installation
npm install react-native-responsive-image --save
Usage
<ResponsiveImage> is expecting initWidth and initHeight props.
These values are used to set image size on any device that has screen size iPhone Plus, or larger. Image is then scaled down for any smaller device.
Optional prop component is used to pass down either an Image or ImageBackground imported react-native (defaults to Image if not provided)
Example
import React, { Component } from "react";
import { AppRegistry, StyleSheet, View } from "react-native";
import ResponsiveImage from "react-native-responsive-image";
class App extends Component {
render() {
return (
<View
style={{
flexGrow: 1,
justifyContent: "center",
alignItems: "center",
flexDirection: "row"
}}
>
<ResponsiveImage
source={{ uri: "https://reactjs.org/logo-og.png" }}
initWidth="138"
initHeight="138"
/>
<ResponsiveImage
source={{ uri: "https://reactjs.org/logo-og.png" }}
initWidth="138"
initHeight="138"
/>
<ResponsiveImage
source={{ uri: "https://reactjs.org/logo-og.png" }}
initWidth="138"
initHeight="138"
/>
</View>
);
}
}
AppRegistry.registerComponent("ResponsiveImageExample", () => App);
For initWidth=138 it looks like this:
| Device | Screen width | Scale | <Image> width |
|---|---|---|---|
| iPhone SE | 320 | 0.77 | 106 |
| iPhone X | 375 | 0.902 | 117 |
| iPhone8 Plus | 414 | 1 | 138 |
| Nokia 5 | 360 | 0.87 | 120 |
| iPad (or any tablet) | - | 1 | 138 |
Just one image?
It sounds like you could save some loading by delivering low resolution images to screens with lower resolution. The best way is to serve just one high-resolution (retina) well compressed image. It’s surprising how well they can be compressed, and the result looks the same.

Example project
Create project
expo init ResponsiveImageExample
- go with 'expo-template-blank'
cp ./example/App.js ./ResponsiveImageExample/App.js
cp -R ./src ./ResponsiveImageExample
cd ResponsiveImageExample
yarn start
Development
Modify any files in ./src directory
Propagate changes by
cp -R ./src ./ResponsiveImageExample/src
探索相关项目
加载中…