feat:Aero add style property

This commit is contained in:
pengfei.zhou 2021-11-25 16:30:29 +08:00 committed by osborn
parent cc014a6061
commit f302592d11
13 changed files with 67 additions and 5 deletions

View File

@ -25,7 +25,7 @@ android {
} }
afterEvaluate { afterEvaluate {
buildJSBundle.exec() //buildJSBundle.exec()
} }
task buildJSBundle(type: Exec) { task buildJSBundle(type: Exec) {

View File

@ -19,7 +19,6 @@ import android.content.Context;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint; import android.graphics.Paint;
import android.graphics.PorterDuff; import android.graphics.PorterDuff;
import android.graphics.Rect; import android.graphics.Rect;
@ -44,6 +43,8 @@ public class AeroEffectView extends DoricLayer {
private Bitmap mScaledBitmap = null; private Bitmap mScaledBitmap = null;
private Canvas mScaledCanvas = null; private Canvas mScaledCanvas = null;
private String mStyle = null;
public AeroEffectView(@NonNull Context context) { public AeroEffectView(@NonNull Context context) {
super(context); super(context);
} }
@ -54,6 +55,11 @@ public class AeroEffectView extends DoricLayer {
invalidate(); invalidate();
} }
public void setStyle(String style) {
this.mStyle = style;
invalidate();
}
@Override @Override
protected void dispatchDraw(Canvas canvas) { protected void dispatchDraw(Canvas canvas) {
if (mFullBitmap == null if (mFullBitmap == null
@ -97,6 +103,11 @@ public class AeroEffectView extends DoricLayer {
new Rect(0, 0, scaledWidth, scaledHeight), new Rect(0, 0, scaledWidth, scaledHeight),
paint); paint);
blurredBitmap = DoricUtils.blur(getContext(), mScaledBitmap, radius); blurredBitmap = DoricUtils.blur(getContext(), mScaledBitmap, radius);
if ("dark".equals(mStyle)) {
mScaledCanvas.drawColor(0x66000000, PorterDuff.Mode.SRC_OVER);
} else if ("extraLight".equals(mStyle)) {
mScaledCanvas.drawColor(0x99ffffff, PorterDuff.Mode.SRC_OVER);
}
if (mEffectiveRect != null) { if (mEffectiveRect != null) {
mFullCanvas.save(); mFullCanvas.save();
mFullCanvas.clipRect(mEffectiveRect); mFullCanvas.clipRect(mEffectiveRect);

View File

@ -51,6 +51,12 @@ public class AeroEffectViewNode extends StackNode {
int height = DoricUtils.dp2px(prop.asObject().getProperty("height").asNumber().toFloat()); int height = DoricUtils.dp2px(prop.asObject().getProperty("height").asNumber().toFloat());
((AeroEffectView) view).setEffectiveRect(new Rect(x, y, x + width, y + height)); ((AeroEffectView) view).setEffectiveRect(new Rect(x, y, x + width, y + height));
} }
} else if ("style".equals(name)) {
if(prop.isString()){
((AeroEffectView) view).setStyle(prop.asString().value());
}else{
((AeroEffectView) view).setStyle(null);
}
} else { } else {
super.blend(view, name, prop); super.blend(view, name, prop);
} }

View File

@ -27,8 +27,8 @@ @implementation DoricAeroEffectViewNode
- (UIView *)build { - (UIView *)build {
UIView *ret = [super build]; UIView *ret = [super build];
UIVisualEffect *endEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]; UIVisualEffect *effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
self.visualEffectView = [[UIVisualEffectView alloc] initWithEffect:endEffect]; self.visualEffectView = [[UIVisualEffectView alloc] initWithEffect:effect];
[ret addSubview:self.visualEffectView]; [ret addSubview:self.visualEffectView];
self.visualEffectView.doricLayout.widthSpec = DoricLayoutMost; self.visualEffectView.doricLayout.widthSpec = DoricLayoutMost;
self.visualEffectView.doricLayout.heightSpec = DoricLayoutMost; self.visualEffectView.doricLayout.heightSpec = DoricLayoutMost;
@ -47,6 +47,15 @@ - (void)blendView:(UIView *)view forPropName:(NSString *)name propValue:(id)prop
self.visualEffectView.doricLayout.height = height; self.visualEffectView.doricLayout.height = height;
self.visualEffectView.doricLayout.marginLeft = x; self.visualEffectView.doricLayout.marginLeft = x;
self.visualEffectView.doricLayout.marginTop = y; self.visualEffectView.doricLayout.marginTop = y;
} else if ([name isEqualToString:@"style"]) {
UIBlurEffectStyle style = UIBlurEffectStyleLight;
if ([prop isEqualToString:@"dark"]) {
style = UIBlurEffectStyleDark;
} else if ([prop isEqualToString:@"extraLight"]) {
style = UIBlurEffectStyleExtraLight;
}
UIVisualEffect *effect = [UIBlurEffect effectWithStyle:style];
self.visualEffectView.effect = effect;
} else { } else {
[super blendView:view forPropName:name propValue:prop]; [super blendView:view forPropName:name propValue:prop];
} }

View File

@ -3643,6 +3643,10 @@ var AeroEffect = /** @class */ (function (_super) {
Property, Property,
__metadata("design:type", Object) __metadata("design:type", Object)
], AeroEffect.prototype, "effectiveRect", void 0); ], AeroEffect.prototype, "effectiveRect", void 0);
__decorate([
Property,
__metadata("design:type", String)
], AeroEffect.prototype, "style", void 0);
return AeroEffect; return AeroEffect;
}(Stack)); }(Stack));
function blurEffect(views, config) { function blurEffect(views, config) {

View File

@ -2748,6 +2748,10 @@ __decorate([
Property, Property,
__metadata("design:type", Object) __metadata("design:type", Object)
], AeroEffect.prototype, "effectiveRect", void 0); ], AeroEffect.prototype, "effectiveRect", void 0);
__decorate([
Property,
__metadata("design:type", String)
], AeroEffect.prototype, "style", void 0);
function blurEffect(views, config) { function blurEffect(views, config) {
const ret = new BlurEffect; const ret = new BlurEffect;
ret.layoutConfig = layoutConfig().fit(); ret.layoutConfig = layoutConfig().fit();

View File

@ -4269,6 +4269,10 @@ __decorate([
Property, Property,
__metadata("design:type", Object) __metadata("design:type", Object)
], AeroEffect.prototype, "effectiveRect", void 0); ], AeroEffect.prototype, "effectiveRect", void 0);
__decorate([
Property,
__metadata("design:type", String)
], AeroEffect.prototype, "style", void 0);
function blurEffect(views, config) { function blurEffect(views, config) {
const ret = new BlurEffect; const ret = new BlurEffect;
ret.layoutConfig = layoutConfig().fit(); ret.layoutConfig = layoutConfig().fit();

5
doric-js/index.d.ts vendored
View File

@ -1121,6 +1121,11 @@ declare module 'doric/lib/src/widget/effect' {
width: number; width: number;
height: number; height: number;
}; };
/**
* Specify the area of the view is lighter or darker than the underlying view.
* If not set, the default is light.
*/
style?: "light" | "dark" | "extraLight";
} }
export function blurEffect(views: View | View[], config?: Partial<BlurEffect>): BlurEffect; export function blurEffect(views: View | View[], config?: Partial<BlurEffect>): BlurEffect;
export function aeroEffect(views: View | View[], config?: Partial<AeroEffect>): AeroEffect; export function aeroEffect(views: View | View[], config?: Partial<AeroEffect>): AeroEffect;

