android:use DoricLinearLayoutCompat instead

This commit is contained in:
pengfei.zhou 2021-07-28 18:50:28 +08:00 committed by osborn
parent 6fb526105b
commit 3b0f13bb99
4 changed files with 30 additions and 23 deletions

View File

@ -15,12 +15,12 @@
*/ */
package pub.doric.shader; package pub.doric.shader;
import android.widget.LinearLayout;
import androidx.appcompat.widget.DoricLinearLayoutCompat;
import pub.doric.DoricContext; import pub.doric.DoricContext;
import pub.doric.extension.bridge.DoricPlugin; import pub.doric.extension.bridge.DoricPlugin;
import com.github.pengfeizhou.jscore.JSObject;
/** /**
* @Description: com.github.penfeizhou.doric.shader * @Description: com.github.penfeizhou.doric.shader
@ -34,9 +34,9 @@ public class HLayoutNode extends LinearNode {
} }
@Override @Override
protected LinearLayout build() { protected DoricLinearLayoutCompat build() {
LinearLayout linearLayout = super.build(); DoricLinearLayoutCompat linearLayout = super.build();
linearLayout.setOrientation(LinearLayout.HORIZONTAL); linearLayout.setOrientation(DoricLinearLayoutCompat.HORIZONTAL);
return linearLayout; return linearLayout;
} }
} }

View File

@ -18,7 +18,8 @@ package pub.doric.shader;
import android.content.Context; import android.content.Context;
import android.graphics.drawable.ShapeDrawable; import android.graphics.drawable.ShapeDrawable;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.LinearLayout;
import androidx.appcompat.widget.DoricLinearLayoutCompat;
import com.github.pengfeizhou.jscore.JSObject; import com.github.pengfeizhou.jscore.JSObject;
import com.github.pengfeizhou.jscore.JSValue; import com.github.pengfeizhou.jscore.JSValue;
@ -31,9 +32,9 @@ import pub.doric.utils.DoricUtils;
* @Author: pengfei.zhou * @Author: pengfei.zhou
* @CreateDate: 2019-07-23 * @CreateDate: 2019-07-23
*/ */
public class LinearNode extends GroupNode<LinearLayout> { public class LinearNode extends GroupNode<DoricLinearLayoutCompat> {
private static class MaximumLinearLayout extends LinearLayout { private static class MaximumLinearLayout extends DoricLinearLayoutCompat {
private int maxWidth = Integer.MAX_VALUE; private int maxWidth = Integer.MAX_VALUE;
private int maxHeight = Integer.MAX_VALUE; private int maxHeight = Integer.MAX_VALUE;
@ -55,6 +56,11 @@ public class LinearNode extends GroupNode<LinearLayout> {
super.onMeasure(widthMeasureSpec, heightMeasureSpec); super.onMeasure(widthMeasureSpec, heightMeasureSpec);
} }
} }
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
super.onLayout(changed, l, t, r, b);
}
} }
public LinearNode(DoricContext doricContext) { public LinearNode(DoricContext doricContext) {
@ -75,32 +81,32 @@ public class LinearNode extends GroupNode<LinearLayout> {
} }
@Override @Override
protected void blendSubLayoutConfig(ViewNode viewNode, JSObject layoutConfig) { protected void blendSubLayoutConfig(ViewNode<?> viewNode, JSObject layoutConfig) {
super.blendSubLayoutConfig(viewNode, layoutConfig); super.blendSubLayoutConfig(viewNode, layoutConfig);
JSValue jsValue = layoutConfig.getProperty("alignment"); JSValue jsValue = layoutConfig.getProperty("alignment");
if (jsValue.isNumber()) { if (jsValue.isNumber()) {
((LinearLayout.LayoutParams) viewNode.getLayoutParams()).gravity = jsValue.asNumber().toInt(); ((DoricLinearLayoutCompat.LayoutParams) viewNode.getLayoutParams()).gravity = jsValue.asNumber().toInt();
} }
JSValue weight = layoutConfig.getProperty("weight"); JSValue weight = layoutConfig.getProperty("weight");
if (weight.isNumber()) { if (weight.isNumber()) {
((LinearLayout.LayoutParams) viewNode.getLayoutParams()).weight = weight.asNumber().toInt(); ((DoricLinearLayoutCompat.LayoutParams) viewNode.getLayoutParams()).weight = weight.asNumber().toInt();
} }
} }
@Override @Override
protected ViewGroup.LayoutParams generateDefaultLayoutParams() { protected ViewGroup.LayoutParams generateDefaultLayoutParams() {
return new LinearLayout.LayoutParams(0, 0); return new DoricLinearLayoutCompat.LayoutParams(0, 0);
} }
@Override @Override
protected LinearLayout build() { protected DoricLinearLayoutCompat build() {
LinearLayout linearLayout= new MaximumLinearLayout(getContext()); DoricLinearLayoutCompat linearLayout = new MaximumLinearLayout(getContext());
linearLayout.setBaselineAligned(false); linearLayout.setBaselineAligned(false);
return linearLayout; return linearLayout;
} }
@Override @Override
protected void blend(LinearLayout view, String name, JSValue prop) { protected void blend(DoricLinearLayoutCompat view, String name, JSValue prop) {
switch (name) { switch (name) {
case "space": case "space":
if (!prop.isNumber()) { if (!prop.isNumber()) {
@ -110,12 +116,12 @@ public class LinearNode extends GroupNode<LinearLayout> {
if (view.getDividerDrawable() == null) { if (view.getDividerDrawable() == null) {
shapeDrawable = new ShapeDrawable(); shapeDrawable = new ShapeDrawable();
shapeDrawable.setAlpha(0); shapeDrawable.setAlpha(0);
view.setShowDividers(LinearLayout.SHOW_DIVIDER_MIDDLE); view.setShowDividers(DoricLinearLayoutCompat.SHOW_DIVIDER_MIDDLE);
} else { } else {
shapeDrawable = (ShapeDrawable) view.getDividerDrawable(); shapeDrawable = (ShapeDrawable) view.getDividerDrawable();
view.setDividerDrawable(null); view.setDividerDrawable(null);
} }
if (view.getOrientation() == LinearLayout.VERTICAL) { if (view.getOrientation() == DoricLinearLayoutCompat.VERTICAL) {
shapeDrawable.setIntrinsicHeight(DoricUtils.dp2px(prop.asNumber().toFloat())); shapeDrawable.setIntrinsicHeight(DoricUtils.dp2px(prop.asNumber().toFloat()));
} else { } else {
shapeDrawable.setIntrinsicWidth(DoricUtils.dp2px(prop.asNumber().toFloat())); shapeDrawable.setIntrinsicWidth(DoricUtils.dp2px(prop.asNumber().toFloat()));

View File

@ -15,7 +15,7 @@
*/ */
package pub.doric.shader; package pub.doric.shader;
import android.widget.LinearLayout; import androidx.appcompat.widget.DoricLinearLayoutCompat;
import pub.doric.DoricContext; import pub.doric.DoricContext;
import pub.doric.extension.bridge.DoricPlugin; import pub.doric.extension.bridge.DoricPlugin;
@ -32,9 +32,9 @@ public class VLayoutNode extends LinearNode {
} }
@Override @Override
protected LinearLayout build() { protected DoricLinearLayoutCompat build() {
LinearLayout linearLayout = super.build(); DoricLinearLayoutCompat linearLayout = super.build();
linearLayout.setOrientation(LinearLayout.VERTICAL); linearLayout.setOrientation(DoricLinearLayoutCompat.VERTICAL);
return linearLayout; return linearLayout;
} }

View File

@ -39,6 +39,7 @@ import android.widget.FrameLayout;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.appcompat.widget.DoricLinearLayoutCompat;
import androidx.interpolator.view.animation.FastOutSlowInInterpolator; import androidx.interpolator.view.animation.FastOutSlowInInterpolator;
import com.github.pengfeizhou.jscore.JSArray; import com.github.pengfeizhou.jscore.JSArray;
@ -159,7 +160,7 @@ public abstract class ViewNode<T extends View> extends DoricContextHolder {
} else { } else {
params = mLayoutParams; params = mLayoutParams;
} }
if (mLayoutParams instanceof LinearLayout.LayoutParams && ((LinearLayout.LayoutParams) mLayoutParams).weight > 0) { if (mLayoutParams instanceof DoricLinearLayoutCompat.LayoutParams && ((DoricLinearLayoutCompat.LayoutParams) mLayoutParams).weight > 0) {
if (mSuperNode instanceof VLayoutNode) { if (mSuperNode instanceof VLayoutNode) {
params.height = ViewGroup.LayoutParams.MATCH_PARENT; params.height = ViewGroup.LayoutParams.MATCH_PARENT;
} else if (mSuperNode instanceof HLayoutNode) { } else if (mSuperNode instanceof HLayoutNode) {