feat:add onFrameChangedCallback for DoricPanel
This commit is contained in:
parent
aad9029784
commit
aecccabe84
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -492,6 +492,7 @@ public abstract class ViewNode<T extends View> 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<T extends View> extends DoricContextHolder {
|
||||
layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT;
|
||||
break;
|
||||
default:
|
||||
layoutParams.height = Math.max(0, layoutParams.height);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -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
|
@ -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 {
|
||||
|
@ -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)
|
||||
|
4
doric-web/dist/index.js
vendored
4
doric-web/dist/index.js
vendored
@ -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)
|
||||
|
Reference in New Issue
Block a user