You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@weex.apache.org by ky...@apache.org on 2018/04/28 06:53:55 UTC
[27/48] incubator-weex git commit: * [android] Merge WeexCore-master
to master.
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/ui/component/WXVContainer.java
----------------------------------------------------------------------
diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/component/WXVContainer.java b/android/sdk/src/main/java/com/taobao/weex/ui/component/WXVContainer.java
index 2bb4703..86ea719 100644
--- a/android/sdk/src/main/java/com/taobao/weex/ui/component/WXVContainer.java
+++ b/android/sdk/src/main/java/com/taobao/weex/ui/component/WXVContainer.java
@@ -20,11 +20,8 @@ package com.taobao.weex.ui.component;
import android.content.Context;
import android.content.Intent;
-import android.support.annotation.RestrictTo;
-import android.support.annotation.RestrictTo.Scope;
-import android.support.v4.view.ViewCompat;
-import android.util.Pair;
import android.support.annotation.Nullable;
+import android.support.v4.view.ViewCompat;
import android.util.Pair;
import android.view.Menu;
import android.view.View;
@@ -34,6 +31,7 @@ import android.widget.FrameLayout;
import com.taobao.weex.WXSDKInstance;
import com.taobao.weex.annotation.JSMethod;
import com.taobao.weex.common.Constants;
+import com.taobao.weex.ui.action.BasicComponentData;
import com.taobao.weex.dom.WXDomObject;
import com.taobao.weex.dom.flex.Spacing;
import com.taobao.weex.ui.view.WXImageView;
@@ -48,24 +46,23 @@ import java.util.ArrayList;
*/
public abstract class WXVContainer<T extends ViewGroup> extends WXComponent<T> {
- private static final String TAG="WXVContainer";
+ private static final String TAG = "WXVContainer";
protected ArrayList<WXComponent> mChildren = new ArrayList<>();
private BoxShadowHost mBoxShadowHost;
private boolean requestDisallowInterceptTouchEvent = false;
-
@Deprecated
- public WXVContainer(WXSDKInstance instance, WXDomObject dom, WXVContainer parent, String instanceId, boolean isLazy) {
- this(instance,dom,parent,isLazy);
+ public WXVContainer(WXSDKInstance instance, WXVContainer parent, String instanceId, boolean isLazy, BasicComponentData basicComponentData) {
+ this(instance, parent, isLazy, basicComponentData);
}
@Deprecated
- public WXVContainer(WXSDKInstance instance, WXDomObject node, WXVContainer parent, boolean lazy) {
- super(instance, node, parent);
+ public WXVContainer(WXSDKInstance instance, WXVContainer parent, boolean lazy, BasicComponentData basicComponentData) {
+ super(instance, parent, basicComponentData);
}
- public WXVContainer(WXSDKInstance instance, WXDomObject node, WXVContainer parent) {
- super(instance, node, parent);
+ public WXVContainer(WXSDKInstance instance, WXVContainer parent, BasicComponentData basicComponentData) {
+ super(instance, parent, basicComponentData);
}
/**
@@ -96,7 +93,7 @@ public abstract class WXVContainer<T extends ViewGroup> extends WXComponent<T> {
/**
* Offset top for children layout.
*/
- protected int getChildrenLayoutTopOffset(){
+ protected int getChildrenLayoutTopOffset() {
return 0;
}
@@ -104,14 +101,13 @@ public abstract class WXVContainer<T extends ViewGroup> extends WXComponent<T> {
* use {@link #getHostView()} instead
*/
@Deprecated
- public ViewGroup getView(){
+ public ViewGroup getView() {
return getHostView();
}
@Override
public void applyLayoutAndEvent(WXComponent component) {
- long startNanos = System.nanoTime();
- if(!isLazy()) {
+ if (!isLazy()) {
if (component == null) {
component = this;
}
@@ -119,18 +115,15 @@ public abstract class WXVContainer<T extends ViewGroup> extends WXComponent<T> {
int count = childCount();
for (int i = 0; i < count; i++) {
WXComponent child = getChild(i);
- child.applyLayoutAndEvent(((WXVContainer)component).getChild(i));
+ child.applyLayoutAndEvent(((WXVContainer) component).getChild(i));
}
-
}
- mTraceInfo.uiThreadNanos += (System.nanoTime() - startNanos);
}
/**
* Get or generate new layout parameter for child view
- *
*/
- public ViewGroup.LayoutParams getChildLayoutParams(WXComponent child,View childView, int width, int height, int left, int right, int top, int bottom){
+ public ViewGroup.LayoutParams getChildLayoutParams(WXComponent child, View childView, int width, int height, int left, int right, int top, int bottom) {
ViewGroup.LayoutParams lp = null;
if (childView != null) {
lp = childView.getLayoutParams();
@@ -149,45 +142,44 @@ public abstract class WXVContainer<T extends ViewGroup> extends WXComponent<T> {
}
- public Scrollable getFirstScroller(){
- if(this instanceof Scrollable){
- return (Scrollable)this;
- }else{
- for (int i=0;i<getChildCount();i++){
+ public Scrollable getFirstScroller() {
+ if (this instanceof Scrollable) {
+ return (Scrollable) this;
+ } else {
+ for (int i = 0; i < getChildCount(); i++) {
Scrollable scrollable = getChild(i).getFirstScroller();
- if(scrollable!=null){
+ if (scrollable != null) {
return scrollable;
}
}
}
return null;
}
+
@Override
public void bindData(WXComponent component) {
- long startNanos = System.nanoTime();
- if(!isLazy()) {
+ if (!isLazy()) {
if (component == null) {
component = this;
}
super.bindData(component);
int count = childCount();
for (int i = 0; i < count; i++) {
- getChild(i).bindData(((WXVContainer)component).getChild(i));
+ getChild(i).bindData(((WXVContainer) component).getChild(i));
}
}
- mTraceInfo.uiThreadNanos += (System.nanoTime() - startNanos);
}
@Override
public void refreshData(WXComponent component) {
- if (component == null) {
- component = this;
- }
- super.refreshData(component);
- int count = childCount();
- for (int i = 0; i < count; i++) {
- getChild(i).refreshData(((WXVContainer)component).getChild(i));
- }
+ if (component == null) {
+ component = this;
+ }
+ super.refreshData(component);
+ int count = childCount();
+ for (int i = 0; i < count; i++) {
+ getChild(i).refreshData(((WXVContainer) component).getChild(i));
+ }
}
/**
@@ -205,8 +197,8 @@ public abstract class WXVContainer<T extends ViewGroup> extends WXComponent<T> {
for (int i = 0; i < count; ++i) {
createChildViewAt(i);
}
- if(getHostView()!=null){
- getHostView().setClipToPadding(false);
+ if (getHostView() != null) {
+ getHostView().setClipToPadding(false);
}
}
@@ -226,7 +218,7 @@ public abstract class WXVContainer<T extends ViewGroup> extends WXComponent<T> {
* recycle component resources
*/
public void recycled() {
- if (mChildren != null && !getDomObject().isFixed() && getDomObject().getAttrs().canRecycled()) {
+ if (mChildren != null && !isFixed() && getAttrs().canRecycled()) {
int count = mChildren.size();
for (int i = 0; i < count; ++i) {
mChildren.get(i).recycled();
@@ -237,7 +229,7 @@ public abstract class WXVContainer<T extends ViewGroup> extends WXComponent<T> {
}
@Override
- public View detachViewAndClearPreInfo(){
+ public View detachViewAndClearPreInfo() {
View original = super.detachViewAndClearPreInfo();
if (mChildren != null) {
int count = childCount();
@@ -248,16 +240,10 @@ public abstract class WXVContainer<T extends ViewGroup> extends WXComponent<T> {
return original;
}
- /**
- * Use {@link #getChildCount()} instead
- * @return
- */
- @Deprecated
public int childCount() {
return mChildren == null ? 0 : mChildren.size();
}
- @Nullable
public WXComponent getChild(int index) {
if (mChildren == null || index < 0 || index >= mChildren.size()) {
//To avoid index out of bounds
@@ -275,7 +261,6 @@ public abstract class WXVContainer<T extends ViewGroup> extends WXComponent<T> {
}
public void addChild(WXComponent child, int index) {
- long startNanos = System.nanoTime();
if (child == null || index < -1) {
return;
}
@@ -286,15 +271,13 @@ public abstract class WXVContainer<T extends ViewGroup> extends WXComponent<T> {
} else {
mChildren.add(index, child);
}
- mTraceInfo.uiThreadNanos += (System.nanoTime() - startNanos);
}
- public final int indexOf(WXComponent comp){
+ public final int indexOf(WXComponent comp) {
return mChildren.indexOf(comp);
}
public void createChildViewAt(int index) {
- long startNanos = System.nanoTime();
Pair<WXComponent, Integer> ret = rearrangeIndexAndGetChild(index);
if (ret.first != null) {
WXComponent child = ret.first;
@@ -303,24 +286,21 @@ public abstract class WXVContainer<T extends ViewGroup> extends WXComponent<T> {
addSubView(child.getHostView(), ret.second);
}
}
- mTraceInfo.uiThreadNanos += (System.nanoTime() - startNanos);
}
- protected Pair<WXComponent, Integer> rearrangeIndexAndGetChild(int index){
+ protected Pair<WXComponent, Integer> rearrangeIndexAndGetChild(int index) {
int indexToCreate = index;
- if(indexToCreate < 0){
- indexToCreate = childCount()-1;
+ if (indexToCreate < 0) {
+ indexToCreate = childCount() - 1;
}
- if (indexToCreate<0){
+ if (indexToCreate < 0) {
return new Pair<>(null, indexToCreate);
- }
- else {
+ } else {
return new Pair<>(getChild(indexToCreate), indexToCreate);
}
}
- @RestrictTo(Scope.LIBRARY)
public void addSubView(View child, int index) {
if (child == null || getRealView() == null) {
return;
@@ -335,24 +315,24 @@ public abstract class WXVContainer<T extends ViewGroup> extends WXComponent<T> {
}
}
- public void remove(WXComponent child, boolean destroy){
+ public void remove(WXComponent child, boolean destroy) {
if (child == null || mChildren == null || mChildren.size() == 0) {
return;
}
mChildren.remove(child);
- if(getInstance()!=null
- &&getInstance().getRootView()!=null
- && child.getDomObject().isFixed()){
+ if (getInstance() != null
+ && getInstance().getRootView() != null
+ && child.isFixed()) {
getInstance().removeFixedView(child.getHostView());
- }else if(getRealView() != null) {
- if(!child.isVirtualComponent()){
+ } else if (getRealView() != null) {
+ if (!child.isVirtualComponent()) {
getRealView().removeView(child.getHostView());
- }else{
+ } else {
child.removeVirtualComponent();
}
}
- if(destroy) {
+ if (destroy) {
child.destroy();
}
}
@@ -360,22 +340,19 @@ public abstract class WXVContainer<T extends ViewGroup> extends WXComponent<T> {
@Override
public void notifyAppearStateChange(String wxEventType, String direction) {
super.notifyAppearStateChange(wxEventType, direction);
- if(getHostView()==null || mChildren==null){
+ if (getHostView() == null || mChildren == null) {
return;
}
- //appear should not notify child
- if(getDomObject().getAttrs().containsKey("appearNotifyChild")){
- for(WXComponent component:mChildren){
- if(component.getHostView()!=null && !(component.getHostView().getVisibility()==View.VISIBLE)){
- wxEventType= Constants.Event.DISAPPEAR;
- }
- component.notifyAppearStateChange(wxEventType,direction);
+ for (WXComponent component : mChildren) {
+ if (component.getHostView() != null && !(component.getHostView().getVisibility() == View.VISIBLE)) {
+ wxEventType = Constants.Event.DISAPPEAR;
}
+ component.notifyAppearStateChange(wxEventType, direction);
}
}
- /********************************
- * begin hook Activity life cycle callback
+ /********************************************************
+ * begin hook Activity life cycle callback *
********************************************************/
@Override
public void onActivityCreate() {
@@ -451,17 +428,17 @@ public abstract class WXVContainer<T extends ViewGroup> extends WXComponent<T> {
}
@Override
- public void onActivityResult(int requestCode, int resultCode, Intent data){
- super.onActivityResult(requestCode,resultCode,data);
+ public void onActivityResult(int requestCode, int resultCode, Intent data) {
+ super.onActivityResult(requestCode, resultCode, data);
int count = childCount();
for (int i = 0; i < count; i++) {
- getChild(i).onActivityResult(requestCode,resultCode,data);
+ getChild(i).onActivityResult(requestCode, resultCode, data);
}
}
- public boolean onCreateOptionsMenu(Menu menu){
+ public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
int count = childCount();
@@ -473,12 +450,12 @@ public abstract class WXVContainer<T extends ViewGroup> extends WXComponent<T> {
@Override
- public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults){
- super.onRequestPermissionsResult(requestCode,permissions,grantResults);
+ public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
+ super.onRequestPermissionsResult(requestCode, permissions, grantResults);
int count = childCount();
for (int i = 0; i < count; i++) {
- getChild(i).onRequestPermissionsResult(requestCode,permissions,grantResults);
+ getChild(i).onRequestPermissionsResult(requestCode, permissions, grantResults);
}
}
@@ -497,7 +474,7 @@ public abstract class WXVContainer<T extends ViewGroup> extends WXComponent<T> {
if(getHostView() == null
|| !ViewCompat.isAttachedToWindow(getHostView())
|| !(getHostView() instanceof ViewGroup)){
- return;
+ return;
}
boolean isViewTree = WXUtils.getBoolean(viewTreeRecycle, false);
if(isViewTree){
@@ -523,7 +500,7 @@ public abstract class WXVContainer<T extends ViewGroup> extends WXComponent<T> {
if(getHostView() == null
|| !ViewCompat.isAttachedToWindow(getHostView())
|| !(getHostView() instanceof ViewGroup)){
- return;
+ return;
}
boolean isViewTree = WXUtils.getBoolean(viewTreeRecycle, false);
if(isViewTree){
@@ -548,19 +525,19 @@ public abstract class WXVContainer<T extends ViewGroup> extends WXComponent<T> {
* transverse view tree, and recycle wximageview in container
* */
private void doViewTreeRecycleImageView(ViewGroup viewGroup, boolean isRelease){
- int count = viewGroup.getChildCount();
- for(int i=0; i<count; i++){
- View view = viewGroup.getChildAt(i);
- if(view instanceof WXImageView){
- if(isRelease){
- ((WXImageView) view).autoReleaseImage();
- }else{
- ((WXImageView) view).autoRecoverImage();
- }
- }else if(view instanceof ViewGroup){
- doViewTreeRecycleImageView((ViewGroup) view, isRelease);
- }
+ int count = viewGroup.getChildCount();
+ for(int i=0; i<count; i++){
+ View view = viewGroup.getChildAt(i);
+ if(view instanceof WXImageView){
+ if(isRelease){
+ ((WXImageView) view).autoReleaseImage();
+ }else{
+ ((WXImageView) view).autoRecoverImage();
}
+ }else if(view instanceof ViewGroup){
+ doViewTreeRecycleImageView((ViewGroup) view, isRelease);
+ }
+ }
}
@@ -580,7 +557,8 @@ public abstract class WXVContainer<T extends ViewGroup> extends WXComponent<T> {
* end hook Activity life cycle callback
********************************************************/
- public @Nullable View getBoxShadowHost(boolean isClear) {
+ public @Nullable
+ View getBoxShadowHost(boolean isClear) {
if (isClear) {
// Return existed host if want clear shadow
return mBoxShadowHost;
@@ -592,7 +570,7 @@ public abstract class WXVContainer<T extends ViewGroup> extends WXComponent<T> {
}
try {
- String type = getDomObject().getType();
+ String type = getComponentType();
if (WXBasicComponentType.DIV.equals(type)) {
WXLogUtils.d("BoxShadow", "Draw box-shadow with BoxShadowHost on div: " + toString());
if (mBoxShadowHost == null) {
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/ui/component/WXVideo.java
----------------------------------------------------------------------
diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/component/WXVideo.java b/android/sdk/src/main/java/com/taobao/weex/ui/component/WXVideo.java
index f2dc6ef..22be688 100644
--- a/android/sdk/src/main/java/com/taobao/weex/ui/component/WXVideo.java
+++ b/android/sdk/src/main/java/com/taobao/weex/ui/component/WXVideo.java
@@ -33,7 +33,7 @@ import com.taobao.weex.WXSDKManager;
import com.taobao.weex.annotation.Component;
import com.taobao.weex.adapter.URIAdapter;
import com.taobao.weex.common.Constants;
-import com.taobao.weex.dom.WXDomObject;
+import com.taobao.weex.ui.action.BasicComponentData;
import com.taobao.weex.ui.view.WXVideoView;
import com.taobao.weex.utils.WXLogUtils;
import com.taobao.weex.utils.WXUtils;
@@ -54,12 +54,12 @@ public class WXVideo extends WXComponent<FrameLayout> {
private boolean mError;
@Deprecated
- public WXVideo(WXSDKInstance instance, WXDomObject dom, WXVContainer parent, String instanceId, boolean isLazy) {
- this(instance, dom, parent, isLazy);
+ public WXVideo(WXSDKInstance instance, WXVContainer parent, String instanceId, boolean isLazy, BasicComponentData basicComponentData) {
+ this(instance, parent, isLazy, basicComponentData);
}
- public WXVideo(WXSDKInstance instance, WXDomObject dom, WXVContainer parent, boolean isLazy) {
- super(instance, dom, parent, isLazy);
+ public WXVideo(WXSDKInstance instance, WXVContainer parent, boolean isLazy, BasicComponentData basicComponentData) {
+ super(instance, parent, isLazy, basicComponentData);
}
@Override
@@ -77,7 +77,7 @@ public class WXVideo extends WXComponent<FrameLayout> {
mPrepared = false;
mError = true;
- if ( getDomObject().getEvents().contains(Constants.Event.FAIL)) {
+ if (getEvents().contains(Constants.Event.FAIL)) {
WXVideo.this.notify(Constants.Event.FAIL, Constants.Value.STOP);
}
return true;
@@ -120,7 +120,7 @@ public class WXVideo extends WXComponent<FrameLayout> {
if (WXEnvironment.isApkDebugable()) {
WXLogUtils.d("Video", "onCompletion");
}
- if ( getDomObject().getEvents().contains(Constants.Event.FINISH)) {
+ if (getEvents().contains(Constants.Event.FINISH)) {
WXVideo.this.notify(Constants.Event.FINISH, Constants.Value.STOP);
}
}
@@ -133,7 +133,7 @@ public class WXVideo extends WXComponent<FrameLayout> {
if (WXEnvironment.isApkDebugable()) {
WXLogUtils.d("Video", "onPause");
}
- if ( getDomObject().getEvents().contains(Constants.Event.PAUSE)) {
+ if (getEvents().contains(Constants.Event.PAUSE)) {
WXVideo.this.notify(Constants.Event.PAUSE, Constants.Value.PAUSE);
}
}
@@ -144,7 +144,7 @@ public class WXVideo extends WXComponent<FrameLayout> {
WXLogUtils.d("Video", "onStart");
}
- if ( getDomObject().getEvents().contains(Constants.Event.START)) {
+ if (getEvents().contains(Constants.Event.START)) {
WXVideo.this.notify(Constants.Event.START, Constants.Value.PLAY);
}
}
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/ui/component/WXWeb.java
----------------------------------------------------------------------
diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/component/WXWeb.java b/android/sdk/src/main/java/com/taobao/weex/ui/component/WXWeb.java
index ae910d0..a536c46 100644
--- a/android/sdk/src/main/java/com/taobao/weex/ui/component/WXWeb.java
+++ b/android/sdk/src/main/java/com/taobao/weex/ui/component/WXWeb.java
@@ -30,7 +30,7 @@ import com.taobao.weex.annotation.Component;
import com.taobao.weex.adapter.URIAdapter;
import com.taobao.weex.annotation.JSMethod;
import com.taobao.weex.common.Constants;
-import com.taobao.weex.dom.WXDomObject;
+import com.taobao.weex.ui.action.BasicComponentData;
import com.taobao.weex.ui.view.IWebView;
import com.taobao.weex.ui.view.WXWebView;
import com.taobao.weex.utils.WXUtils;
@@ -48,12 +48,12 @@ public class WXWeb extends WXComponent {
protected IWebView mWebView;
@Deprecated
- public WXWeb(WXSDKInstance instance, WXDomObject dom, WXVContainer parent, String instanceId, boolean isLazy) {
- this(instance,dom,parent,isLazy);
+ public WXWeb(WXSDKInstance instance, WXVContainer parent, String instanceId, boolean isLazy, BasicComponentData basicComponentData) {
+ this(instance, parent, isLazy, basicComponentData);
}
- public WXWeb(WXSDKInstance instance, WXDomObject dom, WXVContainer parent, boolean isLazy) {
- super(instance, dom, parent, isLazy);
+ public WXWeb(WXSDKInstance instance, WXVContainer parent, boolean isLazy, BasicComponentData basicComponentData) {
+ super(instance, parent, isLazy, basicComponentData);
createWebView();
}
@@ -84,7 +84,7 @@ public class WXWeb extends WXComponent {
mWebView.setOnPageListener(new IWebView.OnPageListener() {
@Override
public void onReceivedTitle(String title) {
- if (getDomObject().getEvents().contains(Constants.Event.RECEIVEDTITLE)) {
+ if (getEvents().contains(Constants.Event.RECEIVEDTITLE)) {
Map<String, Object> params = new HashMap<>();
params.put("title", title);
fireEvent(Constants.Event.RECEIVEDTITLE, params);
@@ -93,7 +93,7 @@ public class WXWeb extends WXComponent {
@Override
public void onPageStart(String url) {
- if ( getDomObject().getEvents().contains(Constants.Event.PAGESTART)) {
+ if (getEvents().contains(Constants.Event.PAGESTART)) {
Map<String, Object> params = new HashMap<>();
params.put("url", url);
fireEvent(Constants.Event.PAGESTART, params);
@@ -102,7 +102,7 @@ public class WXWeb extends WXComponent {
@Override
public void onPageFinish(String url, boolean canGoBack, boolean canGoForward) {
- if ( getDomObject().getEvents().contains(Constants.Event.PAGEFINISH)) {
+ if (getEvents().contains(Constants.Event.PAGEFINISH)) {
Map<String, Object> params = new HashMap<>();
params.put("url", url);
params.put("canGoBack", canGoBack);
@@ -185,7 +185,7 @@ public class WXWeb extends WXComponent {
}
private void fireEvent(String type, Object message) {
- if (getDomObject().getEvents().contains(Constants.Event.ERROR)) {
+ if (getEvents().contains(Constants.Event.ERROR)) {
Map<String, Object> params = new HashMap<>();
params.put("type", type);
params.put("errorMsg", message);
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/ui/component/basic/WXBasicComponent.java
----------------------------------------------------------------------
diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/component/basic/WXBasicComponent.java b/android/sdk/src/main/java/com/taobao/weex/ui/component/basic/WXBasicComponent.java
new file mode 100644
index 0000000..67296a0
--- /dev/null
+++ b/android/sdk/src/main/java/com/taobao/weex/ui/component/basic/WXBasicComponent.java
@@ -0,0 +1,215 @@
+/**
+ * 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.basic;
+
+import android.support.annotation.NonNull;
+import android.view.View;
+import com.taobao.weex.dom.CSSShorthand;
+import com.taobao.weex.dom.WXAttr;
+import com.taobao.weex.dom.WXEvent;
+import com.taobao.weex.dom.WXStyle;
+import com.taobao.weex.ui.action.BasicComponentData;
+import com.taobao.weex.ui.action.GraphicPosition;
+import com.taobao.weex.ui.action.GraphicSize;
+import com.taobao.weex.ui.component.WXComponent;
+import java.util.Map;
+import java.util.Set;
+
+public abstract class WXBasicComponent<T extends View> {
+
+ private Object mExtra;
+ private String mComponentType;
+ private String mRef;
+ private GraphicPosition mLayoutPosition;
+ private GraphicSize mLayoutSize;
+ private BasicComponentData mBasicComponentData;
+
+ private int mViewPortWidth = 750;
+
+ public WXBasicComponent(BasicComponentData basicComponentData) {
+ this.mBasicComponentData = basicComponentData;
+ this.mRef = basicComponentData.mRef;
+ this.mComponentType = basicComponentData.mComponentType;
+ }
+
+ public BasicComponentData getBasicComponentData() {
+ return mBasicComponentData;
+ }
+
+ protected void bindComponent(WXComponent component) {
+ mComponentType = component.getComponentType();
+ mRef = component.getRef();
+ }
+
+ public final @NonNull
+ WXStyle getStyles() {
+ return mBasicComponentData.getStyles();
+ }
+
+ public final @NonNull
+ WXAttr getAttrs() {
+ return mBasicComponentData.getAttrs();
+ }
+
+ public final @NonNull
+ WXEvent getEvents() {
+ return mBasicComponentData.getEvents();
+ }
+
+ /**
+ * Get this node's margin, as defined by cssstyle + default margin.
+ */
+ public final @NonNull
+ CSSShorthand getMargin() {
+ return mBasicComponentData.getMargin();
+ }
+
+ /**
+ * Get this node's padding, as defined by cssstyle + default padding.
+ */
+ public final @NonNull
+ CSSShorthand getPadding() {
+ return mBasicComponentData.getPadding();
+ }
+
+ /**
+ * Get this node's border, as defined by cssstyle.
+ */
+ public @NonNull
+ CSSShorthand getBorder() {
+ return mBasicComponentData.getBorder();
+ }
+
+ public final void setMargins(@NonNull CSSShorthand margins) {
+ mBasicComponentData.setMargins(margins);
+ }
+
+ public final void setPaddings(@NonNull CSSShorthand paddings) {
+ mBasicComponentData.setPaddings(paddings);
+ }
+
+ public final void setBorders(@NonNull CSSShorthand borders) {
+ mBasicComponentData.setBorders(borders);
+ }
+
+ public final void addAttr(Map<String, Object> attrs) {
+ if (attrs == null || attrs.isEmpty()) {
+ return;
+ }
+ mBasicComponentData.addAttr(attrs);
+ }
+
+ public final void addStyle(Map<String, Object> styles) {
+ if (styles == null || styles.isEmpty()) {
+ return;
+ }
+ mBasicComponentData.addStyle(styles);
+ }
+
+ public final void addStyle(Map<String, Object> styles, boolean byPesudo) {
+ if (styles == null || styles.isEmpty()) {
+ return;
+ }
+ mBasicComponentData.addStyle(styles, byPesudo);
+ }
+
+ public final void addEvent(Set<String> events) {
+ if (events == null || events.isEmpty()) {
+ return;
+ }
+
+ mBasicComponentData.addEvent(events);
+ }
+
+ public final void addShorthand(Map<String, String> shorthand) {
+ if (!shorthand.isEmpty() && mBasicComponentData != null) {
+ mBasicComponentData.addShorthand(shorthand);
+ }
+ }
+
+ public int getViewPortWidth() {
+ return mViewPortWidth;
+ }
+
+ public void setViewPortWidth(int mViewPortWidth) {
+ this.mViewPortWidth = mViewPortWidth;
+ }
+
+ public Object getExtra() {
+ return mExtra;
+ }
+
+ public void updateExtra(Object extra) {
+ this.mExtra = extra;
+ }
+
+ public String getComponentType() {
+ return mComponentType;
+ }
+
+ public String getRef() {
+ return mRef;
+ }
+
+ protected GraphicPosition getLayoutPosition() {
+ if (mLayoutPosition == null) {
+ mLayoutPosition = new GraphicPosition(0, 0, 0, 0);
+ }
+ return mLayoutPosition;
+ }
+
+ protected void setLayoutPosition(GraphicPosition mLayoutPosition) {
+ this.mLayoutPosition = mLayoutPosition;
+ }
+
+ protected GraphicSize getLayoutSize() {
+ if (mLayoutSize == null) {
+ mLayoutSize = new GraphicSize(0, 0);
+ }
+ return mLayoutSize;
+ }
+
+ protected void setLayoutSize(GraphicSize mLayoutSize) {
+ this.mLayoutSize = mLayoutSize;
+ }
+
+ public float getCSSLayoutTop() {
+ return mLayoutPosition == null ? 0 : mLayoutPosition.getTop();
+ }
+
+ public float getCSSLayoutBottom() {
+ return mLayoutPosition == null ? 0 : mLayoutPosition.getBottom();
+ }
+
+ public float getCSSLayoutLeft() {
+ return mLayoutPosition == null ? 0 : mLayoutPosition.getLeft();
+ }
+
+ public float getCSSLayoutRight() {
+ return mLayoutPosition == null ? 0 : mLayoutPosition.getRight();
+ }
+
+ public float getLayoutWidth() {
+ return mLayoutSize == null ? 0 : mLayoutSize.getWidth();
+ }
+
+ public float getLayoutHeight() {
+ return mLayoutSize == null ? 0 : mLayoutSize.getHeight();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/ui/component/binding/Layouts.java
----------------------------------------------------------------------
diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/component/binding/Layouts.java b/android/sdk/src/main/java/com/taobao/weex/ui/component/binding/Layouts.java
index 3357882..e9307bb 100644
--- a/android/sdk/src/main/java/com/taobao/weex/ui/component/binding/Layouts.java
+++ b/android/sdk/src/main/java/com/taobao/weex/ui/component/binding/Layouts.java
@@ -25,8 +25,6 @@ import android.os.AsyncTask;
import com.taobao.weex.WXEnvironment;
import com.taobao.weex.WXSDKInstance;
import com.taobao.weex.common.Constants;
-import com.taobao.weex.dom.WXDomObject;
-import com.taobao.weex.dom.flex.CSSLayoutContext;
import com.taobao.weex.ui.component.WXComponent;
import com.taobao.weex.ui.component.WXVContainer;
import com.taobao.weex.ui.component.list.template.TemplateViewHolder;
@@ -54,7 +52,10 @@ public class Layouts {
protected Void doInBackground(Void... params) {
if(templateViewHolder.getHolderPosition() == position){
if(component.getInstance() != null && !component.getInstance().isDestroy()) {
- doSafeLayout(component, templateViewHolder.getLayoutContext());
+ doSafeLayout(component
+ // TODO
+// , templateViewHolder.getLayoutContext()
+ );
}
}
return null;
@@ -72,7 +73,9 @@ public class Layouts {
templateViewHolder.asyncTask = asyncTask;
asyncTask.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR); //serial executor is better
}else{
- doSafeLayout(component, templateViewHolder.getLayoutContext());
+ doSafeLayout(component
+// , templateViewHolder.getLayoutContext() // TODO
+ );
setLayout(component, false);
}
@@ -81,18 +84,23 @@ public class Layouts {
/**
* safe layout
* */
- public static void doSafeLayout(WXComponent component, final CSSLayoutContext layoutContext){
+ public static void doSafeLayout(WXComponent component
+ // TODO
+// , final CSSLayoutContext layoutContext
+ ){
try{
long start = System.currentTimeMillis();
- doLayout(component, layoutContext);
+ doLayout(component
+// , layoutContext
+ );
if(WXEnvironment.isOpenDebugLog() && WXRecyclerTemplateList.ENABLE_TRACE_LOG) {
WXLogUtils.d(WXRecyclerTemplateList.TAG, "WXTemplateList doSafeLayout" +
- component.getDomObject().getAttrs().get(Constants.Name.Recycler.SLOT_TEMPLATE_CASE) + Thread.currentThread().getName() + " doSafeLayout used " +
+ component.getAttrs().get(Constants.Name.Recycler.SLOT_TEMPLATE_CASE) + Thread.currentThread().getName() + " doSafeLayout used " +
(System.currentTimeMillis() - start));
}
if(!(component.getLayoutHeight() > 0)){
WXLogUtils.e(WXRecyclerTemplateList.TAG, " WXTemplateList doSafeLayout wrong template " +
- component.getDomObject().getAttrs().get(Constants.Name.Recycler.SLOT_TEMPLATE_CASE) + " cell height " + component.getLayoutHeight());
+ component.getAttrs().get(Constants.Name.Recycler.SLOT_TEMPLATE_CASE) + " cell height " + component.getLayoutHeight());
}
}catch (Exception e){
if(WXEnvironment.isApkDebugable()){
@@ -101,41 +109,44 @@ public class Layouts {
}
}
- private static void doLayout(WXComponent component, final CSSLayoutContext layoutContext){
- WXDomObject domObject = (WXDomObject) component.getDomObject();
- final WXSDKInstance instance = component.getInstance();
- domObject.traverseUpdateTree(new WXDomObject.Consumer() {
- @Override
- public void accept(WXDomObject dom) {
- if(instance == null || instance.isDestroy()){
- return;
- }
- if(!dom.hasUpdate()){
- return;
- }
- if(!dom.isShow()){ //not show just skip
- return;
- }
- dom.layoutBefore();
- }
- });
- if(instance != null && !instance.isDestroy()){
- domObject.calculateLayout(layoutContext);
- }
- domObject.traverseUpdateTree( new WXDomObject.Consumer() {
- @Override
- public void accept(WXDomObject dom) {
- if(instance == null || instance.isDestroy()){
- return;
- }
- if(!dom.isShow()){
- return;
- }
- if (dom.hasUpdate()) {
- dom.layoutAfter();
- }
- }
- });
+ private static void doLayout(WXComponent component
+// , final CSSLayoutContext layoutContext
+ ){
+ // TODO
+// WXDomObject domObject = (WXDomObject) component.getDomObject();
+// final WXSDKInstance instance = component.getInstance();
+// domObject.traverseUpdateTree(new WXDomObject.Consumer() {
+// @Override
+// public void accept(WXDomObject dom) {
+// if(instance == null || instance.isDestroy()){
+// return;
+// }
+// if(!dom.hasUpdate()){
+// return;
+// }
+// if(!dom.isShow()){ //not show just skip
+// return;
+// }
+// dom.layoutBefore();
+// }
+// });
+// if(instance != null && !instance.isDestroy()){
+// domObject.markDirty(layoutContext);
+// }
+// domObject.traverseUpdateTree( new WXDomObject.Consumer() {
+// @Override
+// public void accept(WXDomObject dom) {
+// if(instance == null || instance.isDestroy()){
+// return;
+// }
+// if(!dom.isShow()){
+// return;
+// }
+// if (dom.hasUpdate()) {
+// dom.layoutAfter();
+// }
+// }
+// });
}
@@ -150,17 +161,18 @@ public class Layouts {
if(component.isWaste()){
return;
}
- WXDomObject domObject = (WXDomObject) component.getDomObject();
- if(domObject.hasUpdate() || force){
- domObject.markUpdateSeen();
- if(domObject.hasUpdate()){
- domObject.markLayoutStateUpdated();
- }
- component.setLayout(component.getDomObject());
- if(component.getDomObject().getExtra() != null){
- component.updateExtra(component.getDomObject().getExtra());
- }
- }
+ // TODO
+// WXDomObject domObject = (WXDomObject) component.getDomObject();
+// if(domObject.hasUpdate() || force){
+// domObject.markUpdateSeen();
+// if(domObject.hasUpdate()){
+// domObject.markLayoutStateUpdated();
+// }
+// component.setLayout(component.getDomObject());
+// if(component.getDomObject().getExtra() != null){
+// component.updateExtra(component.getDomObject().getExtra());
+// }
+// }
if(component instanceof WXVContainer){
WXVContainer container = (WXVContainer) component;
int count = container.getChildCount();
@@ -174,13 +186,14 @@ public class Layouts {
}
private static final void setLayoutWaste(WXComponent component, boolean force){
- WXDomObject domObject = (WXDomObject) component.getDomObject();
- if(domObject.hasUpdate() || force){
- domObject.markUpdateSeen();
- if(domObject.hasUpdate()){
- domObject.markLayoutStateUpdated();
- }
- }
+ // TODO
+// WXDomObject domObject = (WXDomObject) component.getDomObject();
+// if(domObject.hasUpdate() || force){
+// domObject.markUpdateSeen();
+// if(domObject.hasUpdate()){
+// domObject.markLayoutStateUpdated();
+// }
+// }
if(component instanceof WXVContainer){
WXVContainer container = (WXVContainer) component;
int count = container.getChildCount();
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/ui/component/binding/Statements.java
----------------------------------------------------------------------
diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/component/binding/Statements.java b/android/sdk/src/main/java/com/taobao/weex/ui/component/binding/Statements.java
index f0ddf03..39a2531 100644
--- a/android/sdk/src/main/java/com/taobao/weex/ui/component/binding/Statements.java
+++ b/android/sdk/src/main/java/com/taobao/weex/ui/component/binding/Statements.java
@@ -29,7 +29,6 @@ import com.taobao.weex.bridge.EventResult;
import com.taobao.weex.bridge.WXBridgeManager;
import com.taobao.weex.common.Constants;
import com.taobao.weex.dom.WXAttr;
-import com.taobao.weex.dom.WXDomObject;
import com.taobao.weex.dom.WXEvent;
import com.taobao.weex.dom.WXStyle;
import com.taobao.weex.dom.binding.ELUtils;
@@ -42,8 +41,8 @@ import com.taobao.weex.ui.component.WXComponentFactory;
import com.taobao.weex.ui.component.WXImage;
import com.taobao.weex.ui.component.WXVContainer;
import com.taobao.weex.ui.component.list.WXCell;
-import com.taobao.weex.ui.component.list.template.CellRenderContext;
import com.taobao.weex.ui.component.list.template.CellDataManager;
+import com.taobao.weex.ui.component.list.template.CellRenderContext;
import com.taobao.weex.ui.component.list.template.VirtualComponentLifecycle;
import com.taobao.weex.ui.component.list.template.WXRecyclerTemplateList;
import com.taobao.weex.utils.WXLogUtils;
@@ -74,19 +73,16 @@ public class Statements {
* recursive copy component,
* */
private static final WXComponent copyComponentTree(WXComponent source, WXVContainer parent){
- WXDomObject node = (WXDomObject) source.getDomObject();
- WXComponent component = WXComponentFactory.newInstance(source.getInstance(), node, parent);
+ WXComponent component = WXComponentFactory.newInstance(source.getInstance(), parent, source.getBasicComponentData());
if(source instanceof WXVContainer){
WXVContainer container = (WXVContainer) source;
WXVContainer childParent = (WXVContainer) component;
- WXDomObject childParentNode = (WXDomObject) childParent.getDomObject();
int count = container.getChildCount();
for (int i = 0; i < count; ++i) {
WXComponent child = container.getChild(i);
if (child != null) {
WXComponent targetChild = copyComponentTree(child, childParent);
childParent.addChild(targetChild);
- childParentNode.add((WXDomObject) targetChild.getDomObject(), -1);
}
}
}
@@ -147,16 +143,14 @@ public class Statements {
* after statement has executed, render component's binding attrs in context and bind it to component.
* */
private static final int doRenderComponent(WXComponent component, CellRenderContext context,
- List<WXComponent> updates){
+ List<WXComponent> updates){
WXVContainer parent = component.getParent();
- WXDomObject domObject = (WXDomObject) component.getDomObject();
- WXAttr attrs = domObject.getAttrs();
+ WXAttr attrs = component.getAttrs();
WXStatement statement = attrs.getStatement();
if(statement != null){
- WXDomObject parentDomObject = (WXDomObject) parent.getDomObject();
Token vif = null;
JSONObject vfor = null;
- if(statement.get(WXStatement.WX_IF) instanceof Token){
+ if(statement.get(WXStatement.WX_IF) instanceof Token){
vif = (Token) statement.get(WXStatement.WX_IF);
}
if(statement.get(WXStatement.WX_FOR) instanceof JSONObject){
@@ -166,7 +160,7 @@ public class Statements {
if(vfor != null){
int renderIndex = parent.indexOf(component);
if(vfor.get(WXStatement.WX_FOR_LIST) instanceof Token){
- Token listBlock = (Token) vfor.get(WXStatement.WX_FOR_LIST);
+ Token listBlock = (Token) vfor.get(WXStatement.WX_FOR_LIST);
String indexKey = vfor.getString(WXStatement.WX_FOR_INDEX);
String itemKey = vfor.getString(WXStatement.WX_FOR_ITEM);
Object data = null;
@@ -233,19 +227,17 @@ public class Statements {
long start = System.currentTimeMillis();
renderNode = copyComponentTree(component, parent);
renderNode.setWaste(false);
- WXDomObject renderNodeDomObject = (WXDomObject) renderNode.getDomObject();
- if(renderNodeDomObject.getAttrs().getStatement() != null) {
- renderNodeDomObject.getAttrs().getStatement().remove(WXStatement.WX_FOR);
- renderNodeDomObject.getAttrs().getStatement().remove(WXStatement.WX_IF); //clear node's statement
+ if(renderNode.getAttrs().getStatement() != null) {
+ renderNode.getAttrs().getStatement().remove(WXStatement.WX_FOR);
+ renderNode.getAttrs().getStatement().remove(WXStatement.WX_IF); //clear node's statement
}
- parentDomObject.add(renderNodeDomObject, renderIndex);
parent.addChild(renderNode, renderIndex);
updates.add(renderNode);
if(WXEnvironment.isApkDebugable()){
- WXLogUtils.d(WXRecyclerTemplateList.TAG, Thread.currentThread().getName() + renderNode.getRef() + renderNode.getDomObject().getType() + "statements copy component tree used " + (System.currentTimeMillis() - start));
+ WXLogUtils.d(WXRecyclerTemplateList.TAG, Thread.currentThread().getName() + renderNode.getRef() + renderNode.getComponentType() + "statements copy component tree used " + (System.currentTimeMillis() - start));
}
}
- doBindingAttrsEventAndRenderChildNode(renderNode, (WXDomObject) renderNode.getDomObject(), context, updates);
+ doBindingAttrsEventAndRenderChildNode(renderNode, context, updates);
renderIndex++;
if(loop.size() > 0){
context.stack.push(loop);
@@ -280,7 +272,7 @@ public class Statements {
}
}
- doBindingAttrsEventAndRenderChildNode(component, domObject, context, updates);
+ doBindingAttrsEventAndRenderChildNode(component, context, updates);
return 1;
}
@@ -288,9 +280,9 @@ public class Statements {
/**
* bind attrs and doRender component child
* */
- private static void doBindingAttrsEventAndRenderChildNode(WXComponent component, WXDomObject domObject, CellRenderContext context,
+ private static void doBindingAttrsEventAndRenderChildNode(WXComponent component, CellRenderContext context,
List<WXComponent> updates){
- WXAttr attr = component.getDomObject().getAttrs();
+ WXAttr attr = component.getAttrs();
/**
* sub component supported, sub component new stack
@@ -343,7 +335,7 @@ public class Statements {
}
}
}
- component.getDomObject().getAttrs().put(CellDataManager.VIRTUAL_COMPONENT_ID, virtualComponentId);
+ component.getAttrs().put(CellDataManager.VIRTUAL_COMPONENT_ID, virtualComponentId);
}else{ //stateless component
Map<String, Object> props = renderProps((JSONObject) attr.get(ELUtils.COMPONENT_PROPS), context.stack);
compoentData = props;
@@ -372,12 +364,10 @@ public class Statements {
context.stack = onceStack;
}
- doRenderBindingAttrsAndEvent(component, domObject, context);
+ doRenderBindingAttrsAndEvent(component, context);
if(component instanceof WXVContainer){
- if(!domObject.isShow()){
- if(!(component instanceof WXCell)){
+ if(!(component instanceof WXCell)){
return;
- }
}
WXVContainer container = (WXVContainer) component;
for(int k=0; k<container.getChildCount();){
@@ -402,14 +392,14 @@ public class Statements {
/**
* render dynamic binding attrs and bind them to component node.
* */
- private static void doRenderBindingAttrsAndEvent(WXComponent component, WXDomObject domObject, CellRenderContext context){
+ private static void doRenderBindingAttrsAndEvent(WXComponent component, CellRenderContext context){
ArrayStack stack = context.stack;
component.setWaste(false);
- WXAttr attr = domObject.getAttrs();
+ WXAttr attr = component.getAttrs();
if(attr != null
&& attr.getBindingAttrs() != null
&& attr.getBindingAttrs().size() > 0){
- ArrayMap<String, Object> bindAttrs = domObject.getAttrs().getBindingAttrs();
+ ArrayMap<String, Object> bindAttrs = component.getAttrs().getBindingAttrs();
Map<String, Object> dynamic = renderBindingAttrs(bindAttrs, stack);
Set<Map.Entry<String, Object>> entries = dynamic.entrySet();
/**
@@ -438,9 +428,9 @@ public class Statements {
&& dynamic.get(Constants.Name.SRC) != null
&& component instanceof WXImage){
//for image avoid dirty layout, only update src attrs
- domObject.getAttrs().put(Constants.Name.SRC, dynamic.get(Constants.Name.SRC));
+ component.getAttrs().put(Constants.Name.SRC, dynamic.get(Constants.Name.SRC));
}else {
- domObject.updateAttr(dynamic); //dirty layout
+// domObject.updateAttr(dynamic); //dirty layout
}
if(isMainThread()) {
component.updateProperties(dynamic);
@@ -450,7 +440,7 @@ public class Statements {
}
- WXStyle style = domObject.getStyles();
+ WXStyle style = component.getStyles();
if(style != null && style.getBindingStyle() != null){
ArrayMap<String, Object> bindStyle = style.getBindingStyle();
Map<String, Object> dynamic = renderBindingAttrs(bindStyle, stack);
@@ -476,15 +466,16 @@ public class Statements {
}
}
if(dynamic.size() > 0) {
- domObject.updateStyle(dynamic, false);
- domObject.applyStyle(dynamic);
+ // TODO
+// domObject.updateStyle(dynamic, false);
+// domObject.applyStyle(dynamic);
if(isMainThread()) {
component.updateProperties(dynamic);
}
}
}
- WXEvent event = domObject.getEvents();
+ WXEvent event = component.getEvents();
if(event == null || event.getEventBindingArgs() == null){
return;
}
@@ -564,7 +555,7 @@ public class Statements {
Object value = entry.getValue();
String key = entry.getKey();
if(value instanceof JSONObject
- && (((JSONObject) value).get(ELUtils.BINDING) instanceof Token)){
+ && (((JSONObject) value).get(ELUtils.BINDING) instanceof Token)){
JSONObject binding = (JSONObject) value;
Token block = (Token) (binding.get(ELUtils.BINDING));
Object blockValue = block.execute(stack);
@@ -583,7 +574,7 @@ public class Statements {
for(int i=0; i<array.size(); i++){
Object value = array.get(i);
if(value instanceof JSONObject
- && (((JSONObject) value).get(ELUtils.BINDING) instanceof Token)){
+ && (((JSONObject) value).get(ELUtils.BINDING) instanceof Token)){
Token block = (Token)(((JSONObject) value).get(ELUtils.BINDING));
Object blockValue = block.execute(stack);
params.add(blockValue);
@@ -593,7 +584,7 @@ public class Statements {
}
}else if(bindings instanceof JSONObject){
JSONObject binding = (JSONObject) bindings;
- if(binding.get(ELUtils.BINDING) instanceof Token){
+ if(binding.get(ELUtils.BINDING) instanceof Token){
Token block = (Token) binding.get(ELUtils.BINDING);
Object blockValue = block.execute(stack);
params.add(blockValue);
@@ -616,11 +607,10 @@ public class Statements {
public static String getComponentId(WXComponent component){
- if(component instanceof WXCell || component == null){
+ if(component instanceof WXCell || component == null){
return null;
}
- WXDomObject domObject = (WXDomObject) component.getDomObject();
- WXAttr attr = domObject.getAttrs();
+ WXAttr attr = component.getAttrs();
if(attr.get(ELUtils.IS_COMPONENT_ROOT) != null
&& WXUtils.getBoolean(attr.get(ELUtils.IS_COMPONENT_ROOT), false)){
if(attr.get(ELUtils.COMPONENT_PROPS) != null
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/ui/component/helper/ScrollStartEndHelper.java
----------------------------------------------------------------------
diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/component/helper/ScrollStartEndHelper.java b/android/sdk/src/main/java/com/taobao/weex/ui/component/helper/ScrollStartEndHelper.java
index 15163e1..871f86a 100644
--- a/android/sdk/src/main/java/com/taobao/weex/ui/component/helper/ScrollStartEndHelper.java
+++ b/android/sdk/src/main/java/com/taobao/weex/ui/component/helper/ScrollStartEndHelper.java
@@ -20,6 +20,7 @@ package com.taobao.weex.ui.component.helper;
import android.os.Handler;
import android.os.Looper;
+
import com.taobao.weex.common.Constants;
import com.taobao.weex.ui.component.WXComponent;
import com.taobao.weex.ui.component.WXScroller;
@@ -35,7 +36,7 @@ import java.util.Map;
* Created by furture on 2017/11/13.
*/
-public class ScrollStartEndHelper implements Runnable{
+public class ScrollStartEndHelper implements Runnable{
private Handler handler;
private WXComponent component;
@@ -48,7 +49,7 @@ public class ScrollStartEndHelper implements Runnable{
public ScrollStartEndHelper(WXComponent component) {
this.component = component;
this.handler = new Handler(Looper.getMainLooper());
- this.minInterval = WXUtils.getNumberInt(component.getDomObject().getAttrs().get("minscrolldelayinterval"), 32);
+ this.minInterval = WXUtils.getNumberInt(component.getAttrs().get("minscrolldelayinterval"), 32);
}
/**
@@ -56,12 +57,12 @@ public class ScrollStartEndHelper implements Runnable{
* @param y scroll offset or dy, which is not accurate
* */
public void onScrolled(int x, int y){
- if((component.getDomObject().getEvents().contains(Constants.Event.SCROLL_START)
- || component.getDomObject().getEvents().contains(Constants.Event.SCROLL_END))){
+ if((component.getEvents().contains(Constants.Event.SCROLL_START)
+ || component.getEvents().contains(Constants.Event.SCROLL_END))){
this.x = x;
this.y = y;
if(!hasStart){
- if(component.getDomObject().getEvents().contains(Constants.Event.SCROLL_START)){
+ if(component.getEvents().contains(Constants.Event.SCROLL_START)){
component.fireEvent(Constants.Event.SCROLL_START, getScrollEvent(x, y));
}
hasStart = true;
@@ -77,7 +78,7 @@ public class ScrollStartEndHelper implements Runnable{
if(component.isDestoryed()){
return;
}
- if(component.getDomObject().getEvents().contains(Constants.Event.SCROLL_END)){
+ if(component.getEvents().contains(Constants.Event.SCROLL_END)){
component.fireEvent(Constants.Event.SCROLL_END, getScrollEvent(this.x, this.y));
}
hasStart = false;
@@ -86,7 +87,7 @@ public class ScrollStartEndHelper implements Runnable{
private Map<String, Object> getScrollEvent(int offsetX, int offsetY){
if(component instanceof BasicListComponent){
BasicListComponent basicListComponent = (BasicListComponent) component;
- if(basicListComponent.getHostView() instanceof ListComponentView){
+ if(basicListComponent.getHostView() instanceof ListComponentView){
ListComponentView componentView = (ListComponentView) basicListComponent.getHostView();
if(componentView != null){
return basicListComponent.getScrollEvent(componentView.getInnerView(), offsetX, offsetY);
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/ui/component/helper/WXTimeInputHelper.java
----------------------------------------------------------------------
diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/component/helper/WXTimeInputHelper.java b/android/sdk/src/main/java/com/taobao/weex/ui/component/helper/WXTimeInputHelper.java
index 9d3f669..d666439 100644
--- a/android/sdk/src/main/java/com/taobao/weex/ui/component/helper/WXTimeInputHelper.java
+++ b/android/sdk/src/main/java/com/taobao/weex/ui/component/helper/WXTimeInputHelper.java
@@ -29,42 +29,42 @@ import com.taobao.weex.ui.component.AbstractEditComponent;
*/
public class WXTimeInputHelper {
- public static void pickDate(String max, String min, final AbstractEditComponent component) {
- final TextView target = component.getHostView();
+ public static void pickDate(String max, String min, final AbstractEditComponent component) {
+ final TextView target = component.getHostView();
- DatePickerImpl.pickDate(
- target.getContext(),
- target.getText().toString(),
- max,
- min,
- new DatePickerImpl.OnPickListener() {
- @Override
- public void onPick(boolean set, @Nullable String result) {
- if (set) {
- target.setText(result);
- component.performOnChange(result);
- }
- }
- },
- null);
- }
+ DatePickerImpl.pickDate(
+ target.getContext(),
+ target.getText().toString(),
+ max,
+ min,
+ new DatePickerImpl.OnPickListener() {
+ @Override
+ public void onPick(boolean set, @Nullable String result) {
+ if (set) {
+ target.setText(result);
+ component.performOnChange(result);
+ }
+ }
+ },
+ null);
+ }
- public static void pickTime(final AbstractEditComponent component) {
- final TextView target = component.getHostView();
+ public static void pickTime(final AbstractEditComponent component) {
+ final TextView target = component.getHostView();
- DatePickerImpl.pickTime(
- target.getContext(),
- target.getText().toString(),
- new DatePickerImpl.OnPickListener() {
- @Override
- public void onPick(boolean set, @Nullable String result) {
- if (set) {
- target.setText(result);
- component.performOnChange(result);
- }
- }
- },
- null
- );
- }
+ DatePickerImpl.pickTime(
+ target.getContext(),
+ target.getText().toString(),
+ new DatePickerImpl.OnPickListener() {
+ @Override
+ public void onPick(boolean set, @Nullable String result) {
+ if (set) {
+ target.setText(result);
+ component.performOnChange(result);
+ }
+ }
+ },
+ null
+ );
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/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 8ffc097..742f164 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
@@ -48,9 +48,8 @@ import com.taobao.weex.annotation.JSMethod;
import com.taobao.weex.common.Constants;
import com.taobao.weex.common.ICheckBindingScroller;
import com.taobao.weex.common.OnWXScrollListener;
-import com.taobao.weex.dom.ImmutableDomObject;
import com.taobao.weex.dom.WXAttr;
-import com.taobao.weex.dom.WXDomObject;
+import com.taobao.weex.ui.action.BasicComponentData;
import com.taobao.weex.ui.component.AppearanceHelper;
import com.taobao.weex.ui.component.Scrollable;
import com.taobao.weex.ui.component.WXBaseRefresh;
@@ -67,6 +66,7 @@ import com.taobao.weex.ui.view.listview.adapter.IOnLoadMoreListener;
import com.taobao.weex.ui.view.listview.adapter.IRecyclerAdapterListener;
import com.taobao.weex.ui.view.listview.adapter.ListBaseViewHolder;
import com.taobao.weex.ui.view.listview.adapter.RecyclerViewBaseAdapter;
+import com.taobao.weex.ui.view.listview.adapter.TransformItemDecoration;
import com.taobao.weex.ui.view.listview.adapter.WXRecyclerViewOnScrollListener;
import com.taobao.weex.ui.view.refresh.wrapper.BounceRecyclerView;
import com.taobao.weex.utils.WXLogUtils;
@@ -81,6 +81,7 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
@@ -156,14 +157,11 @@ public abstract class BasicListComponent<T extends ViewGroup & ListComponentView
private Map<String, Map<String, WXComponent>> mStickyMap = new HashMap<>();
private WXStickyHelper stickyHelper;
-
/**
* scroll start and scroll end event
* */
private ScrollStartEndHelper mScrollStartEndHelper;
-
-
/**
* keep positon
* */
@@ -172,8 +170,8 @@ public abstract class BasicListComponent<T extends ViewGroup & ListComponentView
private long keepPositionLayoutDelay = 150;
- public BasicListComponent(WXSDKInstance instance, WXDomObject node, WXVContainer parent) {
- super(instance, node, parent);
+ public BasicListComponent(WXSDKInstance instance, WXVContainer parent, BasicComponentData basicComponentData) {
+ super(instance, parent, basicComponentData);
stickyHelper = new WXStickyHelper(this);
}
@@ -186,10 +184,10 @@ public abstract class BasicListComponent<T extends ViewGroup & ListComponentView
WXLogUtils.e(TAG, "RecyclerView is not found or Adapter is not bound");
return;
}
- if(WXUtils.getBoolean(getDomObject().getAttrs().get("prefetchGapDisable"), false)){
- if(recyclerView.getLayoutManager() != null){
- recyclerView.getLayoutManager().setItemPrefetchEnabled(false);
- }
+ if(WXUtils.getBoolean(getAttrs().get("prefetchGapDisable"), false)){
+ if(recyclerView.getLayoutManager() != null){
+ recyclerView.getLayoutManager().setItemPrefetchEnabled(false);
+ }
}
if (mChildren == null) {
@@ -204,7 +202,7 @@ public abstract class BasicListComponent<T extends ViewGroup & ListComponentView
}
});
- mTriggerType = getTriggerType(getDomObject());
+ mTriggerType = getTriggerType(this);
}
/**
@@ -257,22 +255,21 @@ public abstract class BasicListComponent<T extends ViewGroup & ListComponentView
return params;
}
-
abstract T generateListView(Context context, int orientation);
@Override
protected T initComponentHostView(@NonNull Context context) {
T bounceRecyclerView = generateListView(context, getOrientation());
- String transforms = (String) getDomObject().getAttrs().get(TRANSFORM);
+ String transforms = getAttrByKey(TRANSFORM);
if (transforms != null) {
bounceRecyclerView.getInnerView().addItemDecoration(RecyclerTransform.parseTransforms(getOrientation(), transforms));
}
- if(getDomObject().getAttrs().get(Constants.Name.KEEP_POSITION_LAYOUT_DELAY) != null){
- keepPositionLayoutDelay = WXUtils.getNumberInt(getDomObject().getAttrs().get(Constants.Name.KEEP_POSITION_LAYOUT_DELAY), (int)keepPositionLayoutDelay);
+ if(getAttrs().get(Constants.Name.KEEP_POSITION_LAYOUT_DELAY) != null){
+ keepPositionLayoutDelay = WXUtils.getNumberInt(getAttrs().get(Constants.Name.KEEP_POSITION_LAYOUT_DELAY), (int)keepPositionLayoutDelay);
}
- if(getDomObject().getAttrs().get("appearActionDelay") != null){
- mAppearDelay = WXUtils.getNumberInt(getDomObject().getAttrs().get("appearActionDelay"), (int)mAppearDelay);
+ if(getAttrs().get("appearActionDelay") != null){
+ mAppearDelay = WXUtils.getNumberInt(getAttrs().get("appearActionDelay"), (int)mAppearDelay);
}
mItemAnimator=bounceRecyclerView.getInnerView().getItemAnimator();
@@ -283,10 +280,11 @@ public abstract class BasicListComponent<T extends ViewGroup & ListComponentView
bounceRecyclerView.setOverScrollMode(View.OVER_SCROLL_NEVER);
bounceRecyclerView.getInnerView().clearOnScrollListeners();
bounceRecyclerView.getInnerView().addOnScrollListener(mViewOnScrollListener);
- if(getDomObject().getAttrs().get(Constants.Name.HAS_FIXED_SIZE) != null){
- boolean hasFixedSize = WXUtils.getBoolean(getDomObject().getAttrs().get(Constants.Name.HAS_FIXED_SIZE), false);
+ if(getAttrs().get(Constants.Name.HAS_FIXED_SIZE) != null){
+ boolean hasFixedSize = WXUtils.getBoolean(getAttrs().get(Constants.Name.HAS_FIXED_SIZE), false);
bounceRecyclerView.getInnerView().setHasFixedSize(hasFixedSize);
}
+
bounceRecyclerView.getInnerView().addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
@@ -331,6 +329,7 @@ public abstract class BasicListComponent<T extends ViewGroup & ListComponentView
});
+
bounceRecyclerView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
@Override
@@ -441,7 +440,6 @@ public abstract class BasicListComponent<T extends ViewGroup & ListComponentView
}
}
-
@Override
public boolean isScrollable() {
return isScrollable;
@@ -473,7 +471,7 @@ public abstract class BasicListComponent<T extends ViewGroup & ListComponentView
@Override
public void run() {
if(mAppearComponentsRunnable != null) {
- notifyAppearStateChange(0, 0, 0, 0);
+ notifyAppearStateChange(0, 0, 0, 0);
}
}
};
@@ -560,71 +558,70 @@ public abstract class BasicListComponent<T extends ViewGroup & ListComponentView
entry = iterator.next();
stickyComponent = entry.getValue();
- if (stickyComponent != null && stickyComponent.getDomObject() != null
- && stickyComponent instanceof WXCell) {
+ if (stickyComponent != null && stickyComponent instanceof WXCell) {
- WXCell cell = (WXCell) stickyComponent;
- if (cell.getHostView() == null) {
- return;
- }
+ WXCell cell = (WXCell) stickyComponent;
+ if (cell.getHostView() == null) {
+ return;
+ }
- int[] location = new int[2];
- stickyComponent.getHostView().getLocationOnScreen(location);
- int[] parentLocation = new int[2];
- stickyComponent.getParentScroller().getView().getLocationOnScreen(parentLocation);
- int top = location[1] - parentLocation[1];
-
-
- RecyclerView.LayoutManager layoutManager;
- boolean beforeFirstVisibleItem = false;
- boolean removeOldSticky = false;
- layoutManager = getHostView().getInnerView().getLayoutManager();
- if (layoutManager instanceof LinearLayoutManager || layoutManager instanceof GridLayoutManager) {
- int firstVisiblePosition = ((LinearLayoutManager) layoutManager).findFirstVisibleItemPosition();
- int lastVisiblePosition = ((LinearLayoutManager) layoutManager).findLastVisibleItemPosition();
- int pos = mChildren.indexOf(cell);
- cell.setScrollPositon(pos);
- if (pos <= firstVisiblePosition
- || (cell.getStickyOffset() > 0 && firstVisiblePosition < pos && pos <= lastVisiblePosition &&
- top <= cell.getStickyOffset())) {
- beforeFirstVisibleItem = true;
- if(pos > currentStickyPos) {
- currentStickyPos = pos;
- }
- }else{
- removeOldSticky = true;
+ int[] location = new int[2];
+ stickyComponent.getHostView().getLocationOnScreen(location);
+ int[] parentLocation = new int[2];
+ stickyComponent.getParentScroller().getView().getLocationOnScreen(parentLocation);
+ int top = location[1] - parentLocation[1];
+
+
+ RecyclerView.LayoutManager layoutManager;
+ boolean beforeFirstVisibleItem = false;
+ boolean removeOldSticky = false;
+ layoutManager = getHostView().getInnerView().getLayoutManager();
+ if (layoutManager instanceof LinearLayoutManager || layoutManager instanceof GridLayoutManager) {
+ int firstVisiblePosition = ((LinearLayoutManager) layoutManager).findFirstVisibleItemPosition();
+ int lastVisiblePosition = ((LinearLayoutManager) layoutManager).findLastVisibleItemPosition();
+ int pos = mChildren.indexOf(cell);
+ cell.setScrollPositon(pos);
+ if (pos <= firstVisiblePosition
+ || (cell.getStickyOffset() > 0 && firstVisiblePosition < pos && pos <= lastVisiblePosition &&
+ top <= cell.getStickyOffset())) {
+ beforeFirstVisibleItem = true;
+ if(pos > currentStickyPos) {
+ currentStickyPos = pos;
}
- } else if(layoutManager instanceof StaggeredGridLayoutManager){
- int [] firstItems= new int[3];
- int firstVisiblePosition = ((StaggeredGridLayoutManager) layoutManager).findFirstVisibleItemPositions(firstItems)[0];
- int lastVisiblePosition = ((StaggeredGridLayoutManager) layoutManager).findLastVisibleItemPositions(firstItems)[0];
- int pos = mChildren.indexOf(cell);
-
- if (pos <= firstVisiblePosition || (cell.getStickyOffset() > 0 && firstVisiblePosition < pos && pos <= lastVisiblePosition &&
- top <= cell.getStickyOffset())) {
- beforeFirstVisibleItem = true;
- if(pos > currentStickyPos) {
- currentStickyPos = pos;
- }
- }else{
- removeOldSticky = true;
+ }else{
+ removeOldSticky = true;
+ }
+ } else if(layoutManager instanceof StaggeredGridLayoutManager){
+ int [] firstItems= new int[3];
+ int firstVisiblePosition = ((StaggeredGridLayoutManager) layoutManager).findFirstVisibleItemPositions(firstItems)[0];
+ int lastVisiblePosition = ((StaggeredGridLayoutManager) layoutManager).findLastVisibleItemPositions(firstItems)[0];
+ int pos = mChildren.indexOf(cell);
+
+ if (pos <= firstVisiblePosition || (cell.getStickyOffset() > 0 && firstVisiblePosition < pos && pos <= lastVisiblePosition &&
+ top <= cell.getStickyOffset())) {
+ beforeFirstVisibleItem = true;
+ if(pos > currentStickyPos) {
+ currentStickyPos = pos;
}
+ }else{
+ removeOldSticky = true;
}
+ }
- boolean showSticky = beforeFirstVisibleItem && cell.getLocationFromStart() >= 0 && top <= cell.getStickyOffset() && dy >= 0;
- boolean removeSticky = cell.getLocationFromStart() <= cell.getStickyOffset() && top > cell.getStickyOffset() && dy <= 0;
- if (showSticky) {
- bounceRecyclerView.notifyStickyShow(cell);
- } else if (removeSticky || removeOldSticky) {
- bounceRecyclerView.notifyStickyRemove(cell);
- }
- cell.setLocationFromStart(top);
+ boolean showSticky = beforeFirstVisibleItem && cell.getLocationFromStart() >= 0 && top <= cell.getStickyOffset() && dy >= 0;
+ boolean removeSticky = cell.getLocationFromStart() <= cell.getStickyOffset() && top > cell.getStickyOffset() && dy <= 0;
+ if (showSticky) {
+ bounceRecyclerView.notifyStickyShow(cell);
+ } else if (removeSticky || removeOldSticky) {
+ bounceRecyclerView.notifyStickyRemove(cell);
}
+ cell.setLocationFromStart(top);
+ }
}
if(currentStickyPos >= 0){
- bounceRecyclerView.updateStickyView(currentStickyPos);
+ bounceRecyclerView.updateStickyView(currentStickyPos);
}else{
if(bounceRecyclerView instanceof BounceRecyclerView){
((BounceRecyclerView) bounceRecyclerView).getStickyHeaderHelper().clearStickyHeaders();
@@ -681,9 +678,8 @@ public abstract class BasicListComponent<T extends ViewGroup & ListComponentView
final T view = getHostView();
if (view != null) {
boolean isAddAnimation = false;
- ImmutableDomObject domObject = child.getDomObject();
- if (domObject != null) {
- Object attr = domObject.getAttrs().get(Constants.Name.INSERT_CELL_ANIMATION);
+ if (getBasicComponentData() != null) {
+ Object attr = getAttrs().get(Constants.Name.INSERT_CELL_ANIMATION);
if (Constants.Value.DEFAULT.equals(attr)) {
isAddAnimation = true;
}
@@ -694,53 +690,53 @@ public abstract class BasicListComponent<T extends ViewGroup & ListComponentView
view.getInnerView().setItemAnimator(null);
}
boolean isKeepScrollPosition = false;
- if (child.getDomObject() != null) {
- Object attr = child.getDomObject().getAttrs().get(Constants.Name.KEEP_SCROLL_POSITION);
+ if (child.getBasicComponentData() != null) {
+ Object attr = child.getAttrs().get(Constants.Name.KEEP_SCROLL_POSITION);
if (WXUtils.getBoolean(attr, false) && index <= getChildCount() && index>-1) {
- isKeepScrollPosition = true;
+ isKeepScrollPosition = true;
}
}
if (isKeepScrollPosition) {
if(view.getInnerView().getLayoutManager() instanceof LinearLayoutManager){
- if(!view.getInnerView().isLayoutFrozen()){ //frozen, prevent layout when scroll
- view.getInnerView().setLayoutFrozen(true);
+ if(!view.getInnerView().isLayoutFrozen()){ //frozen, prevent layout when scroll
+ view.getInnerView().setLayoutFrozen(true);
+ }
+ if(keepPositionCell == null){
+ int last=((LinearLayoutManager)view.getInnerView().getLayoutManager()).findLastCompletelyVisibleItemPosition();
+ ListBaseViewHolder holder = (ListBaseViewHolder) view.getInnerView().findViewHolderForAdapterPosition(last);
+ if(holder != null){
+ keepPositionCell = holder.getComponent();
}
- if(keepPositionCell == null){
- int last=((LinearLayoutManager)view.getInnerView().getLayoutManager()).findLastCompletelyVisibleItemPosition();
- ListBaseViewHolder holder = (ListBaseViewHolder) view.getInnerView().findViewHolderForAdapterPosition(last);
- if(holder != null){
- keepPositionCell = holder.getComponent();
+ if(keepPositionCell != null) {
+ if(keepPositionCellRunnable != null){
+ view.removeCallbacks(keepPositionCellRunnable);
}
- if(keepPositionCell != null) {
- if(keepPositionCellRunnable != null){
- view.removeCallbacks(keepPositionCellRunnable);
- }
- keepPositionCellRunnable = new Runnable() {
- @Override
- public void run() {
- if(keepPositionCell != null){
- int keepPosition = indexOf(keepPositionCell);
- int offset = 0;
- if(keepPositionCell.getHostView() != null){
- offset = keepPositionCell.getHostView().getTop();
- }
- if(offset > 0) {
- ((LinearLayoutManager) view.getInnerView().getLayoutManager()).scrollToPositionWithOffset(keepPosition, offset);
- }else{
- view.getInnerView().getLayoutManager().scrollToPosition(keepPosition);
-
- }
- view.getInnerView().setLayoutFrozen(false);
- keepPositionCell = null;
- keepPositionCellRunnable = null;
+ keepPositionCellRunnable = new Runnable() {
+ @Override
+ public void run() {
+ if(keepPositionCell != null){
+ int keepPosition = indexOf(keepPositionCell);
+ int offset = 0;
+ if(keepPositionCell.getHostView() != null){
+ offset = keepPositionCell.getHostView().getTop();
+ }
+ if(offset > 0) {
+ ((LinearLayoutManager) view.getInnerView().getLayoutManager()).scrollToPositionWithOffset(keepPosition, offset);
+ }else{
+ view.getInnerView().getLayoutManager().scrollToPosition(keepPosition);
+
}
+ view.getInnerView().setLayoutFrozen(false);
+ keepPositionCell = null;
+ keepPositionCellRunnable = null;
}
- };
- }
- }
- if(keepPositionCellRunnable == null){
- view.getInnerView().scrollToPosition(((LinearLayoutManager)view.getInnerView().getLayoutManager()).findLastVisibleItemPosition());
+ }
+ };
}
+ }
+ if(keepPositionCellRunnable == null){
+ view.getInnerView().scrollToPosition(((LinearLayoutManager)view.getInnerView().getLayoutManager()).findLastVisibleItemPosition());
+ }
}
view.getRecyclerViewBaseAdapter().notifyItemInserted(adapterPosition);
if(keepPositionCellRunnable != null){
@@ -754,9 +750,6 @@ public abstract class BasicListComponent<T extends ViewGroup & ListComponentView
relocateAppearanceHelper();
}
-
-
-
private void relocateAppearanceHelper() {
Iterator<Map.Entry<String, AppearanceHelper>> iterator = mAppearComponents.entrySet().iterator();
while (iterator.hasNext()) {
@@ -801,12 +794,9 @@ public abstract class BasicListComponent<T extends ViewGroup & ListComponentView
}
boolean isRemoveAnimation = false;
- ImmutableDomObject domObject = child.getDomObject();
- if (domObject != null) {
- Object attr = domObject.getAttrs().get(Constants.Name.DELETE_CELL_ANIMATION);
- if (Constants.Value.DEFAULT.equals(attr)) {
- isRemoveAnimation = true;
- }
+ Object attr = getAttrs().get(Constants.Name.DELETE_CELL_ANIMATION);
+ if (Constants.Value.DEFAULT.equals(attr)) {
+ isRemoveAnimation = true;
}
if (isRemoveAnimation) {
view.getInnerView().setItemAnimator(mItemAnimator);
@@ -823,7 +813,6 @@ public abstract class BasicListComponent<T extends ViewGroup & ListComponentView
-
@Override
public void computeVisiblePointInViewCoordinate(PointF pointF) {
RecyclerView view = getHostView().getInnerView();
@@ -842,9 +831,9 @@ public abstract class BasicListComponent<T extends ViewGroup & ListComponentView
holder.setComponentUsing(false);
if (holder != null
- && holder.canRecycled()
- && holder.getComponent() != null
- && !holder.getComponent().isUsing()) {
+ && holder.canRecycled()
+ && holder.getComponent() != null
+ && !holder.getComponent().isUsing()) {
holder.recycled();
} else {
@@ -867,22 +856,21 @@ public abstract class BasicListComponent<T extends ViewGroup & ListComponentView
holder.setComponentUsing(true);
WXComponent component = getChild(position);
if (component == null
- || (component instanceof WXRefresh)
- || (component instanceof WXLoading)
- || (component.getDomObject() != null && component.getDomObject().isFixed())
- ) {
+ || (component instanceof WXRefresh)
+ || (component instanceof WXLoading)
+ || (component.isFixed())
+ ) {
if (WXEnvironment.isApkDebugable()) {
WXLogUtils.d(TAG, "Bind WXRefresh & WXLoading " + holder);
}
if(component instanceof WXBaseRefresh
&& holder.getView() != null
- && component.getDomObject() != null
- && (component.getDomObject().getAttrs().get("holderBackground") != null)){
- Object holderBackground = component.getDomObject().getAttrs().get("holderBackground");
+ && (component.getAttrs().get("holderBackground") != null)){
+ Object holderBackground = component.getAttrs().get("holderBackground");
int color = WXResourceUtils.getColor(holderBackground.toString(), Color.WHITE);
- holder.getView().setBackgroundColor(color);
- holder.getView().setVisibility(View.VISIBLE);
- holder.getView().postInvalidate();
+ holder.getView().setBackgroundColor(color);
+ holder.getView().setVisibility(View.VISIBLE);
+ holder.getView().postInvalidate();
}
return;
}
@@ -899,10 +887,8 @@ public abstract class BasicListComponent<T extends ViewGroup & ListComponentView
WXCell cell = (WXCell) holder.getComponent();
boolean isExcluded = DEFAULT_EXCLUDED;
- if(cell.getDomObject() != null){
- WXAttr cellAttrs = cell.getDomObject().getAttrs();
- isExcluded = WXUtils.getBoolean(cellAttrs.get(EXCLUDED), DEFAULT_EXCLUDED);
- }
+ WXAttr cellAttrs = cell.getAttrs();
+ isExcluded = WXUtils.getBoolean(cellAttrs.get(EXCLUDED), DEFAULT_EXCLUDED);
mDragHelper.setDragExcluded(holder, isExcluded);
@@ -970,7 +956,7 @@ public abstract class BasicListComponent<T extends ViewGroup & ListComponentView
|| component.isUsing()) {
continue;
}
- if (component.getDomObject() != null && component.getDomObject().isFixed()) {
+ if (component.isFixed()) {
return createVHForFakeComponent(viewType);
} else {
if (component instanceof WXCell) {
@@ -1048,9 +1034,8 @@ public abstract class BasicListComponent<T extends ViewGroup & ListComponentView
deque.add(root);
while (!deque.isEmpty()) {
WXComponent curComponent = deque.removeFirst();
- ImmutableDomObject object = curComponent.getDomObject();
- if (object != null) {
- String isAnchorSet = WXUtils.getString(object.getAttrs().get(anchorName), null);
+ if (curComponent != null) {
+ String isAnchorSet = WXUtils.getString(curComponent.getAttrs().get(anchorName), null);
//hit
if (isAnchorSet != null && isAnchorSet.equals("true")) {
@@ -1076,12 +1061,12 @@ public abstract class BasicListComponent<T extends ViewGroup & ListComponentView
}
- private String getTriggerType(@Nullable ImmutableDomObject domObject) {
+ private String getTriggerType(@Nullable WXComponent component) {
String triggerType = DEFAULT_TRIGGER_TYPE;
- if (domObject == null) {
+ if (component == null) {
return triggerType;
}
- triggerType = WXUtils.getString(domObject.getAttrs().get(DRAG_TRIGGER_TYPE), DEFAULT_TRIGGER_TYPE);
+ triggerType = WXUtils.getString(component.getAttrs().get(DRAG_TRIGGER_TYPE), DEFAULT_TRIGGER_TYPE);
if (!DragTriggerType.LONG_PRESS.equals(triggerType) && !DragTriggerType.PAN.equals(triggerType)) {
triggerType = DEFAULT_TRIGGER_TYPE;
}
@@ -1136,8 +1121,8 @@ public abstract class BasicListComponent<T extends ViewGroup & ListComponentView
private int generateViewType(WXComponent component) {
long id;
try {
- id = Integer.parseInt(component.getDomObject().getRef());
- String type = component.getDomObject().getAttrs().getScope();
+ id = Integer.parseInt(component.getRef());
+ String type = component.getAttrs().getScope();
if (!TextUtils.isEmpty(type)) {
if (mRefToViewType == null) {
@@ -1179,7 +1164,7 @@ public abstract class BasicListComponent<T extends ViewGroup & ListComponentView
public long getItemId(int position) {
long id;
try {
- id = Long.parseLong(getChild(position).getDomObject().getRef());
+ id = Long.parseLong(getChild(position).getRef());
} catch (RuntimeException e) {
WXLogUtils.e(TAG, WXLogUtils.getStackTrace(e));
id = RecyclerView.NO_ID;
@@ -1190,14 +1175,14 @@ public abstract class BasicListComponent<T extends ViewGroup & ListComponentView
@Override
public void onLoadMore(int offScreenY) {
try {
- String offset = getDomObject().getAttrs().getLoadMoreOffset();
+ String offset = getAttrs().getLoadMoreOffset();
if (TextUtils.isEmpty(offset)) {
offset = "0";
}
float offsetParsed = WXViewUtils.getRealPxByWidth(Integer.parseInt(offset),getInstance().getInstanceViewPortWidth());
- if (offScreenY <= offsetParsed) {
+ if (offScreenY < offsetParsed) {
if (mListCellCount != mChildren.size()
|| mForceLoadmoreNextTime) {
@@ -1214,13 +1199,13 @@ public abstract class BasicListComponent<T extends ViewGroup & ListComponentView
@Override
public void notifyAppearStateChange(int firstVisible, int lastVisible, int directionX, int directionY) {
if(mAppearComponentsRunnable != null) {
- getHostView().removeCallbacks(mAppearComponentsRunnable);
- mAppearComponentsRunnable = null;
+ getHostView().removeCallbacks(mAppearComponentsRunnable);
+ mAppearComponentsRunnable = null;
}
//notify appear state
Iterator<AppearanceHelper> it = mAppearComponents.values().iterator();
String direction = directionY > 0 ? Constants.Value.DIRECTION_UP :
- directionY < 0 ? Constants.Value.DIRECTION_DOWN : null;
+ directionY < 0 ? Constants.Value.DIRECTION_DOWN : null;
if (getOrientation() == Constants.Orientation.HORIZONTAL && directionX != 0) {
direction = directionX > 0 ? Constants.Value.DIRECTION_LEFT : Constants.Value.DIRECTION_RIGHT;
}
@@ -1308,7 +1293,7 @@ public abstract class BasicListComponent<T extends ViewGroup & ListComponentView
offsetY = offsetY - offsetYCorrection;
}
getScrollStartEndHelper().onScrolled(offsetX, offsetY);
- if(!getDomObject().getEvents().contains(Constants.Event.SCROLL)){
+ if(!getEvents().contains(Constants.Event.SCROLL)){
return;
}
if (mFirstEvent) {
@@ -1442,7 +1427,7 @@ public abstract class BasicListComponent<T extends ViewGroup & ListComponentView
public ScrollStartEndHelper getScrollStartEndHelper() {
if(mScrollStartEndHelper == null){
- mScrollStartEndHelper = new ScrollStartEndHelper(this);
+ mScrollStartEndHelper = new ScrollStartEndHelper(this);
}
return mScrollStartEndHelper;
}