diff --git a/packages/f-my/examples/test/mini.project.json b/packages/f-my/examples/test/mini.project.json
index e4ce602..a78cf22 100644
--- a/packages/f-my/examples/test/mini.project.json
+++ b/packages/f-my/examples/test/mini.project.json
@@ -1,8 +1,10 @@
{
+ "format": 2,
+ "compileOptions": {
+ "component2": true,
+ "enableNodeModuleBabelTransform": true
+ },
"scripts": {
"beforeCompile": "npm run beforeCompile"
- },
- "enableNodeModuleBabelTransform": true,
- "component2": true,
- "enableAppxNg": true
+ }
}
\ No newline at end of file
diff --git a/packages/f-my/examples/test/pages/index/index.acss b/packages/f-my/examples/test/pages/index/index.acss
index c05f449..2614fcf 100644
--- a/packages/f-my/examples/test/pages/index/index.acss
+++ b/packages/f-my/examples/test/pages/index/index.acss
@@ -3,3 +3,8 @@
width: 100%;
height: 600rpx;
}
+
+.web-container {
+ width: 350rpx;
+ height: 480rpx;
+}
diff --git a/packages/f-my/examples/test/pages/index/index.axml b/packages/f-my/examples/test/pages/index/index.axml
index 787a2cf..c8c0cea 100644
--- a/packages/f-my/examples/test/pages/index/index.axml
+++ b/packages/f-my/examples/test/pages/index/index.axml
@@ -2,5 +2,8 @@
native
web
-
+
+
+
+
\ No newline at end of file
diff --git a/packages/f-my/examples/test/pages/index/rect.js b/packages/f-my/examples/test/pages/index/rect.js
index 98d2212..cd1a201 100644
--- a/packages/f-my/examples/test/pages/index/rect.js
+++ b/packages/f-my/examples/test/pages/index/rect.js
@@ -1,6 +1,5 @@
import { Component } from '@antv/f-engine';
-import { jsx as _jsx } from "@antv/f-engine/jsx-runtime";
-import { jsxs as _jsxs } from "@antv/f-engine/jsx-runtime";
+import { jsx as _jsx, jsxs as _jsxs } from "@antv/f-engine/jsx-runtime";
class Rect extends Component {
render() {
const {
diff --git a/packages/f-my/src/web.axml b/packages/f-my/src/web.axml
index 10027f3..37f246c 100644
--- a/packages/f-my/src/web.axml
+++ b/packages/f-my/src/web.axml
@@ -1,11 +1,10 @@
+/>
\ No newline at end of file
diff --git a/packages/f-my/src/web.tsx b/packages/f-my/src/web.tsx
index bf4bd39..6d89177 100644
--- a/packages/f-my/src/web.tsx
+++ b/packages/f-my/src/web.tsx
@@ -27,37 +27,21 @@ function dispatchEvent(el, event, type) {
el.dispatchEvent(event);
}
-const getPixelRatio = () => my.getSystemInfoSync().pixelRatio;
-
Component({
- props: {
- onRender: (_props) => {},
- // width height 会作为元素兜底的宽高使用
- width: null,
- height: null,
- onError: () => {},
- onCanvasReady: () => {},
- onCanvasRender: () => {},
- },
- /**
- * 组件创建时触发
- * 注意:
- * 使用该生命周期,项目配置需启用:"component2": true
- */
- onInit() {
- this.setCanvasId();
- },
didMount() {
- // 为了兼容未配置 "component2": true 的情况
- if (!this.data.id) {
- this.setCanvasId();
- }
- this.onCanvasReady();
+ this.createChart();
},
didUpdate() {
const { canvas, props } = this;
if (!canvas) return;
- const { theme, px2hd } = props;
+ const { theme, px2hd, reCreateOnUpdate } = props;
+ if (reCreateOnUpdate) {
+ canvas.destroy();
+ this.canvas = null;
+ this.createChart();
+ return;
+ }
+
const children = props.onRender(props);
const updateProps = {
theme,
@@ -74,52 +58,32 @@ Component({
canvas.destroy();
},
methods: {
- setCanvasId() {
- const pageId = (this.$page && this.$page.$id) || 0;
- const id = `f-canvas-${pageId}-${this.$id}`;
- this.setData({ id });
- },
- onCanvasReady() {
- const { onCanvasReady } = this.props;
- onCanvasReady && onCanvasReady();
- const { id } = this.data;
- const query = my.createSelectorQuery();
- query
- .select(`#${id}`)
- .boundingClientRect()
- .exec((res) => {
- if (!res[0]) {
- return;
- }
- const { width, height } = res[0] as {
- width: number;
- height: number;
- };
- const pixelRatio = Math.ceil(getPixelRatio());
+ createChart() {
+ const { width, height } = this.props;
+ const id = `f-web-canvas-${this.$id}`;
+ const { pixelRatio: drp = 2, windowWidth = 375 } = my?.getSystemInfoSync();
- // 高清解决方案
- this.setData(
- {
- width: width * pixelRatio,
- height: height * pixelRatio,
- },
- () => {
- const { element: canvas, context } = createCanvasAdapter(my.createCanvasContext(id));
- const fCanvas = this.createCanvas({
- width,
- height,
- pixelRatio,
- context,
- createImage: canvas.createImage.bind(canvas),
- requestAnimationFrame: canvas.requestAnimationFrame.bind(canvas),
- cancelAnimationFrame: canvas.cancelAnimationFrame.bind(canvas),
- });
- fCanvas.render().catch((error) => {
- this.catchError(error);
- });
- },
- );
- });
+ const pixelRatio = Math.ceil(drp);
+ const rpx2px = windowWidth / 750;
+
+ this.setData({
+ width: width * rpx2px * pixelRatio,
+ height: height * rpx2px * pixelRatio,
+ });
+
+ const { element: canvas, context } = createCanvasAdapter(my.createCanvasContext(id));
+ const fCanvas = this.createCanvas({
+ width: width * rpx2px,
+ height: height * rpx2px,
+ pixelRatio,
+ context,
+ createImage: canvas.createImage.bind(canvas),
+ requestAnimationFrame: canvas.requestAnimationFrame.bind(canvas),
+ cancelAnimationFrame: canvas.cancelAnimationFrame.bind(canvas),
+ });
+ fCanvas.render().catch((error) => {
+ this.catchError(error);
+ });
},
catchError(error) {
@@ -156,7 +120,17 @@ Component({
createImage,
requestAnimationFrame,
cancelAnimationFrame,
- onRender: onCanvasRender,
+ onRender: () => {
+ const query = my.createSelectorQuery();
+ query
+ .select(`f-web-canvas-${this.$id}`)
+ //@ts-ignore
+ .node()
+ .exec((time) => {
+ // api 执行结束后的下一个通信才会上屏
+ onCanvasRender && onCanvasRender(time);
+ });
+ },
// @ts-ignore
offscreenCanvas: my.createOffscreenCanvas ? my.createOffscreenCanvas() : null,
// useNativeClickEvent: false,