我正在尝试将图像(按图像全尺寸)添加到ScrollView
组件中,其想法是让图像具有自己的大小(不限制它),而是让水平和垂直滚动(取决于图像) . 所以我在Image.getSize()
a 中使用它ScrollView
,这是我的组件,
import React, { Component } from 'react';
import { Image, ScrollView } from 'react-native';
export default class App extends Component {
constructor(props) {
super(props);
this.state = {
width: 10,
height: 10,
image: 'http://www.francedimanche.fr/parole/wp-content/uploads/2017/08/Angelina-Jolie.png',
}
}
componentDidMount() {
Image.getSize(this.state.image, (width, height) => {
this.setState({ width, height });
});
}
render() {
return (
<ScrollView>
<Image
style={{ width: this.state.width, height: this.state.height }}
source={{uri: this.state.image}}
/>
</ScrollView>
);
}
}
谢谢!