diff --git a/packages/hippy_ui_react/src/components/UImage/index.tsx b/packages/hippy_ui_react/src/components/UImage/index.tsx index 2319e30..3afd683 100644 --- a/packages/hippy_ui_react/src/components/UImage/index.tsx +++ b/packages/hippy_ui_react/src/components/UImage/index.tsx @@ -16,18 +16,22 @@ export class UImage extends Component { }; } - componentDidUpdate(prevProps: UImageProps) { - if (prevProps.src !== this.props.src) { + shouldComponentUpdate(nextProps: Readonly, nextState: Readonly, nextContext: any): boolean { + if (this.props.src !== nextProps.src) { // 检测到图片有更新,需要重新加载 this.state.isError && this.setState({ isError: false, }); this.isLoad = false; + this.androidIgnoreLoadEnd = + Platform.OS === 'android' && this.props.src.startsWith('http') && !nextProps.src.startsWith('http'); } + return true; } private isLoad: boolean; + private androidIgnoreLoadEnd = false; // 安卓http切base64会马上触发一个onLoadEnd导致走到错误逻辑 static resizeMode = Image.resizeMode; onError = (e) => { @@ -45,6 +49,10 @@ export class UImage extends Component { }; onLoadEnd = () => { + if (this.androidIgnoreLoadEnd) { + this.androidIgnoreLoadEnd = false; + return; + } if (!this.isLoad && !this.state.isError) { this.setState({ isError: true,