android: reset view node when reuse this node
This commit is contained in:
parent
60c8651e10
commit
481e643ff9
@ -177,4 +177,9 @@ public class DoricLayer extends MaximumFrameLayout {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
mCornerRadii = null;
|
||||
mBorderPaint = null;
|
||||
mShadowPaint = null;
|
||||
}
|
||||
}
|
||||
|
@ -499,4 +499,20 @@ public class ImageNode extends ViewNode<ImageView> {
|
||||
((Animatable) drawable).stop();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void reset() {
|
||||
super.reset();
|
||||
mView.setImageDrawable(null);
|
||||
mView.setScaleType(ImageView.ScaleType.CENTER_CROP);
|
||||
loadCallbackId = "";
|
||||
isBlur = false;
|
||||
placeHolderImage = null;
|
||||
placeHolderColor = Color.TRANSPARENT;
|
||||
placeHolderImageBase64 = null;
|
||||
errorImage = null;
|
||||
errorColor = Color.TRANSPARENT;
|
||||
errorImageBase64 = null;
|
||||
imageScale = DoricUtils.getScreenScale();
|
||||
}
|
||||
}
|
||||
|
@ -16,6 +16,7 @@
|
||||
package pub.doric.shader;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Typeface;
|
||||
import android.text.Editable;
|
||||
import android.text.InputFilter;
|
||||
@ -478,4 +479,16 @@ public class InputNode extends ViewNode<EditText> implements TextWatcher, View.O
|
||||
}
|
||||
return ret ? null : "";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void reset() {
|
||||
super.reset();
|
||||
mView.setText("");
|
||||
mView.setTextColor(Color.BLACK);
|
||||
mView.setHint("");
|
||||
mView.setHintTextColor(Color.GRAY);
|
||||
onTextChangeId = null;
|
||||
onFocusChangeId = null;
|
||||
beforeTextChangeId = null;
|
||||
}
|
||||
}
|
||||
|
@ -115,4 +115,11 @@ public class SwitchNode extends ViewNode<SwitchCompat> {
|
||||
mView.setThumbTintList(thumbTintList);
|
||||
mView.setTrackTintList(trackTintList);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void reset() {
|
||||
super.reset();
|
||||
mView.setChecked(false);
|
||||
mView.setOnCheckedChangeListener(null);
|
||||
}
|
||||
}
|
||||
|
@ -409,4 +409,18 @@ public class TextNode extends ViewNode<TextView> {
|
||||
textView.getPaint().setShader(textShader);
|
||||
textView.invalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void reset() {
|
||||
super.reset();
|
||||
mView.setText("");
|
||||
mView.setTextColor(Color.BLACK);
|
||||
mView.setGravity(Gravity.CENTER);
|
||||
mView.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL));
|
||||
mView.setMaxLines(1);
|
||||
mView.setSingleLine(true);
|
||||
mView.setEllipsize(TextUtils.TruncateAt.END);
|
||||
mView.getPaint().setStrikeThruText(false);
|
||||
mView.getPaint().setUnderlineText(false);
|
||||
}
|
||||
}
|
||||
|
@ -144,6 +144,9 @@ public abstract class ViewNode<T extends View> extends DoricContextHolder {
|
||||
protected abstract T build();
|
||||
|
||||
public void blend(JSObject jsObject) {
|
||||
if (mSuperNode != null && mSuperNode.mReusable) {
|
||||
reset();
|
||||
}
|
||||
if (jsObject != null) {
|
||||
JSValue value = jsObject.getProperty("layoutConfig");
|
||||
if (value.isObject()) {
|
||||
@ -1186,4 +1189,34 @@ public abstract class ViewNode<T extends View> extends DoricContextHolder {
|
||||
.put("y", DoricUtils.px2dp(position[1]))
|
||||
.toJSONObject();
|
||||
}
|
||||
|
||||
protected void reset() {
|
||||
ViewGroup.LayoutParams layoutParams = getLayoutParams();
|
||||
layoutParams.width = 0;
|
||||
layoutParams.height = 0;
|
||||
if (layoutParams instanceof ViewGroup.MarginLayoutParams) {
|
||||
((ViewGroup.MarginLayoutParams) layoutParams).leftMargin = 0;
|
||||
((ViewGroup.MarginLayoutParams) layoutParams).rightMargin = 0;
|
||||
((ViewGroup.MarginLayoutParams) layoutParams).topMargin = 0;
|
||||
((ViewGroup.MarginLayoutParams) layoutParams).bottomMargin = 0;
|
||||
}
|
||||
setBackgroundColor(Color.TRANSPARENT);
|
||||
setAlpha(1);
|
||||
setTranslationX(0);
|
||||
setTranslationY(0);
|
||||
setScaleX(0);
|
||||
setScaleY(0);
|
||||
setRotation(0);
|
||||
setRotationX(0);
|
||||
setRotationY(0);
|
||||
mView.setPadding(0, 0, 0, 0);
|
||||
mView.setOnClickListener(null);
|
||||
DoricLayer doricLayer = this.doricLayer;
|
||||
if (mView instanceof DoricLayer) {
|
||||
doricLayer = (DoricLayer) mView;
|
||||
}
|
||||
if (doricLayer != null) {
|
||||
doricLayer.reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -383,4 +383,16 @@ public class FlowLayoutNode extends SuperNode<RecyclerView> implements IDoricScr
|
||||
}
|
||||
return jsonArray;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void reset() {
|
||||
super.reset();
|
||||
scrollable = true;
|
||||
loadMore = false;
|
||||
loadMoreViewId = null;
|
||||
onLoadMoreFuncId = null;
|
||||
onScrollFuncId = null;
|
||||
onScrollEndFuncId = null;
|
||||
flowAdapter.renderItemFuncId = null;
|
||||
}
|
||||
}
|
||||
|
@ -352,4 +352,16 @@ public class ListNode extends SuperNode<RecyclerView> implements IDoricScrollabl
|
||||
mView.scrollToPosition(pos);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void reset() {
|
||||
super.reset();
|
||||
scrollable = true;
|
||||
loadMore = false;
|
||||
loadMoreViewId = null;
|
||||
onLoadMoreFuncId = null;
|
||||
onScrollFuncId = null;
|
||||
onScrollEndFuncId = null;
|
||||
renderItemFuncId = null;
|
||||
}
|
||||
}
|
||||
|
@ -252,4 +252,11 @@ public class NestedSliderNode extends GroupNode<ViewPager> implements ViewPager.
|
||||
public int getSlidedPage() {
|
||||
return mView.getCurrentItem();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void reset() {
|
||||
super.reset();
|
||||
onPageSlidedFuncId = null;
|
||||
((CustomViewPager) mView).setScrollable(true);
|
||||
}
|
||||
}
|
||||
|
@ -248,4 +248,12 @@ public class SliderNode extends SuperNode<RecyclerView> {
|
||||
return pageIndex;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void reset() {
|
||||
super.reset();
|
||||
scrollable = true;
|
||||
onPageSlidedFuncId = null;
|
||||
renderPageFuncId = null;
|
||||
}
|
||||
}
|
||||
|
@ -636,5 +636,8 @@ - (void)reset {
|
||||
self.errorColor = nil;
|
||||
self.errorImage = nil;
|
||||
self.errorImageBase64 = nil;
|
||||
self.imageScale = UIScreen.mainScreen.scale;
|
||||
self.blurEffectView = nil;
|
||||
self.view.contentMode = UIViewContentModeScaleAspectFill;
|
||||
}
|
||||
@end
|
||||
|
@ -933,7 +933,11 @@ - (CAMediaTimingFunction *)translateToTimingFunction:(NSNumber *)timingFunction
|
||||
|
||||
- (void)reset {
|
||||
self.view.backgroundColor = UIColor.clearColor;
|
||||
DoricLayoutType doricLayoutType = self.view.doricLayout.layoutType;
|
||||
self.view.doricLayout = [[DoricLayout new] also:^(DoricLayout *it) {
|
||||
it.width = 0;
|
||||
it.height = 0;
|
||||
it.layoutType = doricLayoutType;
|
||||
it.view = self.view;
|
||||
}];
|
||||
|
||||
|
Reference in New Issue
Block a user