diff --git a/examples/hippy-react-demo/scripts/hippy-webpack.web-renderer.js b/examples/hippy-react-demo/scripts/hippy-webpack.web-renderer.js index d15bec933fd..8b8d09d914c 100644 --- a/examples/hippy-react-demo/scripts/hippy-webpack.web-renderer.js +++ b/examples/hippy-react-demo/scripts/hippy-webpack.web-renderer.js @@ -1,3 +1,4 @@ +const fs = require('fs'); const path = require('path'); const webpack = require('webpack'); const HtmlWebpackPlugin = require('html-webpack-plugin'); @@ -78,5 +79,20 @@ module.exports = { resolve: { extensions: ['.js', '.jsx', '.json'], modules: [path.resolve(__dirname, '../node_modules')], + alias: (() => { + const aliases = {}; + // If @hippy/web-renderer was built exist in packages directory then make an alias + // Remove the section if you don't use it + const webRendererPath = path.resolve(__dirname, '../../../packages/hippy-web-renderer/dist'); + if (fs.existsSync(path.resolve(webRendererPath, 'index.js'))) { + console.warn(`* Using the @hippy/web-renderer in ${webRendererPath} as @hippy/web-renderer alias`); + aliases['@hippy/web-renderer'] = webRendererPath; + } else { + console.warn('* Using the @hippy/web-renderer defined in package.json'); + } + + + return aliases; + })(), }, }; diff --git a/packages/hippy-web-renderer/src/component/image.ts b/packages/hippy-web-renderer/src/component/image.ts index afd6437cbed..e3585dcb6df 100644 --- a/packages/hippy-web-renderer/src/component/image.ts +++ b/packages/hippy-web-renderer/src/component/image.ts @@ -63,6 +63,13 @@ export class Image extends HippyWebView { return { boxSizing: 'border-box', zIndex: 0 }; } + public replaceHpfile(value: string) { + if (value && /^(hpfile):\/\//.test(value) && value.indexOf('assets') > -1) { + return value.replace('hpfile://./', ''); + } + return value ?? ''; + } + public set tintColor(value) { this.props[NodeProps.TINY_COLOR] = value; if (value !== undefined && value !== 0) { @@ -108,17 +115,14 @@ export class Image extends HippyWebView { public get src() { const value = this.props[NodeProps.SOURCE]; - if (value && /^(hpfile):\/\//.test(value) && value.indexOf('assets') > -1) { - return value.replace('hpfile://./', ''); - } - - return value ?? ''; + return this.replaceHpfile(value); } public set src(value: string) { if (value && this.src === value) { return; } + value = this.replaceHpfile(value); this.props[NodeProps.SOURCE] = value ?? ''; if (value && value !== this.props[NodeProps.DEFAULT_SOURCE]) { @@ -145,10 +149,12 @@ export class Image extends HippyWebView { } public get defaultSource() { - return this.props[NodeProps.DEFAULT_SOURCE]; + const value = this.props[NodeProps.DEFAULT_SOURCE]; + return this.replaceHpfile(value); } public set defaultSource(value: string) { + value = this.replaceHpfile(value); this.props[NodeProps.DEFAULT_SOURCE] = value; if (!this.isLoadSuccess) { this.renderImgDom!.src = value; @@ -190,12 +196,12 @@ export class Image extends HippyWebView { private handleLoad(_event: Event, loadUrl?: string) { this.isLoadSuccess = false; if ((!loadUrl && this.renderImgDom?.src === this.src) || loadUrl === this.src) { - this.onLoad(null); + this.onLoad({}); if (this.renderImgDom?.src !== this.src) { this.renderImgDom!.src = this.src; } } - this.onLoadEnd(null); + this.onLoadEnd({}); } private buildTintDomContainer() {