短视频系统源码,上传图片自适应拉伸符合高度
短视频系统源码,上传图片自适应拉伸符合高度实现的相关代码
import React, { useState, useEffect } from 'react';
import { Image } from 'react-native';
export default ({ source = {}, style = {}, width = 0 }) => {
const [height, setHeight] = useState(100);
useEffect(() => {
if (source.uri) {
// 网络图
Image.getSize(source.uri, (w, h) => {
setHeight((width * h) / w);
});
} else {
// 本地图
const result = Image.resolveAssetSource(source);
let h = result.height;
let w = result.width;
const finalHeight = (width * h) / w;
setHeight(finalHeight);
}
}, [source, width]);
return <Image style={[style, { height, width }]} source={source} />;
};
以上就是短视频系统源码,上传图片自适应拉伸符合高度实现的相关代码, 更多内容欢迎关注之后的文章