add handling layoutconfig in flexlayout
This commit is contained in:
@@ -34,6 +34,7 @@ import com.bumptech.glide.request.RequestOptions;
|
||||
import com.bumptech.glide.request.target.DrawableImageViewTarget;
|
||||
import com.bumptech.glide.request.target.SizeReadyCallback;
|
||||
import com.bumptech.glide.request.target.Target;
|
||||
import com.facebook.yoga.YogaNode;
|
||||
import com.github.pengfeizhou.jscore.JSONBuilder;
|
||||
import com.github.pengfeizhou.jscore.JSObject;
|
||||
import com.github.pengfeizhou.jscore.JSValue;
|
||||
@@ -47,6 +48,7 @@ import androidx.annotation.Nullable;
|
||||
import jp.wasabeef.glide.transformations.BlurTransformation;
|
||||
import pub.doric.DoricContext;
|
||||
import pub.doric.extension.bridge.DoricPlugin;
|
||||
import pub.doric.shader.flex.FlexNode;
|
||||
import pub.doric.utils.DoricLog;
|
||||
import pub.doric.utils.DoricUtils;
|
||||
|
||||
@@ -83,7 +85,12 @@ public class ImageNode extends ViewNode<ImageView> {
|
||||
|
||||
@Override
|
||||
protected ImageView build() {
|
||||
ImageView imageView = new ImageView(getContext());
|
||||
ImageView imageView = new ImageView(getContext()) {
|
||||
@Override
|
||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||
}
|
||||
};
|
||||
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
|
||||
imageView.setAdjustViewBounds(true);
|
||||
return imageView;
|
||||
@@ -223,6 +230,12 @@ public class ImageNode extends ViewNode<ImageView> {
|
||||
@Override
|
||||
protected void setResource(@Nullable Drawable resource) {
|
||||
super.setResource(resource);
|
||||
if (mSuperNode instanceof FlexNode) {
|
||||
YogaNode node = ((FlexNode) mSuperNode).mView.getYogaNodeForView(mView);
|
||||
if (node != null) {
|
||||
node.dirty();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@@ -50,6 +50,7 @@ import java.util.LinkedList;
|
||||
|
||||
import pub.doric.DoricContext;
|
||||
import pub.doric.DoricRegistry;
|
||||
import pub.doric.R;
|
||||
import pub.doric.async.AsyncResult;
|
||||
import pub.doric.extension.bridge.DoricMethod;
|
||||
import pub.doric.extension.bridge.DoricPromise;
|
||||
@@ -89,6 +90,7 @@ public abstract class ViewNode<T extends View> extends DoricContextHolder {
|
||||
this.mSuperNode = superNode;
|
||||
this.mLayoutParams = superNode.generateDefaultLayoutParams();
|
||||
this.mView = build();
|
||||
this.mView.setTag(R.id.doric_node, this);
|
||||
this.mView.setLayoutParams(mLayoutParams);
|
||||
}
|
||||
|
||||
@@ -106,6 +108,10 @@ public abstract class ViewNode<T extends View> extends DoricContextHolder {
|
||||
return mType;
|
||||
}
|
||||
|
||||
public T getView() {
|
||||
return mView;
|
||||
}
|
||||
|
||||
public View getNodeView() {
|
||||
if (doricLayer != null) {
|
||||
return doricLayer;
|
||||
@@ -466,6 +472,7 @@ public abstract class ViewNode<T extends View> extends DoricContextHolder {
|
||||
} else {
|
||||
doricLayer.addView(mView, params);
|
||||
}
|
||||
this.doricLayer.setTag(R.id.doric_node, this);
|
||||
}
|
||||
return doricLayer;
|
||||
}
|
||||
|
@@ -15,7 +15,9 @@
|
||||
*/
|
||||
package pub.doric.shader.flex;
|
||||
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import com.facebook.yoga.YogaAlign;
|
||||
import com.facebook.yoga.YogaDirection;
|
||||
@@ -32,6 +34,7 @@ import com.github.pengfeizhou.jscore.JSObject;
|
||||
import com.github.pengfeizhou.jscore.JSValue;
|
||||
|
||||
import pub.doric.DoricContext;
|
||||
import pub.doric.R;
|
||||
import pub.doric.extension.bridge.DoricPlugin;
|
||||
import pub.doric.shader.GroupNode;
|
||||
import pub.doric.shader.ViewNode;
|
||||
@@ -56,7 +59,56 @@ public class FlexNode extends GroupNode<YogaLayout> {
|
||||
|
||||
@Override
|
||||
protected YogaLayout build() {
|
||||
return new YogaLayout(getContext());
|
||||
YogaLayout yogaLayout = new YogaLayout(getContext()) {
|
||||
@Override
|
||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
for (int i = 0; i < getChildCount(); i++) {
|
||||
View child = getChildAt(i);
|
||||
ViewNode childNode = (ViewNode) child.getTag(R.id.doric_node);
|
||||
if (childNode != null && childNode.getFlexConfig() == null) {
|
||||
ViewGroup.LayoutParams layoutParams = child.getLayoutParams();
|
||||
int childWidthMeasureSpec;
|
||||
int childHeightMeasureSpec;
|
||||
if (layoutParams.width == ViewGroup.LayoutParams.MATCH_PARENT) {
|
||||
childWidthMeasureSpec = View.MeasureSpec.makeMeasureSpec(
|
||||
0,
|
||||
View.MeasureSpec.AT_MOST);
|
||||
} else if (layoutParams.width == ViewGroup.LayoutParams.WRAP_CONTENT) {
|
||||
childWidthMeasureSpec = View.MeasureSpec.makeMeasureSpec(
|
||||
0,
|
||||
View.MeasureSpec.UNSPECIFIED);
|
||||
} else {
|
||||
childWidthMeasureSpec = View.MeasureSpec.makeMeasureSpec(
|
||||
layoutParams.width,
|
||||
View.MeasureSpec.EXACTLY);
|
||||
}
|
||||
|
||||
if (layoutParams.height == ViewGroup.LayoutParams.MATCH_PARENT) {
|
||||
childHeightMeasureSpec = View.MeasureSpec.makeMeasureSpec(
|
||||
0,
|
||||
View.MeasureSpec.AT_MOST);
|
||||
} else if (layoutParams.height == ViewGroup.LayoutParams.WRAP_CONTENT) {
|
||||
childHeightMeasureSpec = View.MeasureSpec.makeMeasureSpec(
|
||||
0,
|
||||
View.MeasureSpec.UNSPECIFIED);
|
||||
} else {
|
||||
childHeightMeasureSpec = View.MeasureSpec.makeMeasureSpec(
|
||||
layoutParams.height,
|
||||
View.MeasureSpec.EXACTLY);
|
||||
}
|
||||
child.measure(childWidthMeasureSpec, childHeightMeasureSpec);
|
||||
if (layoutParams.width != ViewGroup.LayoutParams.MATCH_PARENT) {
|
||||
getYogaNodeForView(child).setWidth(childNode.getView().getMeasuredWidth());
|
||||
}
|
||||
if (layoutParams.height != ViewGroup.LayoutParams.MATCH_PARENT) {
|
||||
getYogaNodeForView(child).setHeight(childNode.getView().getMeasuredHeight());
|
||||
}
|
||||
}
|
||||
}
|
||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||
}
|
||||
};
|
||||
return yogaLayout;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -84,6 +136,9 @@ public class FlexNode extends GroupNode<YogaLayout> {
|
||||
super.blend(jsObject);
|
||||
for (ViewNode childNode : mChildNodes) {
|
||||
YogaNode yogaNode = this.mView.getYogaNodeForView(childNode.getNodeView());
|
||||
if (childNode.getFlexConfig() != null && childNode.getView() instanceof ImageView) {
|
||||
((ImageView) childNode.getView()).setAdjustViewBounds(false);
|
||||
}
|
||||
if (yogaNode != null) {
|
||||
blendSubFlexConfig(yogaNode, childNode.getFlexConfig());
|
||||
}
|
||||
@@ -92,11 +147,11 @@ public class FlexNode extends GroupNode<YogaLayout> {
|
||||
|
||||
private void blendSubFlexConfig(YogaNode yogaNode, JSObject jsObject) {
|
||||
if (jsObject == null) {
|
||||
return;
|
||||
}
|
||||
for (String name : jsObject.propertySet()) {
|
||||
JSValue value = jsObject.getProperty(name);
|
||||
blendFlexConfig(yogaNode, name, value);
|
||||
} else {
|
||||
for (String name : jsObject.propertySet()) {
|
||||
JSValue value = jsObject.getProperty(name);
|
||||
blendFlexConfig(yogaNode, name, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -3,4 +3,5 @@
|
||||
<item name="doric_mask_loading" type="id" />
|
||||
<item name="doric_mask_error" type="id" />
|
||||
<item name="doric_mask_error_retry" type="id" />
|
||||
<item name="doric_node" type="id" />
|
||||
</resources>
|
Reference in New Issue
Block a user