diff --git a/doric-android/doric/src/main/java/pub/doric/DoricPanel.java b/doric-android/doric/src/main/java/pub/doric/DoricPanel.java index 97f3a79d..014b2c4b 100644 --- a/doric-android/doric/src/main/java/pub/doric/DoricPanel.java +++ b/doric-android/doric/src/main/java/pub/doric/DoricPanel.java @@ -27,6 +27,8 @@ import androidx.lifecycle.OnLifecycleEvent; import android.util.AttributeSet; import android.widget.FrameLayout; +import com.github.penfeizhou.animation.decode.Frame; + import pub.doric.utils.DoricUtils; /** @@ -37,6 +39,9 @@ import pub.doric.utils.DoricUtils; public class DoricPanel extends FrameLayout implements LifecycleObserver { private DoricContext mDoricContext; + private FrameChangedListener frameChangedListener; + private int renderedWidth = -1; + private int renderedHeight = -1; public DoricPanel(@NonNull Context context) { this(context, null); @@ -80,9 +85,20 @@ public class DoricPanel extends FrameLayout implements LifecycleObserver { @Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { super.onSizeChanged(w, h, oldw, oldh); - if (oldw != w || oldh != h) { - if (mDoricContext != null) { - mDoricContext.init(DoricUtils.px2dp(w), DoricUtils.px2dp(h)); + if (mDoricContext != null) { + if (w != renderedWidth || h != renderedHeight) { + if (renderedWidth == oldw && renderedHeight == oldh) { + //Changed by doric + if (frameChangedListener != null) { + frameChangedListener.onFrameChanged(w, h); + } + renderedWidth = w; + renderedHeight = h; + } else { + mDoricContext.init(DoricUtils.px2dp(w), DoricUtils.px2dp(h)); + renderedWidth = w; + renderedHeight = h; + } } } } @@ -107,4 +123,12 @@ public class DoricPanel extends FrameLayout implements LifecycleObserver { mDoricContext.teardown(); } } + + public interface FrameChangedListener { + void onFrameChanged(int width, int height); + } + + public void setFrameChangedListener(FrameChangedListener listener) { + this.frameChangedListener = listener; + } } diff --git a/doric-android/doric/src/main/java/pub/doric/shader/ViewNode.java b/doric-android/doric/src/main/java/pub/doric/shader/ViewNode.java index 1e40bb83..ac72bef1 100644 --- a/doric-android/doric/src/main/java/pub/doric/shader/ViewNode.java +++ b/doric-android/doric/src/main/java/pub/doric/shader/ViewNode.java @@ -492,6 +492,7 @@ public abstract class ViewNode extends DoricContextHolder { layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT; break; default: + layoutParams.width = Math.max(0, layoutParams.width); break; } } @@ -504,6 +505,7 @@ public abstract class ViewNode extends DoricContextHolder { layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT; break; default: + layoutParams.height = Math.max(0, layoutParams.height); break; } } diff --git a/doric-iOS/Pod/Classes/DoricPanel.h b/doric-iOS/Pod/Classes/DoricPanel.h index 4dedaf8f..26490b06 100644 --- a/doric-iOS/Pod/Classes/DoricPanel.h +++ b/doric-iOS/Pod/Classes/DoricPanel.h @@ -24,6 +24,7 @@ @interface DoricPanel : UIViewController @property(nonatomic, strong) DoricContext *doricContext; +@property(nonatomic, strong) void (^frameChangedBlock)(CGSize frameSize); - (void)config:(NSString *)script alias:(NSString *)alias extra:(NSString *)extra; @end \ No newline at end of file diff --git a/doric-iOS/Pod/Classes/DoricPanel.m b/doric-iOS/Pod/Classes/DoricPanel.m index a544ba21..07493912 100644 --- a/doric-iOS/Pod/Classes/DoricPanel.m +++ b/doric-iOS/Pod/Classes/DoricPanel.m @@ -20,9 +20,9 @@ #import "DoricPanel.h" #import "Doric.h" -@interface DoricPanel() -@property(nonatomic,assign) CGFloat renderedWidth; -@property(nonatomic,assign) CGFloat renderedHeight; +@interface DoricPanel () +@property(nonatomic, assign) CGFloat renderedWidth; +@property(nonatomic, assign) CGFloat renderedHeight; @end @implementation DoricPanel @@ -41,13 +41,22 @@ - (void)config:(NSString *)script alias:(NSString *)alias extra:(NSString *)extr - (void)viewWillLayoutSubviews { [super viewWillLayoutSubviews]; - [self.doricContext.rootNode.view also:^(DoricStackView *it) { - if (it.width != self.renderedWidth || it.height != self.renderedHeight) { - [self.doricContext initContextWithWidth:it.width height:it.height]; - self.renderedWidth = it.width; - self.renderedHeight = it.height; - } - }]; + if (self.doricContext && self.renderedWidth != self.view.width && self.renderedHeight != self.view.height) { + self.renderedWidth = self.view.width; + self.renderedHeight = self.view.height; + [self.doricContext initContextWithWidth:self.renderedWidth height:self.renderedHeight]; + } else { + [self.doricContext.rootNode.view also:^(DoricStackView *it) { + if (it.width != self.renderedWidth || it.height != self.renderedHeight) { + // Frame changed + self.renderedWidth = self.view.width = it.width; + self.renderedHeight = self.view.height = it.height; + if (self.frameChangedBlock) { + self.frameChangedBlock(CGSizeMake(it.width, it.height)); + } + } + }]; + } } - (void)viewDidAppear:(BOOL)animated { diff --git a/doric-js/bundle/doric-lib.es5.js b/doric-js/bundle/doric-lib.es5.js index adab2def..d7458aa8 100644 --- a/doric-js/bundle/doric-lib.es5.js +++ b/doric-js/bundle/doric-lib.es5.js @@ -1676,6 +1676,10 @@ var Image = /** @class */ (function (_super) { Property, __metadata$4("design:type", String) ], Image.prototype, "imageRes", void 0); + __decorate$4([ + Property, + __metadata$4("design:type", String) + ], Image.prototype, "imageBase64", void 0); __decorate$4([ Property, __metadata$4("design:type", Number) diff --git a/doric-web/dist/index.js b/doric-web/dist/index.js index 9b8536cb..2eb697e1 100644 --- a/doric-web/dist/index.js +++ b/doric-web/dist/index.js @@ -2759,6 +2759,10 @@ __decorate$4([ Property, __metadata$4("design:type", String) ], Image.prototype, "imageRes", void 0); +__decorate$4([ + Property, + __metadata$4("design:type", String) +], Image.prototype, "imageBase64", void 0); __decorate$4([ Property, __metadata$4("design:type", Number)