Merge branch 'feature/slider' into 'master'
Feature/slider See merge request !18
This commit is contained in:
@@ -19,7 +19,7 @@ import android.graphics.drawable.Drawable;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import android.view.ViewGroup;
|
||||
import android.text.TextUtils;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
@@ -31,7 +31,7 @@ import com.bumptech.glide.request.target.Target;
|
||||
import pub.doric.DoricContext;
|
||||
import pub.doric.extension.bridge.DoricPlugin;
|
||||
|
||||
import com.github.pengfeizhou.jscore.JSObject;
|
||||
import com.github.pengfeizhou.jscore.JSONBuilder;
|
||||
import com.github.pengfeizhou.jscore.JSValue;
|
||||
|
||||
/**
|
||||
@@ -41,6 +41,8 @@ import com.github.pengfeizhou.jscore.JSValue;
|
||||
*/
|
||||
@DoricPlugin(name = "Image")
|
||||
public class ImageNode extends ViewNode<ImageView> {
|
||||
private String loadCallbackId = "";
|
||||
|
||||
public ImageNode(DoricContext doricContext) {
|
||||
super(doricContext);
|
||||
}
|
||||
@@ -52,22 +54,51 @@ public class ImageNode extends ViewNode<ImageView> {
|
||||
|
||||
@Override
|
||||
protected void blend(ImageView view, String name, JSValue prop) {
|
||||
if ("imageUrl".equals(name)) {
|
||||
Glide.with(getContext()).load(prop.asString().value())
|
||||
.listener(new RequestListener<Drawable>() {
|
||||
@Override
|
||||
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
|
||||
return false;
|
||||
}
|
||||
switch (name) {
|
||||
case "imageUrl":
|
||||
Glide.with(getContext()).load(prop.asString().value())
|
||||
.listener(new RequestListener<Drawable>() {
|
||||
@Override
|
||||
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
|
||||
if (!TextUtils.isEmpty(loadCallbackId)) {
|
||||
callJSResponse(loadCallbackId);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
|
||||
return false;
|
||||
}
|
||||
})
|
||||
.into(view);
|
||||
} else {
|
||||
super.blend(view, name, prop);
|
||||
@Override
|
||||
public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
|
||||
if (!TextUtils.isEmpty(loadCallbackId)) {
|
||||
callJSResponse(loadCallbackId, new JSONBuilder()
|
||||
.put("width", resource.getIntrinsicWidth())
|
||||
.put("height", resource.getIntrinsicHeight())
|
||||
.toJSONObject());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
})
|
||||
.into(view);
|
||||
break;
|
||||
case "scaleType":
|
||||
int scaleType = prop.asNumber().toInt();
|
||||
switch (scaleType) {
|
||||
case 1:
|
||||
view.setScaleType(ImageView.ScaleType.FIT_CENTER);
|
||||
break;
|
||||
case 2:
|
||||
view.setScaleType(ImageView.ScaleType.CENTER_CROP);
|
||||
break;
|
||||
default:
|
||||
view.setScaleType(ImageView.ScaleType.FIT_XY);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "loadCallback":
|
||||
this.loadCallbackId = prop.asString().value();
|
||||
break;
|
||||
default:
|
||||
super.blend(view, name, prop);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -57,6 +57,8 @@ public class TextNode extends ViewNode<TextView> {
|
||||
case "textAlignment":
|
||||
view.setGravity(prop.asNumber().toInt() | Gravity.CENTER_VERTICAL);
|
||||
break;
|
||||
case "numberOfLines":
|
||||
break;
|
||||
default:
|
||||
super.blend(view, name, prop);
|
||||
break;
|
||||
|
@@ -135,12 +135,6 @@ public class HVScrollView extends FrameLayout implements NestedScrollingParent,
|
||||
*/
|
||||
private VelocityTracker mVelocityTracker;
|
||||
|
||||
/**
|
||||
* When set to true, the scroll view measure its child to make it fill the currently
|
||||
* visible area.
|
||||
*/
|
||||
private boolean mFillViewport;
|
||||
|
||||
/**
|
||||
* Whether arrow scrolling is animated.
|
||||
*/
|
||||
@@ -203,9 +197,6 @@ public class HVScrollView extends FrameLayout implements NestedScrollingParent,
|
||||
|
||||
final TypedArray a = context.obtainStyledAttributes(
|
||||
attrs, SCROLLVIEW_STYLEABLE, defStyleAttr, 0);
|
||||
|
||||
setFillViewport(a.getBoolean(0, false));
|
||||
|
||||
a.recycle();
|
||||
|
||||
mParentHelper = new NestedScrollingParentHelper(this);
|
||||
@@ -513,30 +504,6 @@ public class HVScrollView extends FrameLayout implements NestedScrollingParent,
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates whether this ScrollView's content is stretched to fill the viewport.
|
||||
*
|
||||
* @return True if the content fills the viewport, false otherwise.
|
||||
* @attr name android:fillViewport
|
||||
*/
|
||||
public boolean isFillViewport() {
|
||||
return mFillViewport;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether this ScrollView should stretch its content height to fill the viewport or not.
|
||||
*
|
||||
* @param fillViewport True to stretch the content's height to the viewport's
|
||||
* boundaries, false otherwise.
|
||||
* @attr name android:fillViewport
|
||||
*/
|
||||
public void setFillViewport(boolean fillViewport) {
|
||||
if (fillViewport != mFillViewport) {
|
||||
mFillViewport = fillViewport;
|
||||
requestLayout();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Whether arrow scrolling will animate its transition.
|
||||
*/
|
||||
@@ -566,10 +533,6 @@ public class HVScrollView extends FrameLayout implements NestedScrollingParent,
|
||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||
|
||||
if (!mFillViewport) {
|
||||
return;
|
||||
}
|
||||
|
||||
final int widthMode = MeasureSpec.getMode(widthMeasureSpec);
|
||||
final int heightMode = MeasureSpec.getMode(heightMeasureSpec);
|
||||
if (heightMode == MeasureSpec.UNSPECIFIED && widthMode == MeasureSpec.UNSPECIFIED) {
|
||||
@@ -587,14 +550,17 @@ public class HVScrollView extends FrameLayout implements NestedScrollingParent,
|
||||
int childWidthMeasureSpec;
|
||||
int childHeightMeasureSpec;
|
||||
final FrameLayout.LayoutParams lp = (LayoutParams) child.getLayoutParams();
|
||||
if (child.getMeasuredWidth() < width) {
|
||||
if (lp.width != ViewGroup.LayoutParams.MATCH_PARENT && lp.height != ViewGroup.LayoutParams.MATCH_PARENT) {
|
||||
return;
|
||||
}
|
||||
if (child.getMeasuredWidth() < width && lp.width == ViewGroup.LayoutParams.MATCH_PARENT) {
|
||||
childWidthMeasureSpec = MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY);
|
||||
} else {
|
||||
widthMeasureSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
|
||||
childWidthMeasureSpec = getChildMeasureSpec(widthMeasureSpec,
|
||||
getPaddingLeft() + getPaddingRight(), lp.width);
|
||||
}
|
||||
if (child.getMeasuredHeight() < height) {
|
||||
if (child.getMeasuredHeight() < height && lp.height == ViewGroup.LayoutParams.MATCH_PARENT) {
|
||||
childHeightMeasureSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY);
|
||||
} else {
|
||||
heightMeasureSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
|
||||
|
Reference in New Issue
Block a user