feat:Android only add DoricLayer when needed,and align contentview's size to refreshable itself
This commit is contained in:
parent
10f159cfee
commit
ddc1442815
@ -28,7 +28,6 @@ import pub.doric.extension.bridge.DoricMethod;
|
||||
import pub.doric.extension.bridge.DoricPlugin;
|
||||
import pub.doric.extension.bridge.DoricPromise;
|
||||
import pub.doric.navbar.IDoricNavBar;
|
||||
import pub.doric.utils.DoricUtils;
|
||||
import pub.doric.utils.ThreadMode;
|
||||
|
||||
/**
|
||||
@ -62,7 +61,7 @@ public class NavBarPlugin extends DoricJavaPlugin {
|
||||
JSObject jsObject = jsDecoder.decode().asObject();
|
||||
boolean hidden = jsObject.getProperty("hidden").asBoolean().value();
|
||||
navBar.setHidden(hidden);
|
||||
View v = getDoricContext().getRootNode().getDoricLayer();
|
||||
View v = getDoricContext().getRootNode().getNodeView();
|
||||
ViewGroup.LayoutParams params = v.getLayoutParams();
|
||||
if (params instanceof ViewGroup.MarginLayoutParams) {
|
||||
((ViewGroup.MarginLayoutParams) params).topMargin =
|
||||
|
@ -85,7 +85,7 @@ public class RefreshableNode extends SuperNode<DoricSwipeLayout> implements Pull
|
||||
mContentNode.setId(viewId);
|
||||
mContentNode.init(this);
|
||||
mContentNode.blend(props);
|
||||
mView.addView(mContentNode.getDoricLayer());
|
||||
mView.addView(mContentNode.getNodeView());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -93,7 +93,7 @@ public class RefreshableNode extends SuperNode<DoricSwipeLayout> implements Pull
|
||||
mContentNode.setId(viewId);
|
||||
mContentNode.init(this);
|
||||
mContentNode.blend(props);
|
||||
mView.addView(mContentNode.getDoricLayer());
|
||||
mView.addView(mContentNode.getNodeView());
|
||||
}
|
||||
}
|
||||
|
||||
@ -117,7 +117,7 @@ public class RefreshableNode extends SuperNode<DoricSwipeLayout> implements Pull
|
||||
mHeaderNode.setId(viewId);
|
||||
mHeaderNode.init(this);
|
||||
mHeaderNode.blend(props);
|
||||
mView.getRefreshView().setContent(mHeaderNode.getDoricLayer());
|
||||
mView.getRefreshView().setContent(mHeaderNode.getNodeView());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -125,7 +125,7 @@ public class RefreshableNode extends SuperNode<DoricSwipeLayout> implements Pull
|
||||
mHeaderNode.setId(viewId);
|
||||
mHeaderNode.init(this);
|
||||
mHeaderNode.blend(props);
|
||||
mView.getRefreshView().setContent(mHeaderNode.getDoricLayer());
|
||||
mView.getRefreshView().setContent(mHeaderNode.getNodeView());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -75,13 +75,13 @@ public abstract class GroupNode<F extends ViewGroup> extends SuperNode<F> {
|
||||
} else {
|
||||
//Replace this view
|
||||
mChildNodes.remove(idx);
|
||||
mView.removeView(oldNode.getDoricLayer());
|
||||
mView.removeView(oldNode.getNodeView());
|
||||
ViewNode newNode = ViewNode.create(getDoricContext(), type);
|
||||
newNode.setId(id);
|
||||
newNode.init(this);
|
||||
newNode.blend(model.getProperty("props").asObject());
|
||||
mChildNodes.add(idx, newNode);
|
||||
mView.addView(newNode.getDoricLayer(), idx, newNode.getLayoutParams());
|
||||
mView.addView(newNode.getNodeView(), idx, newNode.getLayoutParams());
|
||||
}
|
||||
} else {
|
||||
//Find in remain nodes
|
||||
@ -101,10 +101,10 @@ public abstract class GroupNode<F extends ViewGroup> extends SuperNode<F> {
|
||||
mChildNodes.set(idx, reused);
|
||||
mChildNodes.set(position, abandoned);
|
||||
//View swap index
|
||||
mView.removeView(reused.getDoricLayer());
|
||||
mView.addView(reused.getDoricLayer(), idx);
|
||||
mView.removeView(abandoned.getDoricLayer());
|
||||
mView.addView(abandoned.getDoricLayer(), position);
|
||||
mView.removeView(reused.getNodeView());
|
||||
mView.addView(reused.getNodeView(), idx);
|
||||
mView.removeView(abandoned.getNodeView());
|
||||
mView.addView(abandoned.getNodeView(), position);
|
||||
} else {
|
||||
//Not found,insert
|
||||
ViewNode newNode = ViewNode.create(getDoricContext(), type);
|
||||
@ -113,7 +113,7 @@ public abstract class GroupNode<F extends ViewGroup> extends SuperNode<F> {
|
||||
newNode.blend(model.getProperty("props").asObject());
|
||||
|
||||
mChildNodes.add(idx, newNode);
|
||||
mView.addView(newNode.getDoricLayer(), idx, newNode.getLayoutParams());
|
||||
mView.addView(newNode.getNodeView(), idx, newNode.getLayoutParams());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -124,13 +124,13 @@ public abstract class GroupNode<F extends ViewGroup> extends SuperNode<F> {
|
||||
newNode.init(this);
|
||||
newNode.blend(model.getProperty("props").asObject());
|
||||
mChildNodes.add(newNode);
|
||||
mView.addView(newNode.getDoricLayer(), idx, newNode.getLayoutParams());
|
||||
mView.addView(newNode.getNodeView(), idx, newNode.getLayoutParams());
|
||||
}
|
||||
}
|
||||
int size = mChildNodes.size();
|
||||
for (int idx = mChildViewIds.size(); idx < size; idx++) {
|
||||
ViewNode viewNode = mChildNodes.remove(mChildViewIds.size());
|
||||
mView.removeView(viewNode.getDoricLayer());
|
||||
mView.removeView(viewNode.getNodeView());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -36,7 +36,7 @@ public class RootNode extends StackNode {
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getDoricLayer() {
|
||||
public View getNodeView() {
|
||||
return mView;
|
||||
}
|
||||
|
||||
|
@ -86,7 +86,7 @@ public class ScrollerNode extends SuperNode<HVScrollView> {
|
||||
mChildNode.setId(viewId);
|
||||
mChildNode.init(this);
|
||||
mChildNode.blend(props);
|
||||
mView.addView(mChildNode.getDoricLayer());
|
||||
mView.addView(mChildNode.getNodeView());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -94,7 +94,7 @@ public class ScrollerNode extends SuperNode<HVScrollView> {
|
||||
mChildNode.setId(viewId);
|
||||
mChildNode.init(this);
|
||||
mChildNode.blend(props);
|
||||
mView.addView(mChildNode.getDoricLayer());
|
||||
mView.addView(mChildNode.getNodeView());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -21,6 +21,8 @@ import android.view.ViewGroup;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import pub.doric.DoricContext;
|
||||
import pub.doric.DoricRegistry;
|
||||
import pub.doric.async.AsyncResult;
|
||||
@ -60,11 +62,8 @@ public abstract class ViewNode<T extends View> extends DoricContextHolder {
|
||||
}
|
||||
this.mSuperNode = superNode;
|
||||
this.mLayoutParams = superNode.generateDefaultLayoutParams();
|
||||
this.doricLayer = new DoricLayer(getContext());
|
||||
this.doricLayer.setLayoutParams(mLayoutParams);
|
||||
this.mView = build();
|
||||
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(mLayoutParams.width, mLayoutParams.height);
|
||||
doricLayer.addView(mView, params);
|
||||
this.mView.setLayoutParams(mLayoutParams);
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
@ -75,8 +74,12 @@ public abstract class ViewNode<T extends View> extends DoricContextHolder {
|
||||
return mType;
|
||||
}
|
||||
|
||||
public View getDoricLayer() {
|
||||
public View getNodeView() {
|
||||
if (doricLayer != null) {
|
||||
return doricLayer;
|
||||
} else {
|
||||
return mView;
|
||||
}
|
||||
}
|
||||
|
||||
public Context getContext() {
|
||||
@ -91,6 +94,7 @@ public abstract class ViewNode<T extends View> extends DoricContextHolder {
|
||||
blend(mView, prop, jsObject.getProperty(prop));
|
||||
}
|
||||
}
|
||||
if (doricLayer != null) {
|
||||
ViewGroup.LayoutParams params = mView.getLayoutParams();
|
||||
if (params != null) {
|
||||
params.width = mLayoutParams.width;
|
||||
@ -108,6 +112,7 @@ public abstract class ViewNode<T extends View> extends DoricContextHolder {
|
||||
|
||||
mView.setLayoutParams(params);
|
||||
}
|
||||
}
|
||||
|
||||
protected void blend(T view, String name, JSValue prop) {
|
||||
switch (name) {
|
||||
@ -139,34 +144,30 @@ public abstract class ViewNode<T extends View> extends DoricContextHolder {
|
||||
setLayoutConfig(prop.asObject());
|
||||
break;
|
||||
case "border":
|
||||
if (prop.isObject() && doricLayer != null) {
|
||||
doricLayer.setBorder(DoricUtils.dp2px(prop.asObject().getProperty("width").asNumber().toFloat()),
|
||||
if (prop.isObject()) {
|
||||
requireDoricLayer().setBorder(DoricUtils.dp2px(prop.asObject().getProperty("width").asNumber().toFloat()),
|
||||
prop.asObject().getProperty("color").asNumber().toInt());
|
||||
}
|
||||
break;
|
||||
case "corners":
|
||||
if (doricLayer != null) {
|
||||
if (prop.isNumber()) {
|
||||
doricLayer.setCornerRadius(DoricUtils.dp2px(prop.asNumber().toFloat()));
|
||||
requireDoricLayer().setCornerRadius(DoricUtils.dp2px(prop.asNumber().toFloat()));
|
||||
} else if (prop.isObject()) {
|
||||
JSValue lt = prop.asObject().getProperty("leftTop");
|
||||
JSValue rt = prop.asObject().getProperty("rightTop");
|
||||
JSValue rb = prop.asObject().getProperty("rightBottom");
|
||||
JSValue lb = prop.asObject().getProperty("leftBottom");
|
||||
doricLayer.setCornerRadius(
|
||||
requireDoricLayer().setCornerRadius(
|
||||
DoricUtils.dp2px(lt.isNumber() ? lt.asNumber().toFloat() : 0),
|
||||
DoricUtils.dp2px(rt.isNumber() ? rt.asNumber().toFloat() : 0),
|
||||
DoricUtils.dp2px(rb.isNumber() ? rb.asNumber().toFloat() : 0),
|
||||
DoricUtils.dp2px(lb.isNumber() ? lb.asNumber().toFloat() : 0)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
case "shadow":
|
||||
if (doricLayer != null) {
|
||||
if (prop.isObject()) {
|
||||
doricLayer.setShadow(
|
||||
requireDoricLayer().setShadow(
|
||||
prop.asObject().getProperty("color").asNumber().toInt(),
|
||||
(int) (prop.asObject().getProperty("opacity").asNumber().toFloat() * 255),
|
||||
DoricUtils.dp2px(prop.asObject().getProperty("radius").asNumber().toFloat()),
|
||||
@ -174,13 +175,32 @@ public abstract class ViewNode<T extends View> extends DoricContextHolder {
|
||||
DoricUtils.dp2px(prop.asObject().getProperty("offsetY").asNumber().toFloat())
|
||||
);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private DoricLayer requireDoricLayer() {
|
||||
if (doricLayer == null) {
|
||||
doricLayer = new DoricLayer(getContext());
|
||||
doricLayer.setLayoutParams(mLayoutParams);
|
||||
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(mLayoutParams.width, mLayoutParams.height);
|
||||
if (mView.getParent() instanceof ViewGroup) {
|
||||
//Already added in
|
||||
ViewGroup superview = (ViewGroup) mView.getParent();
|
||||
int index = superview.indexOfChild(mView);
|
||||
superview.removeView(mView);
|
||||
doricLayer.addView(mView, params);
|
||||
superview.addView(doricLayer, index);
|
||||
} else {
|
||||
doricLayer.addView(mView, params);
|
||||
}
|
||||
}
|
||||
return doricLayer;
|
||||
}
|
||||
|
||||
String[] getIdList() {
|
||||
LinkedList<String> ids = new LinkedList<>();
|
||||
ViewNode viewNode = this;
|
||||
|
@ -54,7 +54,7 @@ class ListAdapter extends RecyclerView.Adapter<ListAdapter.DoricViewHolder> {
|
||||
public DoricViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
ListItemNode node = (ListItemNode) ViewNode.create(listNode.getDoricContext(), "ListItem");
|
||||
node.init(listNode);
|
||||
return new DoricViewHolder(node, node.getDoricLayer());
|
||||
return new DoricViewHolder(node, node.getNodeView());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -50,7 +50,7 @@ public class ListItemNode extends StackNode {
|
||||
@Override
|
||||
public void blend(JSObject jsObject) {
|
||||
super.blend(jsObject);
|
||||
getDoricLayer().getLayoutParams().width = getLayoutParams().width;
|
||||
getDoricLayer().getLayoutParams().height = getLayoutParams().height;
|
||||
getNodeView().getLayoutParams().width = getLayoutParams().width;
|
||||
getNodeView().getLayoutParams().height = getLayoutParams().height;
|
||||
}
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ class SlideAdapter extends RecyclerView.Adapter<SlideAdapter.DoricViewHolder> {
|
||||
public DoricViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
SlideItemNode node = (SlideItemNode) ViewNode.create(sliderNode.getDoricContext(), "SlideItem");
|
||||
node.init(sliderNode);
|
||||
return new DoricViewHolder(node, node.getDoricLayer());
|
||||
return new DoricViewHolder(node, node.getNodeView());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -50,7 +50,7 @@ public class SlideItemNode extends StackNode {
|
||||
@Override
|
||||
public void blend(JSObject jsObject) {
|
||||
super.blend(jsObject);
|
||||
getDoricLayer().getLayoutParams().width = getLayoutParams().width;
|
||||
getDoricLayer().getLayoutParams().height = getLayoutParams().height;
|
||||
getNodeView().getLayoutParams().width = getLayoutParams().width;
|
||||
getNodeView().getLayoutParams().height = getLayoutParams().height;
|
||||
}
|
||||
}
|
||||
|
@ -49,8 +49,8 @@ - (DoricViewNode *)subNodeWithViewId:(NSString *)viewId {
|
||||
|
||||
- (void)blend:(NSDictionary *)props {
|
||||
[super blend:props];
|
||||
[self blendHeader];
|
||||
[self blendContent];
|
||||
[self blendHeader];
|
||||
}
|
||||
|
||||
- (void)blendContent {
|
||||
|
@ -5,6 +5,7 @@
|
||||
#import "DoricSwipeRefreshLayout.h"
|
||||
#import "UIView+Doric.h"
|
||||
#import "DoricLayouts.h"
|
||||
#import "Doric.h"
|
||||
|
||||
@interface DoricSwipeRefreshLayout () <UIScrollViewDelegate>
|
||||
|
||||
@ -53,9 +54,16 @@ - (BOOL)requestFromSubview:(UIView *)subview {
|
||||
}
|
||||
|
||||
- (void)layoutSelf:(CGSize)targetSize {
|
||||
[super layoutSelf:targetSize];
|
||||
self.headerView.bottom = 0;
|
||||
self.headerView.centerX = self.centerX;
|
||||
self.width = targetSize.width;
|
||||
self.height = targetSize.height;
|
||||
[self.headerView also:^(UIView *it) {
|
||||
[it layoutSelf:[it measureSize:targetSize]];
|
||||
it.bottom = 0;
|
||||
it.centerX = self.centerX;
|
||||
}];
|
||||
[self.contentView also:^(UIView *it) {
|
||||
[it layoutSelf:targetSize];
|
||||
}];
|
||||
self.contentSize = self.frame.size;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user