From dad961cade50eccc0f3915889da03f66861a677a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E9=9B=81=E7=A7=8B?= <1273378004@qq.com> Date: Thu, 27 May 2021 10:39:16 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix:=E4=BF=AE=E5=A4=8D=E6=99=BA=E8=83=BD?= =?UTF-8?q?=E7=9A=84=E6=8B=96=E6=8B=BD=E5=B8=83=E5=B1=80=EF=BC=88=E5=9E=82?= =?UTF-8?q?=E7=9B=B4=EF=BC=89=E5=9C=A8102.0.0.110=E3=80=90SDK5=E3=80=91?= =?UTF-8?q?=E4=B8=AD=E5=A4=B1=E6=95=88=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lxj/xpopup/widget/SmartDragLayout.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/library/src/main/java/com/lxj/xpopup/widget/SmartDragLayout.java b/library/src/main/java/com/lxj/xpopup/widget/SmartDragLayout.java index b67ce68..6046228 100644 --- a/library/src/main/java/com/lxj/xpopup/widget/SmartDragLayout.java +++ b/library/src/main/java/com/lxj/xpopup/widget/SmartDragLayout.java @@ -4,6 +4,7 @@ import ohos.agp.animation.Animator; import ohos.agp.animation.AnimatorValue; import ohos.agp.components.AttrSet; import ohos.agp.components.Component; +import ohos.agp.components.ComponentContainer; import ohos.agp.components.DragInfo; import ohos.agp.components.StackLayout; import ohos.agp.render.Canvas; @@ -14,7 +15,7 @@ import ohos.app.Context; * Description: 智能的拖拽布局(垂直),优先滚动整体,整体滚到头,则滚动内部能滚动的View * Create by dance, at 2018/12/23 */ -public class SmartDragLayout extends StackLayout implements Component.BindStateChangedListener, Component.DrawTask { +public class SmartDragLayout extends StackLayout implements Component.BindStateChangedListener, ComponentContainer.ArrangeListener { private Component child; boolean enableDrag = true; // 是否启用手势拖拽 @@ -31,7 +32,7 @@ public class SmartDragLayout extends StackLayout implements Component.BindStateC public SmartDragLayout(Context context, AttrSet attrSet, String styleName) { super(context, attrSet, styleName); setBindStateChangedListener(this); - addDrawTask(this); + setArrangeListener(this); setDraggedListener(DRAG_VERTICAL, mDragListener); } @@ -45,11 +46,12 @@ public class SmartDragLayout extends StackLayout implements Component.BindStateC } @Override - public void onDraw(Component component, Canvas canvas) { - maxY = child.getHeight(); + public boolean onArrange(int left, int top, int right, int bottom) { + maxY = child.getEstimatedHeight(); minY = 0; - int left = getWidth() / 2 - child.getWidth() / 2; - child.setComponentPosition(left, getHeight(), left + child.getWidth(), getHeight() + maxY); + int childLeft = getEstimatedWidth() / 2 - child.getEstimatedWidth() / 2; + child.arrange(childLeft, getEstimatedHeight() - maxY, childLeft + child.getEstimatedWidth(), getEstimatedHeight()); + return false; } Component.DraggedListener mDragListener = new Component.DraggedListener() { @@ -70,6 +72,8 @@ public class SmartDragLayout extends StackLayout implements Component.BindStateC if (enableDrag) { int ty = (int) (dragInfo.updatePoint.getPointY() - startPoint.getPointY()); ty = ty > maxY - 1 ? maxY - 1 : ty; + isScrollUp = ty < 0; + ty = ty < 0 ? 0 : ty; translationY(ty); } } @@ -96,8 +100,6 @@ public class SmartDragLayout extends StackLayout implements Component.BindStateC boolean isScrollUp; public void translationY(int dy) { - dy = dy < 0 ? 0 : dy; - isScrollUp = dy < 0; float fraction = dy * 1f / maxY; if (listener != null) { listener.onDrag(dy, fraction, isScrollUp); @@ -151,6 +153,7 @@ public class SmartDragLayout extends StackLayout implements Component.BindStateC this.listener = listener; } + public interface OnCloseListener { void onClose(); -- Gitee From 9dbf2acb9281c58492243b73d31583acd9065d07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E9=9B=81=E7=A7=8B?= <1273378004@qq.com> Date: Thu, 27 May 2021 10:48:17 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix:=E4=BF=AE=E5=A4=8D=E6=99=BA=E8=83=BD?= =?UTF-8?q?=E7=9A=84=E6=8B=96=E6=8B=BD=E5=B8=83=E5=B1=80=EF=BC=88=E6=B0=B4?= =?UTF-8?q?=E5=B9=B3=EF=BC=89=E5=9C=A8102.0.0.110=E3=80=90SDK5=E3=80=91?= =?UTF-8?q?=E4=B8=AD=E6=98=BE=E7=A4=BA=E5=BC=82=E5=B8=B8=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lxj/xpopup/widget/PopupDrawerLayout.java | 44 +++++++++++-------- 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/library/src/main/java/com/lxj/xpopup/widget/PopupDrawerLayout.java b/library/src/main/java/com/lxj/xpopup/widget/PopupDrawerLayout.java index 7d55e7e..435fbcc 100644 --- a/library/src/main/java/com/lxj/xpopup/widget/PopupDrawerLayout.java +++ b/library/src/main/java/com/lxj/xpopup/widget/PopupDrawerLayout.java @@ -7,6 +7,7 @@ import ohos.agp.animation.Animator; import ohos.agp.animation.AnimatorValue; import ohos.agp.components.AttrSet; import ohos.agp.components.Component; +import ohos.agp.components.ComponentContainer; import ohos.agp.components.DragInfo; import ohos.agp.components.StackLayout; import ohos.agp.utils.Point; @@ -16,11 +17,11 @@ import ohos.app.Context; * Description: 智能的拖拽布局(水平) * Create by dance, at 2018/12/23 */ -public class PopupDrawerLayout extends StackLayout implements Component.BindStateChangedListener, Component.LayoutRefreshedListener { +public class PopupDrawerLayout extends StackLayout implements Component.BindStateChangedListener, ComponentContainer.ArrangeListener { private static final String TAG = "SmartDragLayout"; private Component placeHolder; - private Component mChild; + private Component mChild; public PopupPosition position = PopupPosition.Left; ShadowBgAnimator bgAnimator = new ShadowBgAnimator(); boolean enableDrag = true; // 是否启用手势拖拽 @@ -39,30 +40,37 @@ public class PopupDrawerLayout extends StackLayout implements Component.BindStat super(context, attrSet, styleName); setBindStateChangedListener(this); setDraggedListener(DRAG_HORIZONTAL, mDragListener); - setLayoutRefreshedListener(this); + setArrangeListener(this); } int parentWidth = 0; int parentHeight = 0; int childWidth = 0; int childHeight = 0; + private boolean hasLayout = false; @Override - public void onRefreshed(Component component) { + public boolean onArrange(int left, int top, int right, int bottom) { if (placeHolder == null) { placeHolder = getComponentAt(0); mChild = getComponentAt(1); } - parentWidth = getWidth(); - parentHeight = getHeight(); - childWidth = mChild.getWidth(); - childHeight = mChild.getHeight(); - placeHolder.setComponentPosition(0, 0, parentWidth, parentHeight); - if (position == PopupPosition.Left) { - mChild.setComponentPosition(0, 0, childWidth, childHeight); + parentWidth = getEstimatedWidth(); + parentHeight = getEstimatedHeight(); + childWidth = mChild.getEstimatedWidth(); + childHeight = mChild.getEstimatedHeight(); + placeHolder.arrange(0, 0, parentWidth, parentHeight); + if (!hasLayout) { + if (position == PopupPosition.Left) { + mChild.arrange(0, 0, childWidth, childHeight); + } else { + mChild.arrange(parentWidth - childWidth, 0, parentWidth, childHeight); + } + hasLayout = true; } else { - mChild.setComponentPosition(parentWidth - childWidth, 0, parentWidth, childHeight); + mChild.arrange(mChild.getLeft(), mChild.getTop(), mChild.getRight(), mChild.getEstimatedHeight()); } + return true; } DraggedListener mDragListener = new DraggedListener() { @@ -84,6 +92,12 @@ public class PopupDrawerLayout extends StackLayout implements Component.BindStat int tx = (int) (dragInfo.updatePoint.getPointX() - startPoint.getPointX()); tx = tx > childWidth - 1 ? childWidth - 1 : tx; tx = tx < -childWidth + 1 ? -childWidth + 1 : tx; + if (position == PopupPosition.Left) { + tx = tx > 0 ? 0 : tx; + } else { + tx = tx < 0 ? 0 : tx; + } + isToLeft = tx < 0; translationX(tx); } } @@ -112,12 +126,6 @@ public class PopupDrawerLayout extends StackLayout implements Component.BindStat boolean isToLeft; public void translationX(int dx) { - if (position == PopupPosition.Left) { - dx = dx > 0 ? 0 : dx; - } else { - dx = dx < 0 ? 0 : dx; - } - isToLeft = dx < 0; float fraction = dx * 1f / childHeight; if (hasShadowBg) { setBackground(ElementUtil.getShapeElement(bgAnimator.calculateBgColor(fraction))); -- Gitee