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.util.AttributeSet;
|
||||||
import android.widget.FrameLayout;
|
import android.widget.FrameLayout;
|
||||||
|
|
||||||
|
import com.github.penfeizhou.animation.decode.Frame;
|
||||||
|
|
||||||
import pub.doric.utils.DoricUtils;
|
import pub.doric.utils.DoricUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -37,6 +39,9 @@ import pub.doric.utils.DoricUtils;
|
|||||||
public class DoricPanel extends FrameLayout implements LifecycleObserver {
|
public class DoricPanel extends FrameLayout implements LifecycleObserver {
|
||||||
|
|
||||||
private DoricContext mDoricContext;
|
private DoricContext mDoricContext;
|
||||||
|
private FrameChangedListener frameChangedListener;
|
||||||
|
private int renderedWidth = -1;
|
||||||
|
private int renderedHeight = -1;
|
||||||
|
|
||||||
public DoricPanel(@NonNull Context context) {
|
public DoricPanel(@NonNull Context context) {
|
||||||
this(context, null);
|
this(context, null);
|
||||||
@ -80,9 +85,20 @@ public class DoricPanel extends FrameLayout implements LifecycleObserver {
|
|||||||
@Override
|
@Override
|
||||||
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
|
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
|
||||||
super.onSizeChanged(w, h, oldw, oldh);
|
super.onSizeChanged(w, h, oldw, oldh);
|
||||||
if (oldw != w || oldh != h) {
|
|
||||||
if (mDoricContext != null) {
|
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));
|
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();
|
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;
|
layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
layoutParams.width = Math.max(0, layoutParams.width);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -504,6 +505,7 @@ public abstract class ViewNode<T extends View> extends DoricContextHolder {
|
|||||||
layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT;
|
layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
layoutParams.height = Math.max(0, layoutParams.height);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
|
|
||||||
@interface DoricPanel : UIViewController
|
@interface DoricPanel : UIViewController
|
||||||
@property(nonatomic, strong) DoricContext *doricContext;
|
@property(nonatomic, strong) DoricContext *doricContext;
|
||||||
|
@property(nonatomic, strong) void (^frameChangedBlock)(CGSize frameSize);
|
||||||
|
|
||||||
- (void)config:(NSString *)script alias:(NSString *)alias extra:(NSString *)extra;
|
- (void)config:(NSString *)script alias:(NSString *)alias extra:(NSString *)extra;
|
||||||
@end
|
@end
|
@ -20,9 +20,9 @@
|
|||||||
#import "DoricPanel.h"
|
#import "DoricPanel.h"
|
||||||
#import "Doric.h"
|
#import "Doric.h"
|
||||||
|
|
||||||
@interface DoricPanel()
|
@interface DoricPanel ()
|
||||||
@property(nonatomic,assign) CGFloat renderedWidth;
|
@property(nonatomic, assign) CGFloat renderedWidth;
|
||||||
@property(nonatomic,assign) CGFloat renderedHeight;
|
@property(nonatomic, assign) CGFloat renderedHeight;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation DoricPanel
|
@implementation DoricPanel
|
||||||
@ -41,13 +41,22 @@ - (void)config:(NSString *)script alias:(NSString *)alias extra:(NSString *)extr
|
|||||||
|
|
||||||
- (void)viewWillLayoutSubviews {
|
- (void)viewWillLayoutSubviews {
|
||||||
[super viewWillLayoutSubviews];
|
[super viewWillLayoutSubviews];
|
||||||
|
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) {
|
[self.doricContext.rootNode.view also:^(DoricStackView *it) {
|
||||||
if (it.width != self.renderedWidth || it.height != self.renderedHeight) {
|
if (it.width != self.renderedWidth || it.height != self.renderedHeight) {
|
||||||
[self.doricContext initContextWithWidth:it.width height:it.height];
|
// Frame changed
|
||||||
self.renderedWidth = it.width;
|
self.renderedWidth = self.view.width = it.width;
|
||||||
self.renderedHeight = it.height;
|
self.renderedHeight = self.view.height = it.height;
|
||||||
|
if (self.frameChangedBlock) {
|
||||||
|
self.frameChangedBlock(CGSizeMake(it.width, it.height));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}];
|
}];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)viewDidAppear:(BOOL)animated {
|
- (void)viewDidAppear:(BOOL)animated {
|
||||||
|
@ -1676,6 +1676,10 @@ var Image = /** @class */ (function (_super) {
|
|||||||
Property,
|
Property,
|
||||||
__metadata$4("design:type", String)
|
__metadata$4("design:type", String)
|
||||||
], Image.prototype, "imageRes", void 0);
|
], Image.prototype, "imageRes", void 0);
|
||||||
|
__decorate$4([
|
||||||
|
Property,
|
||||||
|
__metadata$4("design:type", String)
|
||||||
|
], Image.prototype, "imageBase64", void 0);
|
||||||
__decorate$4([
|
__decorate$4([
|
||||||
Property,
|
Property,
|
||||||
__metadata$4("design:type", Number)
|
__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,
|
Property,
|
||||||
__metadata$4("design:type", String)
|
__metadata$4("design:type", String)
|
||||||
], Image.prototype, "imageRes", void 0);
|
], Image.prototype, "imageRes", void 0);
|
||||||
|
__decorate$4([
|
||||||
|
Property,
|
||||||
|
__metadata$4("design:type", String)
|
||||||
|
], Image.prototype, "imageBase64", void 0);
|
||||||
__decorate$4([
|
__decorate$4([
|
||||||
Property,
|
Property,
|
||||||
__metadata$4("design:type", Number)
|
__metadata$4("design:type", Number)
|
||||||
|
Reference in New Issue
Block a user