diff --git a/doric-android/doric/src/main/java/pub/doric/shader/AeroEffectView.java b/doric-android/doric/src/main/java/pub/doric/shader/AeroEffectView.java index d0823fc1..030ccf25 100644 --- a/doric-android/doric/src/main/java/pub/doric/shader/AeroEffectView.java +++ b/doric-android/doric/src/main/java/pub/doric/shader/AeroEffectView.java @@ -62,6 +62,9 @@ public class AeroEffectView extends DoricLayer { @Override protected void dispatchDraw(Canvas canvas) { + if (canvas.getWidth() <= 0 || canvas.getHeight() <= 0) { + return; + } if (mFullBitmap == null || mFullBitmap.getWidth() != canvas.getWidth() || mFullBitmap.getHeight() != canvas.getHeight()) { diff --git a/doric-android/doric/src/main/java/pub/doric/shader/AeroEffectViewNode.java b/doric-android/doric/src/main/java/pub/doric/shader/AeroEffectViewNode.java index ecb54bd7..130b745d 100644 --- a/doric-android/doric/src/main/java/pub/doric/shader/AeroEffectViewNode.java +++ b/doric-android/doric/src/main/java/pub/doric/shader/AeroEffectViewNode.java @@ -46,7 +46,7 @@ public class AeroEffectViewNode extends StackNode { if ("effectiveRect".equals(name)) { if (prop.isObject()) { int x = DoricUtils.dp2px(prop.asObject().getProperty("x").asNumber().toFloat()); - int y = DoricUtils.dp2px(prop.asObject().getProperty("x").asNumber().toFloat()); + int y = DoricUtils.dp2px(prop.asObject().getProperty("y").asNumber().toFloat()); int width = DoricUtils.dp2px(prop.asObject().getProperty("width").asNumber().toFloat()); int height = DoricUtils.dp2px(prop.asObject().getProperty("height").asNumber().toFloat()); ((AeroEffectView) view).setEffectiveRect(new Rect(x, y, x + width, y + height)); diff --git a/doric-android/doric/src/main/java/pub/doric/shader/BlurEffectView.java b/doric-android/doric/src/main/java/pub/doric/shader/BlurEffectView.java index 98f8fb3b..98af5fe4 100644 --- a/doric-android/doric/src/main/java/pub/doric/shader/BlurEffectView.java +++ b/doric-android/doric/src/main/java/pub/doric/shader/BlurEffectView.java @@ -61,6 +61,9 @@ public class BlurEffectView extends DoricLayer { @Override protected void dispatchDraw(Canvas canvas) { + if (canvas.getWidth() <= 0 || canvas.getHeight() <= 0) { + return; + } if (mFullBitmap == null || mFullBitmap.getWidth() != canvas.getWidth() || mFullBitmap.getHeight() != canvas.getHeight()) { diff --git a/doric-android/doric/src/main/java/pub/doric/shader/BlurEffectViewNode.java b/doric-android/doric/src/main/java/pub/doric/shader/BlurEffectViewNode.java index fa6ff96f..02bcfcff 100644 --- a/doric-android/doric/src/main/java/pub/doric/shader/BlurEffectViewNode.java +++ b/doric-android/doric/src/main/java/pub/doric/shader/BlurEffectViewNode.java @@ -50,7 +50,7 @@ public class BlurEffectViewNode extends StackNode { } else if ("effectiveRect".equals(name)) { if (prop.isObject()) { int x = DoricUtils.dp2px(prop.asObject().getProperty("x").asNumber().toFloat()); - int y = DoricUtils.dp2px(prop.asObject().getProperty("x").asNumber().toFloat()); + int y = DoricUtils.dp2px(prop.asObject().getProperty("y").asNumber().toFloat()); int width = DoricUtils.dp2px(prop.asObject().getProperty("width").asNumber().toFloat()); int height = DoricUtils.dp2px(prop.asObject().getProperty("height").asNumber().toFloat()); ((BlurEffectView) view).setEffectiveRect(new Rect(x, y, x + width, y + height)); diff --git a/doric-demo/src/BlurEffectsDemo.tsx b/doric-demo/src/BlurEffectsDemo.tsx index a7bbfefd..160e1253 100644 --- a/doric-demo/src/BlurEffectsDemo.tsx +++ b/doric-demo/src/BlurEffectsDemo.tsx @@ -8,32 +8,270 @@ import { Image, Text, createRef, - animate, - loge, Stack, - RotationXAnimation, - RotationAnimation, + Color, + GestureContainer, + Scroller, + Gravity, + HLayout, } from "doric"; +import { colors } from "./utils"; @Entry export class BlurEffectsDemo extends Panel { build(root: Group) { - let ref = createRef(); - - - { - const rotation = new RotationAnimation(); - rotation.fromRotation = 0; - rotation.toRotation = 2; - rotation.duration = 1000; - rotation.repeatCount = -1; - ref.current.doAnimation(context, rotation); + root.backgroundColor = Color.WHITE; + const blurEffectRef = createRef(); + const gestureRef = createRef(); + + + - - ; + > + + + + + + + 希腊帕特农神庙历经数千年风雨侵蚀,早已断墙残垣。然而那些廊柱屹立千年,仍然坚固巍然。 + 这种廊柱样式叫做 Doric,即我们这个项目的名称由来。 + 正如Doric样式的廊柱撑起了神庙的千年风雨,我们也希望Doric项目能够作为前端页面的支柱,简洁,可靠。 + 目前Doric正在持续迭代中。如果您对Doric项目感兴趣,欢迎加入我们。 + + + + + + + {(() => { + const labelRef = createRef(); + const spinnerRef = createRef(); + const containerRef = createRef(); + this.addOnRenderFinishedCallback(async () => { + const width = await containerRef.current.getWidth(this.context); + const maxValue = 25; + spinnerRef.current.width = + ((blurEffectRef.current.radius || 0) * width) / maxValue; + labelRef.current.text = `Blur radius: ${blurEffectRef.current.radius}`; + containerRef.current.onTouchDown = async (event) => { + spinnerRef.current.width = event.x; + blurEffectRef.current.radius = Math.round( + (event.x / width) * maxValue + ); + labelRef.current.text = `Blur radius: ${blurEffectRef.current.radius}`; + }; + containerRef.current.onTouchMove = async (event) => { + spinnerRef.current.width = event.x; + blurEffectRef.current.radius = Math.round( + (event.x / width) * maxValue + ); + labelRef.current.text = `Blur radius: ${blurEffectRef.current.radius}`; + }; + }); + return ( + <> + + Blur radius:\t + + + + + + ); + })()} + + + {(() => { + const labelRef = createRef(); + const spinnerRef = createRef(); + const containerRef = createRef(); + this.addOnRenderFinishedCallback(async () => { + const width = await containerRef.current.getWidth(this.context); + const maxValue = await blurEffectRef.current.getWidth( + this.context + ); + spinnerRef.current.width = + ((blurEffectRef.current.effectiveRect?.width || 0) * width) / + maxValue; + labelRef.current.text = `Effective Width: ${blurEffectRef.current.effectiveRect?.width}`; + containerRef.current.onTouchDown = async (event) => { + spinnerRef.current.width = event.x; + blurEffectRef.current.effectiveRect = { + ...blurEffectRef.current.effectiveRect!!, + width: Math.floor((event.x / width) * maxValue), + }; + labelRef.current.text = `Effective Width: ${blurEffectRef.current.effectiveRect?.width}`; + }; + containerRef.current.onTouchMove = async (event) => { + spinnerRef.current.width = event.x; + blurEffectRef.current.effectiveRect = { + ...blurEffectRef.current.effectiveRect!!, + width: Math.floor((event.x / width) * maxValue), + }; + labelRef.current.text = `Effective Width: ${blurEffectRef.current.effectiveRect?.width}`; + }; + }); + return ( + <> + + + + + + ); + })()} + + + {(() => { + const labelRef = createRef(); + const spinnerRef = createRef(); + const containerRef = createRef(); + this.addOnRenderFinishedCallback(async () => { + const width = await containerRef.current.getWidth(this.context); + const maxValue = await blurEffectRef.current.getHeight( + this.context + ); + spinnerRef.current.width = + ((blurEffectRef.current.effectiveRect?.height || 0) * width) / + maxValue; + labelRef.current.text = `Effective Height: ${blurEffectRef.current.effectiveRect?.height}`; + containerRef.current.onTouchDown = async (event) => { + spinnerRef.current.width = event.x; + blurEffectRef.current.effectiveRect = { + ...blurEffectRef.current.effectiveRect!!, + height: Math.floor((event.x / width) * maxValue), + }; + labelRef.current.text = `Effective Height: ${blurEffectRef.current.effectiveRect?.height}`; + }; + containerRef.current.onTouchMove = async (event) => { + spinnerRef.current.width = event.x; + blurEffectRef.current.effectiveRect = { + ...blurEffectRef.current.effectiveRect!!, + height: Math.floor((event.x / width) * maxValue), + }; + labelRef.current.text = `Effective Height: ${blurEffectRef.current.effectiveRect?.height}`; + }; + }); + return ( + <> + + + + + + ); + })()} + + + ; + this.addOnRenderFinishedCallback(() => { + let x = 0, + y = 0, + posX = 0, + posY = 0; + gestureRef.current.onTouchDown = (event) => { + const rect = blurEffectRef.current.effectiveRect || { + x: 0, + y: 0, + width: 0, + height: 0, + }; + if ( + event.x >= rect.x && + event.x <= rect.x + rect.width && + event.y >= rect.y && + event.y <= rect.y + rect.height + ) { + x = event.x; + y = event.y; + posX = rect.x; + posY = rect.y; + } else { + x = -1; + } + }; + gestureRef.current.onTouchMove = (event) => { + if (x >= 0) { + blurEffectRef.current.effectiveRect = { + ...blurEffectRef.current.effectiveRect!!, + x: posX + (event.x - x), + y: posY + (event.y - y), + }; + } + }; + }); } }