View File

@ -29,6 +29,11 @@ export declare class AeroEffect extends Stack {
width: number; width: number;
height: number; height: number;
}; };
/**
* Specify the area of the view is lighter or darker than the underlying view.
* If not set, the default is light.
*/
style?: "light" | "dark" | "extraLight";
} }
export declare function blurEffect(views: View | View[], config?: Partial<BlurEffect>): BlurEffect; export declare function blurEffect(views: View | View[], config?: Partial<BlurEffect>): BlurEffect;
export declare function aeroEffect(views: View | View[], config?: Partial<AeroEffect>): AeroEffect; export declare function aeroEffect(views: View | View[], config?: Partial<AeroEffect>): AeroEffect;

View File

@ -41,6 +41,10 @@ __decorate([
Property, Property,
__metadata("design:type", Object) __metadata("design:type", Object)
], AeroEffect.prototype, "effectiveRect", void 0); ], AeroEffect.prototype, "effectiveRect", void 0);
__decorate([
Property,
__metadata("design:type", String)
], AeroEffect.prototype, "style", void 0);
export function blurEffect(views, config) { export function blurEffect(views, config) {
const ret = new BlurEffect; const ret = new BlurEffect;
ret.layoutConfig = layoutConfig().fit(); ret.layoutConfig = layoutConfig().fit();

View File

@ -51,6 +51,12 @@ export class AeroEffect extends Stack {
width: number, width: number,
height: number, height: number,
} }
/**
* Specify the area of the view is lighter or darker than the underlying view.
* If not set, the default is light.
*/
@Property
style?: "light" | "dark" | "extraLight"
} }

View File

@ -4323,6 +4323,10 @@ __decorate([
Property, Property,
__metadata("design:type", Object) __metadata("design:type", Object)
], AeroEffect.prototype, "effectiveRect", void 0); ], AeroEffect.prototype, "effectiveRect", void 0);
__decorate([
Property,
__metadata("design:type", String)
], AeroEffect.prototype, "style", void 0);
function blurEffect(views, config) { function blurEffect(views, config) {
const ret = new BlurEffect; const ret = new BlurEffect;
ret.layoutConfig = layoutConfig().fit(); ret.layoutConfig = layoutConfig().fit();

File diff suppressed because one or more lines are too long