fix: image inside list flushes when loading more or in other situations
This commit is contained in:
parent
75151d57d4
commit
531e2d9298
@ -94,7 +94,7 @@ public class ImageNode extends ViewNode<ImageView> {
|
||||
private JSObject stretchInset = null;
|
||||
private float imageScale = DoricUtils.getScreenScale();
|
||||
private Animatable2Compat.AnimationCallback animationCallback = null;
|
||||
private int scaleType = 0;
|
||||
private int scaleType = 2;
|
||||
|
||||
public ImageNode(DoricContext doricContext) {
|
||||
super(doricContext);
|
||||
@ -170,9 +170,11 @@ public class ImageNode extends ViewNode<ImageView> {
|
||||
if (loadCallback.isString()) {
|
||||
this.loadCallbackId = loadCallback.asString().value();
|
||||
}
|
||||
|
||||
}
|
||||
super.blend(jsObject);
|
||||
if (scaleType == 2 && mView.getScaleType() != ImageView.ScaleType.CENTER_CROP) {
|
||||
mView.setScaleType(ImageView.ScaleType.CENTER_CROP);
|
||||
}
|
||||
}
|
||||
|
||||
private Drawable getPlaceHolderDrawable() {
|
||||
@ -292,16 +294,20 @@ public class ImageNode extends ViewNode<ImageView> {
|
||||
}
|
||||
}));
|
||||
}
|
||||
Drawable placeHolderDrawable = getPlaceHolderDrawable();
|
||||
|
||||
Drawable placeHolderDrawable = null;
|
||||
if (mView.getDrawable() != null) {
|
||||
placeHolderDrawable = mView.getDrawable();
|
||||
} else {
|
||||
placeHolderDrawable = getPlaceHolderDrawable();
|
||||
}
|
||||
if (placeHolderDrawable != null) {
|
||||
requestBuilder = requestBuilder.apply(RequestOptions.placeholderOf(placeHolderDrawable));
|
||||
}
|
||||
|
||||
Drawable errorDrawable = getErrorDrawable();
|
||||
if (errorDrawable != null) {
|
||||
requestBuilder = requestBuilder.apply(RequestOptions.errorOf(errorDrawable));
|
||||
if (errorDrawable == null) {
|
||||
errorDrawable = new ColorDrawable(Color.TRANSPARENT);
|
||||
}
|
||||
requestBuilder = requestBuilder.apply(RequestOptions.errorOf(errorDrawable));
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
DoricLog.e("ImageNode blend error, please check the glide version");
|
||||
@ -424,6 +430,7 @@ public class ImageNode extends ViewNode<ImageView> {
|
||||
public void onError(Throwable t) {
|
||||
t.printStackTrace();
|
||||
DoricLog.e("Cannot load resource %s, %s", resource.toString(), t.getLocalizedMessage());
|
||||
view.setImageDrawable(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -575,8 +582,7 @@ public class ImageNode extends ViewNode<ImageView> {
|
||||
@Override
|
||||
protected void reset() {
|
||||
super.reset();
|
||||
mView.setImageDrawable(null);
|
||||
mView.setScaleType(ImageView.ScaleType.CENTER_CROP);
|
||||
scaleType = 2;
|
||||
loadCallbackId = "";
|
||||
isBlur = false;
|
||||
placeHolderImage = null;
|
||||
|
@ -23,6 +23,7 @@ import com.github.pengfeizhou.jscore.JSValue;
|
||||
import pub.doric.DoricContext;
|
||||
import pub.doric.extension.bridge.DoricPlugin;
|
||||
import pub.doric.shader.StackNode;
|
||||
import pub.doric.shader.SuperNode;
|
||||
|
||||
/**
|
||||
* @Description: com.github.penfeizhou.doric.widget
|
||||
@ -35,6 +36,11 @@ public class FlowLayoutItemNode extends StackNode {
|
||||
|
||||
public FlowLayoutItemNode(DoricContext doricContext) {
|
||||
super(doricContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(SuperNode<?> superNode) {
|
||||
super.init(superNode);
|
||||
this.mReusable = true;
|
||||
}
|
||||
|
||||
|
@ -23,6 +23,7 @@ import com.github.pengfeizhou.jscore.JSValue;
|
||||
import pub.doric.DoricContext;
|
||||
import pub.doric.extension.bridge.DoricPlugin;
|
||||
import pub.doric.shader.StackNode;
|
||||
import pub.doric.shader.SuperNode;
|
||||
|
||||
/**
|
||||
* @Description: com.github.penfeizhou.doric.widget
|
||||
@ -35,6 +36,11 @@ public class ListItemNode extends StackNode {
|
||||
|
||||
public ListItemNode(DoricContext doricContext) {
|
||||
super(doricContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(SuperNode<?> superNode) {
|
||||
super.init(superNode);
|
||||
this.mReusable = true;
|
||||
}
|
||||
|
||||
|
@ -168,7 +168,8 @@ public class ListNode extends SuperNode<RecyclerView> implements IDoricScrollabl
|
||||
@Override
|
||||
public void blend(JSObject jsObject) {
|
||||
super.blend(jsObject);
|
||||
if (jsObject.propertySet().size() > 1 || !jsObject.propertySet().contains("subviews")) {
|
||||
int limit = jsObject.propertySet().contains("loadMoreView") ? 2 : 1;
|
||||
if (jsObject.propertySet().size() > limit || !jsObject.propertySet().contains("subviews")) {
|
||||
if (mView != null) {
|
||||
mView.post(new Runnable() {
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
|
@ -24,6 +24,7 @@ import com.github.pengfeizhou.jscore.JSValue;
|
||||
import pub.doric.DoricContext;
|
||||
import pub.doric.extension.bridge.DoricPlugin;
|
||||
import pub.doric.shader.StackNode;
|
||||
import pub.doric.shader.SuperNode;
|
||||
|
||||
/**
|
||||
* @Description: com.github.penfeizhou.doric.widget
|
||||
@ -36,7 +37,12 @@ public class SlideItemNode extends StackNode {
|
||||
|
||||
public SlideItemNode(DoricContext doricContext) {
|
||||
super(doricContext);
|
||||
this.mReusable = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(SuperNode<?> superNode) {
|
||||
super.init(superNode);
|
||||
mReusable = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -25,7 +25,13 @@ @implementation DoricBundleResource
|
||||
NSString *path = [self.bundle bundlePath];
|
||||
NSString *fullPath = [path stringByAppendingPathComponent:self.identifier];
|
||||
NSData *imgData = [[NSData alloc] initWithContentsOfFile:fullPath];
|
||||
if (imgData) {
|
||||
[result setupResult:imgData];
|
||||
} else {
|
||||
[result setupError:[NSException exceptionWithName:@"ResourceLoadError"
|
||||
reason:@"Load resource error"
|
||||
userInfo:nil]];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@end
|
||||
|
@ -92,6 +92,7 @@ @interface DoricImageNode ()
|
||||
@implementation DoricImageNode
|
||||
|
||||
- (UIImageView *)build {
|
||||
self.scaleType = 2;
|
||||
self.imageScale = UIScreen.mainScreen.scale;
|
||||
return [[DoricImageView new] also:^(UIImageView *it) {
|
||||
it.clipsToBounds = YES;
|
||||
@ -125,9 +126,15 @@ - (void)blend:(NSDictionary *)props {
|
||||
self.loadCallbackId = it;
|
||||
}];
|
||||
[super blend:props];
|
||||
if(self.scaleType == 2 && self.view.contentMode != UIViewContentModeScaleAspectFill) {
|
||||
self.view.contentMode = UIViewContentModeScaleAspectFill;
|
||||
}
|
||||
}
|
||||
|
||||
- (UIImage *)currentPlaceHolderImage {
|
||||
if (self.view.image) {
|
||||
return self.view.image;
|
||||
}
|
||||
if (self.placeHolderImage) {
|
||||
return [UIImage imageNamed:self.placeHolderImage];
|
||||
}
|
||||
@ -156,7 +163,7 @@ - (UIImage *)currentPlaceHolderImage {
|
||||
UIColor *color = DoricColor(self.placeHolderColor);
|
||||
CGRect rect = CGRectMake(0, 0, 1, 1);
|
||||
self.view.contentMode = UIViewContentModeScaleToFill;
|
||||
|
||||
self.scaleType = 0;
|
||||
if (@available(iOS 10.0, *)) {
|
||||
UIGraphicsImageRendererFormat *format = [[UIGraphicsImageRendererFormat alloc] init];
|
||||
format.scale = [UIScreen mainScreen].scale;
|
||||
@ -212,7 +219,7 @@ - (UIImage *)currentErrorImage {
|
||||
UIColor *color = DoricColor(self.errorColor);
|
||||
CGRect rect = CGRectMake(0, 0, 1, 1);
|
||||
self.view.contentMode = UIViewContentModeScaleToFill;
|
||||
|
||||
self.scaleType = 0;
|
||||
if (@available(iOS 10.0, *)) {
|
||||
UIGraphicsImageRendererFormat *format = [[UIGraphicsImageRendererFormat alloc] init];
|
||||
format.scale = [UIScreen mainScreen].scale;
|
||||
@ -236,7 +243,36 @@ - (UIImage *)currentErrorImage {
|
||||
return image;
|
||||
}
|
||||
}
|
||||
return self.doricContext.driver.registry.defaultErrorImage;
|
||||
UIImage *image = self.doricContext.driver.registry.defaultErrorImage;
|
||||
if (!image) {
|
||||
UIColor *color = UIColor.clearColor;
|
||||
CGRect rect = CGRectMake(0, 0, 1, 1);
|
||||
self.view.contentMode = UIViewContentModeScaleToFill;
|
||||
self.scaleType = 0;
|
||||
if (@available(iOS 10.0, *)) {
|
||||
UIGraphicsImageRendererFormat *format = [[UIGraphicsImageRendererFormat alloc] init];
|
||||
format.scale = [UIScreen mainScreen].scale;
|
||||
UIGraphicsImageRenderer *render = [[UIGraphicsImageRenderer alloc] initWithSize:rect.size format:format];
|
||||
UIImage *image = [render imageWithActions:^(UIGraphicsImageRendererContext *_Nonnull rendererContext) {
|
||||
CGContextRef context = rendererContext.CGContext;
|
||||
|
||||
CGContextSetFillColorWithColor(context, color.CGColor);
|
||||
CGContextFillRect(context, rect);
|
||||
}];
|
||||
return image;
|
||||
} else {
|
||||
UIGraphicsBeginImageContextWithOptions(rect.size, NO, [UIScreen mainScreen].scale);
|
||||
|
||||
CGContextRef context = UIGraphicsGetCurrentContext();
|
||||
CGContextSetFillColorWithColor(context, color.CGColor);
|
||||
CGContextFillRect(context, rect);
|
||||
|
||||
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
|
||||
UIGraphicsEndImageContext();
|
||||
return image;
|
||||
}
|
||||
}
|
||||
return image;
|
||||
}
|
||||
|
||||
- (void)blendView:(UIImageView *)view forPropName:(NSString *)name propValue:(id)prop {
|
||||
@ -287,6 +323,7 @@ - (void)blendView:(UIImageView *)view forPropName:(NSString *)name propValue:(id
|
||||
}];
|
||||
[asyncResult setExceptionCallback:^(NSException *e) {
|
||||
DoricLog(@"Cannot load resource %@, %@", prop, e.reason);
|
||||
self.view.image = nil;
|
||||
}];
|
||||
} else if ([@"imageUrl" isEqualToString:name]) {
|
||||
__weak typeof(self) _self = self;
|
||||
@ -712,7 +749,7 @@ - (void)stopAnimating {
|
||||
|
||||
- (void)reset {
|
||||
[super reset];
|
||||
self.view.image = nil;
|
||||
self.scaleType = 2;
|
||||
self.loadCallbackId = nil;
|
||||
self.placeHolderColor = nil;
|
||||
self.placeHolderImage = nil;
|
||||
@ -722,7 +759,6 @@ - (void)reset {
|
||||
self.errorImageBase64 = nil;
|
||||
self.imageScale = UIScreen.mainScreen.scale;
|
||||
self.blurEffectView = nil;
|
||||
self.view.contentMode = UIViewContentModeScaleAspectFill;
|
||||
if (self.animationEndCallbackId) {
|
||||
#if DORIC_USE_YYWEBIMAGE
|
||||
[(DoricImageView *) self.view removeObserver:self forKeyPath:@"currentIsPlayingAnimation" context:nil];
|
||||
|
Reference in New Issue
Block a user