add handling layoutconfig in flexlayout
This commit is contained in:
parent
ee864620c1
commit
d29ff4991d
@ -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>
|
File diff suppressed because one or more lines are too long
@ -27,6 +27,16 @@ @interface DoricFlexView : UIView
|
||||
|
||||
@implementation DoricFlexView
|
||||
- (CGSize)sizeThatFits:(CGSize)size {
|
||||
for (UIView *view in self.subviews) {
|
||||
if (!view.doricLayout.disabled) {
|
||||
[view.doricLayout apply];
|
||||
[view configureLayoutWithBlock:^(YGLayout *layout) {
|
||||
layout.isEnabled = YES;
|
||||
layout.width = YGPointValue(view.doricLayout.measuredWidth);
|
||||
layout.height = YGPointValue(view.doricLayout.measuredHeight);
|
||||
}];
|
||||
}
|
||||
}
|
||||
return [self.yoga intrinsicSize];
|
||||
}
|
||||
@end
|
||||
@ -53,6 +63,7 @@ - (void)blendSubNode:(DoricViewNode *)subNode flexConfig:(NSDictionary *)flexCon
|
||||
[subNode.view configureLayoutWithBlock:^(YGLayout *_Nonnull layout) {
|
||||
layout.isEnabled = YES;
|
||||
}];
|
||||
subNode.view.doricLayout.disabled = YES;
|
||||
[self blendYoga:subNode.view.yoga from:flexConfig];
|
||||
}
|
||||
|
||||
@ -195,6 +206,7 @@ - (YGValue)translateYGValueFromProperty:(id)prop {
|
||||
|
||||
- (void)requestLayout {
|
||||
[super requestLayout];
|
||||
|
||||
if (self.view.doricLayout.widthSpec != DoricLayoutFit) {
|
||||
self.view.yoga.width = YGPointValue(self.view.width);
|
||||
}
|
||||
@ -204,7 +216,7 @@ - (void)requestLayout {
|
||||
[self.view.yoga applyLayoutPreservingOrigin:YES];
|
||||
/// Need layout again.
|
||||
for (UIView *view in self.view.subviews) {
|
||||
if (view.yoga.isEnabled) {
|
||||
if ([view isKindOfClass:[DoricFlexView class]]) {
|
||||
continue;
|
||||
}
|
||||
if (view.doricLayout.measuredWidth == view.width && view.doricLayout.measuredHeight == view.height) {
|
||||
|
@ -1705,7 +1705,7 @@ var doric = (function (exports) {
|
||||
(module.exports = function (key, value) {
|
||||
return sharedStore[key] || (sharedStore[key] = value !== undefined ? value : {});
|
||||
})('versions', []).push({
|
||||
version: '3.6.5',
|
||||
version: '3.6.4',
|
||||
mode: 'global',
|
||||
copyright: '© 2020 Denis Pushkarev (zloirock.ru)'
|
||||
});
|
||||
@ -6489,13 +6489,7 @@ var doric = (function (exports) {
|
||||
defer = functionBindContext(port.postMessage, port, 1);
|
||||
// Browsers with postMessage, skip WebWorkers
|
||||
// IE8 has postMessage, but it's sync & typeof its postMessage is 'object'
|
||||
} else if (
|
||||
global_1.addEventListener &&
|
||||
typeof postMessage == 'function' &&
|
||||
!global_1.importScripts &&
|
||||
!fails(post) &&
|
||||
location.protocol !== 'file:'
|
||||
) {
|
||||
} else if (global_1.addEventListener && typeof postMessage == 'function' && !global_1.importScripts && !fails(post)) {
|
||||
defer = post;
|
||||
global_1.addEventListener('message', listener, false);
|
||||
// IE8-
|
||||
@ -9867,7 +9861,7 @@ var doric = (function (exports) {
|
||||
var INVALID_PORT = 'Invalid port';
|
||||
|
||||
var ALPHA = /[A-Za-z]/;
|
||||
var ALPHANUMERIC = /[\d+-.A-Za-z]/;
|
||||
var ALPHANUMERIC = /[\d+\-.A-Za-z]/;
|
||||
var DIGIT = /\d/;
|
||||
var HEX_START = /^(0x|0X)/;
|
||||
var OCT = /^[0-7]+$/;
|
||||
|
2
doric-web/dist/index.js
vendored
2
doric-web/dist/index.js
vendored
@ -4055,7 +4055,7 @@ return __module.exports;
|
||||
var doric_web = (function (exports, axios, sandbox) {
|
||||
'use strict';
|
||||
|
||||
axios = axios && Object.prototype.hasOwnProperty.call(axios, 'default') ? axios['default'] : axios;
|
||||
axios = axios && axios.hasOwnProperty('default') ? axios['default'] : axios;
|
||||
|
||||
class DoricPlugin {
|
||||
constructor(context) {
|
||||
|
2
doric-web/dist/index.js.map
vendored
2
doric-web/dist/index.js.map
vendored
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user