Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(web): fix image local path #4095

Merged
merged 4 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions examples/hippy-react-demo/scripts/hippy-webpack.web-renderer.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const fs = require('fs');
const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
Expand Down Expand Up @@ -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;
})(),
},
};
7 changes: 0 additions & 7 deletions packages/hippy-react/src/modules/animation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,13 +265,6 @@ class Animation implements Animation {
Bridge.callNative('AnimationModule', 'pauseAnimation', this.animationId);
}

/**
* Stop the running animation
*/
public stop() {
Bridge.callNative('AnimationModule', 'stopAnimation', this.animationId);
}

/**
* Resume execution of paused animation
*/
Expand Down
22 changes: 14 additions & 8 deletions packages/hippy-web-renderer/src/component/image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ export class Image extends HippyWebView<HTMLImageElement|HTMLElement> {
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) {
Expand Down Expand Up @@ -108,17 +115,14 @@ export class Image extends HippyWebView<HTMLImageElement|HTMLElement> {

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]) {
Expand All @@ -145,10 +149,12 @@ export class Image extends HippyWebView<HTMLImageElement|HTMLElement> {
}

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;
Expand Down Expand Up @@ -190,12 +196,12 @@ export class Image extends HippyWebView<HTMLImageElement|HTMLElement> {
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() {
Expand Down
Loading