Skip to content
This repository has been archived by the owner on Jun 3, 2021. It is now read-only.

Commit

Permalink
* [android] Add flag in WXCell to decide whether enable flatGUI.
Browse files Browse the repository at this point in the history
  • Loading branch information
YorkShen committed Aug 24, 2017
1 parent 1520660 commit 7663f2b
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 17 deletions.
7 changes: 4 additions & 3 deletions android/sdk/src/main/java/com/taobao/weex/WXSDKInstance.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ public class WXSDKInstance implements IWXActivityStateListener,DomContext, View.
private boolean mNeedValidate = false;
private static volatile int mViewPortWidth = 750;
private int mInstanceViewPortWidth = 750;
private final @NonNull FlatUIIImplementation mUIImp = new FlatGUIIContext();
private final @NonNull
FlatGUIIContext mUIImp =new FlatGUIIContext();

public long mRenderStartNanos;
public int mExecJSTraceId = WXTracing.nextId();
Expand Down Expand Up @@ -200,7 +201,7 @@ public void enableLayerType(boolean enable) {
}

public @NonNull
FlatGUIIContext getFlatUIImp(){
FlatGUIIContext getFlatUIContext(){
return mUIImp;
}

Expand Down Expand Up @@ -248,7 +249,7 @@ public WXSDKInstance(Context context) {
/**
* For unittest only.
*/
@RestrictTo(Scope.LIBRARY)
@RestrictTo(Scope.TESTS)
WXSDKInstance(Context context,String id) {
mInstanceId = id;
init(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ public interface Name {
String NORMAL = "normal";
String ARIA_LABEL = "ariaLabel";
String ARIA_HIDDEN = "ariaHidden";

String FLAT = "flat";
}

public interface Value {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ public final void setLayout(ImmutableDomObject domObject) {

private void setComponentLayoutParams(int realWidth, int realHeight, int realLeft, int realTop,
int realRight, int realBottom, Point rawOffset) {
FlatGUIIContext UIImp = getInstance().getFlatUIImp();
FlatGUIIContext UIImp = getInstance().getFlatUIContext();
WidgetContainer ancestor;
Widget widget;
if ((ancestor = UIImp.getFlatComponentAncestor(this)) != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ protected WXFrameLayout initComponentHostView(@NonNull Context context) {
@Override
public boolean promoteToView(boolean checkAncestor) {
return !intendToBeFlatContainer() ||
getInstance().getFlatUIImp().promoteToView(this, checkAncestor, WXDiv.class);
getInstance().getFlatUIContext().promoteToView(this, checkAncestor, WXDiv.class);
}

/**
Expand All @@ -78,7 +78,7 @@ public boolean promoteToView(boolean checkAncestor) {
@NonNull
public WidgetGroup getOrCreateFlatWidget() {
if (mWidgetGroup == null) {
mWidgetGroup = new WidgetGroup(getInstance().getFlatUIImp().getFlatComponentAncestor(this).getHostView());
mWidgetGroup = new WidgetGroup(getInstance().getFlatUIContext().getFlatComponentAncestor(this).getHostView());
for (int i = 0; i < getChildCount(); i++) {
createChildViewAt(i);
}
Expand All @@ -103,7 +103,7 @@ public void unmountFlatGUI() {

@Override
public boolean intendToBeFlatContainer() {
return getInstance().getFlatUIImp().isFlatUIEnabled() && WXDiv.class.equals(getClass());
return getInstance().getFlatUIContext().isFlatUIEnabled() && WXDiv.class.equals(getClass());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,13 @@ public Integer map(String raw) {

@Override
public boolean promoteToView(boolean checkAncestor) {
return getInstance().getFlatUIImp().promoteToView(this, checkAncestor, WXImage.class);
return getInstance().getFlatUIContext().promoteToView(this, checkAncestor, WXImage.class);
}

@Override
@NonNull public ImageWidget getOrCreateFlatWidget() {
if(imageWidget == null){
imageWidget = new ImageWidget(getInstance().getFlatUIImp().getFlatComponentAncestor(this).getHostView());
imageWidget = new ImageWidget(getInstance().getFlatUIContext().getFlatComponentAncestor(this).getHostView());
}
return imageWidget;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ public class WXText extends WXComponent<WXTextView> implements FlatComponent<Tex

@Override
public boolean promoteToView(boolean checkAncestor) {
return getInstance().getFlatUIImp().promoteToView(this, checkAncestor, WXText.class);
return getInstance().getFlatUIContext().promoteToView(this, checkAncestor, WXText.class);
}

@Override
@NonNull
public TextWidget getOrCreateFlatWidget() {
if (mTextWidget == null) {
mTextWidget = new TextWidget(getInstance().getFlatUIImp().getFlatComponentAncestor(this).getHostView());
mTextWidget = new TextWidget(getInstance().getFlatUIContext().getFlatComponentAncestor(this).getHostView());
}
return mTextWidget;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,18 @@

import android.content.Context;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import com.taobao.weex.WXSDKInstance;
import com.taobao.weex.annotation.Component;
import com.taobao.weex.common.Constants.Name;
import com.taobao.weex.dom.WXDomObject;
import com.taobao.weex.ui.component.WXVContainer;
import com.taobao.weex.ui.flat.WidgetContainer;
import com.taobao.weex.ui.view.WXFrameLayout;
import com.taobao.weex.utils.WXUtils;

/**
* Root component for components in {@link WXListComponent}
Expand Down Expand Up @@ -82,6 +85,17 @@ protected WXFrameLayout initComponentHostView(@NonNull Context context) {
}
}

@Override
protected boolean setProperty(String key, Object param) {
if(TextUtils.equals(Name.FLAT, key)){
getInstance().getFlatUIContext().setFlatUIEnabled(WXUtils.getBoolean(param, false));
return true;
}
else {
return super.setProperty(key, param);
}
}

public int getLocationFromStart(){
return mLastLocationY;
}
Expand Down Expand Up @@ -141,6 +155,6 @@ public void unmountFlatGUI() {
@Override
public boolean intendToBeFlatContainer() {
//TODO Is it possible to remove the cell class judge
return getInstance().getFlatUIImp().isFlatUIEnabled() && WXCell.class.equals(getClass());
return getInstance().getFlatUIContext().isFlatUIEnabled() && WXCell.class.equals(getClass());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,18 @@

//TODO when Weex instance is destroyed, there is a work of garbage collection.
//TODO !!!!The index of weex playground show empty cell sometimes.
//TODO The constructor of FlatGUIContext should have a flag decide whether to enable flagGUI.

@RestrictTo(Scope.LIBRARY)
public class FlatGUIIContext {

private boolean mFlatUIEnabled;

//TODO a union-find should be used to achieve quick merge and find. Map is O(n) for merge, while union-find is O(1).
private Map<WXComponent, WidgetContainer> mWidgetRegistry = new ArrayMap<>();
private Map<WXComponent, AndroidViewWidget> mViewWidgetRegistry = new ArrayMap<>();

public FlatGUIIContext(boolean flatUIEnabled) {
this.mFlatUIEnabled = flatUIEnabled;
@RestrictTo(Scope.LIBRARY)
public void setFlatUIEnabled(boolean flag){
mFlatUIEnabled = flag;
}

public boolean isFlatUIEnabled() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void createChildViewAt(int index) {
if (ret.first != null) {
WXComponent child = ret.first;
Widget flatChild;
FlatGUIIContext uiImp = getInstance().getFlatUIImp();
FlatGUIIContext uiImp = getInstance().getFlatUIContext();
WidgetContainer parent = uiImp.getFlatComponentAncestor(this);
if (parent == null || uiImp.getAndroidViewWidget(this) != null) {
parent = this;
Expand Down

0 comments on commit 7663f2b

Please sign in to comment.