Repository: incubator-weex Updated Branches: refs/heads/0.16-dev 8a8dfb818 -> e941cfbac
+ [android] return contentSize on getComponentRect when target component implemented ContentMeasurable @notdanger Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/adaf9cfe Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/adaf9cfe Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/adaf9cfe Branch: refs/heads/0.16-dev Commit: adaf9cfe9c2d79c3ed855a32490d59068e0ee8ee Parents: 5951404 Author: misakuo <misa...@apache.org> Authored: Mon Jul 31 11:35:46 2017 +0800 Committer: misakuo <misa...@apache.org> Committed: Mon Jul 31 11:35:46 2017 +0800 ---------------------------------------------------------------------- .../weex/dom/action/GetComponentRectAction.java | 12 ++++++++ .../weex/ui/component/ContentMeasurable.java | 29 ++++++++++++++++++++ .../taobao/weex/ui/component/WXScroller.java | 16 ++++++++++- .../ui/component/list/BasicListComponent.java | 18 +++++++++++- 4 files changed, 73 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/adaf9cfe/android/sdk/src/main/java/com/taobao/weex/dom/action/GetComponentRectAction.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/dom/action/GetComponentRectAction.java b/android/sdk/src/main/java/com/taobao/weex/dom/action/GetComponentRectAction.java index cf8e224..d622248 100644 --- a/android/sdk/src/main/java/com/taobao/weex/dom/action/GetComponentRectAction.java +++ b/android/sdk/src/main/java/com/taobao/weex/dom/action/GetComponentRectAction.java @@ -28,6 +28,7 @@ import com.taobao.weex.bridge.JSCallback; import com.taobao.weex.bridge.SimpleJSCallback; import com.taobao.weex.dom.RenderAction; import com.taobao.weex.dom.RenderActionContext; +import com.taobao.weex.ui.component.ContentMeasurable; import com.taobao.weex.ui.component.WXComponent; import com.taobao.weex.utils.WXViewUtils; @@ -74,6 +75,17 @@ class GetComponentRectAction implements RenderAction { size.put("top", getWebPxValue(sizes.top,viewPort)); options.put("size", size); options.put("result", true); + + if (component instanceof ContentMeasurable) { + Rect contentFrame = ((ContentMeasurable) component).getContentFrame(); + if (contentFrame != null) { + Map<String, Float> contentSize = new HashMap<>(2); + contentSize.put("width", getWebPxValue(contentFrame.width(), viewPort)); + contentSize.put("height", getWebPxValue(contentFrame.height(), viewPort)); + options.put("contentSize", contentSize); + } + } + } else { options.put("errMsg", "Component does not exist"); } http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/adaf9cfe/android/sdk/src/main/java/com/taobao/weex/ui/component/ContentMeasurable.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/component/ContentMeasurable.java b/android/sdk/src/main/java/com/taobao/weex/ui/component/ContentMeasurable.java new file mode 100644 index 0000000..b804d5b --- /dev/null +++ b/android/sdk/src/main/java/com/taobao/weex/ui/component/ContentMeasurable.java @@ -0,0 +1,29 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package com.taobao.weex.ui.component; + +import android.graphics.Rect; + +/** + * Created by moxun on 2017/7/31. + */ + +public interface ContentMeasurable { + Rect getContentFrame(); +} http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/adaf9cfe/android/sdk/src/main/java/com/taobao/weex/ui/component/WXScroller.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/component/WXScroller.java b/android/sdk/src/main/java/com/taobao/weex/ui/component/WXScroller.java index 627776f..49037ca 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/component/WXScroller.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/component/WXScroller.java @@ -69,7 +69,7 @@ import java.util.Map.Entry; */ @Component(lazyload = false) -public class WXScroller extends WXVContainer<ViewGroup> implements WXScrollViewListener,Scrollable { +public class WXScroller extends WXVContainer<ViewGroup> implements WXScrollViewListener,Scrollable,ContentMeasurable { public static final String DIRECTION = "direction"; protected int mOrientation = Constants.Orientation.VERTICAL; @@ -719,4 +719,18 @@ public class WXScroller extends WXVContainer<ViewGroup> implements WXScrollViewL public void resetLoadmore() { mForceLoadmoreNextTime = true; } + + + @Override + public Rect getContentFrame() { + View innerView = getInnerView(); + if (innerView != null) { + if (innerView instanceof WXScrollView) { + return ((WXScrollView) innerView).getContentFrame(); + } else if (innerView instanceof WXHorizontalScrollView) { + return ((WXHorizontalScrollView) innerView).getContentFrame(); + } + } + return null; + } } http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/adaf9cfe/android/sdk/src/main/java/com/taobao/weex/ui/component/list/BasicListComponent.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/component/list/BasicListComponent.java b/android/sdk/src/main/java/com/taobao/weex/ui/component/list/BasicListComponent.java index c959351..9f3b2cc 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/component/list/BasicListComponent.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/component/list/BasicListComponent.java @@ -23,6 +23,7 @@ import android.content.Context; import android.graphics.Color; import android.graphics.Point; import android.graphics.PointF; +import android.graphics.Rect; import android.os.Build; import android.support.annotation.NonNull; import android.support.annotation.Nullable; @@ -51,6 +52,7 @@ import com.taobao.weex.dom.ImmutableDomObject; import com.taobao.weex.dom.WXAttr; import com.taobao.weex.dom.WXDomObject; import com.taobao.weex.ui.component.AppearanceHelper; +import com.taobao.weex.ui.component.ContentMeasurable; import com.taobao.weex.ui.component.Scrollable; import com.taobao.weex.ui.component.WXBaseRefresh; import com.taobao.weex.ui.component.WXComponent; @@ -85,7 +87,7 @@ import java.util.regex.Pattern; */ public abstract class BasicListComponent<T extends ViewGroup & ListComponentView> extends WXVContainer<T> implements - IRecyclerAdapterListener<ListBaseViewHolder>, IOnLoadMoreListener, Scrollable { + IRecyclerAdapterListener<ListBaseViewHolder>, IOnLoadMoreListener, Scrollable, ContentMeasurable { public static final String TRANSFORM = "transform"; public static final String LOADMOREOFFSET = "loadmoreoffset"; private String TAG = "BasicListComponent"; @@ -1331,4 +1333,18 @@ public abstract class BasicListComponent<T extends ViewGroup & ListComponentView return false; } + + @Override + public Rect getContentFrame() { + T wrapper = getHostView(); + if (wrapper != null) { + RecyclerView recyclerView = wrapper.getInnerView(); + if (recyclerView != null) { + int contentWidth = recyclerView.getMeasuredWidth() + recyclerView.computeHorizontalScrollRange(); + int contentHeight = recyclerView.getMeasuredHeight() + recyclerView.computeVerticalScrollRange(); + return new Rect(0, 0, contentWidth, contentHeight); + } + } + return null; + } }