feat: Image add isAnimating, startAnimating and stopAnimating API
This commit is contained in:
parent
3fd8405e0b
commit
63e0d1c38c
@ -56,6 +56,7 @@ import java.io.File;
|
|||||||
|
|
||||||
import jp.wasabeef.glide.transformations.BlurTransformation;
|
import jp.wasabeef.glide.transformations.BlurTransformation;
|
||||||
import pub.doric.DoricContext;
|
import pub.doric.DoricContext;
|
||||||
|
import pub.doric.extension.bridge.DoricMethod;
|
||||||
import pub.doric.extension.bridge.DoricPlugin;
|
import pub.doric.extension.bridge.DoricPlugin;
|
||||||
import pub.doric.shader.flex.FlexNode;
|
import pub.doric.shader.flex.FlexNode;
|
||||||
import pub.doric.utils.DoricLog;
|
import pub.doric.utils.DoricLog;
|
||||||
@ -440,4 +441,29 @@ public class ImageNode extends ViewNode<ImageView> {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@DoricMethod
|
||||||
|
public boolean isAnimating() {
|
||||||
|
Drawable drawable = mView.getDrawable();
|
||||||
|
if (drawable instanceof Animatable) {
|
||||||
|
return ((Animatable) drawable).isRunning();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@DoricMethod
|
||||||
|
public void startAnimating() {
|
||||||
|
Drawable drawable = mView.getDrawable();
|
||||||
|
if (drawable instanceof Animatable) {
|
||||||
|
((Animatable) drawable).start();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@DoricMethod
|
||||||
|
public void stopAnimating() {
|
||||||
|
Drawable drawable = mView.getDrawable();
|
||||||
|
if (drawable instanceof Animatable) {
|
||||||
|
((Animatable) drawable).stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -104,37 +104,37 @@ export default allFiles
|
|||||||
console.warn(warning.message);
|
console.warn(warning.message);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
})
|
});
|
||||||
.concat(
|
// .concat(
|
||||||
allFiles
|
// allFiles
|
||||||
.map((e) => e.replace(/\.tsx?$/, ""))
|
// .map((e) => e.replace(/\.tsx?$/, ""))
|
||||||
.map((bundle) => {
|
// .map((bundle) => {
|
||||||
return {
|
// return {
|
||||||
input: `build/${bundle}.js`,
|
// input: `build/${bundle}.js`,
|
||||||
output: {
|
// output: {
|
||||||
format: "cjs",
|
// format: "cjs",
|
||||||
file: `bundle/${bundle}.es5.js`,
|
// file: `bundle/${bundle}.es5.js`,
|
||||||
sourcemap: true,
|
// sourcemap: true,
|
||||||
},
|
// },
|
||||||
plugins: [
|
// plugins: [
|
||||||
resolve({ mainFields: ["jsnext"] }),
|
// resolve({ mainFields: ["jsnext"] }),
|
||||||
commonjs(),
|
// commonjs(),
|
||||||
json(),
|
// json(),
|
||||||
buble({
|
// buble({
|
||||||
transforms: {
|
// transforms: {
|
||||||
dangerousForOf: true,
|
// dangerousForOf: true,
|
||||||
generator: false,
|
// generator: false,
|
||||||
},
|
// },
|
||||||
}),
|
// }),
|
||||||
image(),
|
// image(),
|
||||||
],
|
// ],
|
||||||
external: ["reflect-metadata", "doric"],
|
// external: ["reflect-metadata", "doric"],
|
||||||
onwarn: function (warning) {
|
// onwarn: function (warning) {
|
||||||
if (warning.code === "THIS_IS_UNDEFINED") {
|
// if (warning.code === "THIS_IS_UNDEFINED") {
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
console.warn(warning.message);
|
// console.warn(warning.message);
|
||||||
},
|
// },
|
||||||
};
|
// };
|
||||||
})
|
// })
|
||||||
);
|
// );
|
||||||
|
68
doric-demo/src/AnimatedImageDemo.tsx
Normal file
68
doric-demo/src/AnimatedImageDemo.tsx
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
import {
|
||||||
|
Panel,
|
||||||
|
Group,
|
||||||
|
jsx,
|
||||||
|
VLayout,
|
||||||
|
layoutConfig,
|
||||||
|
Image,
|
||||||
|
createRef,
|
||||||
|
Gravity,
|
||||||
|
ScaleType,
|
||||||
|
Color,
|
||||||
|
Text,
|
||||||
|
modal,
|
||||||
|
} from "doric";
|
||||||
|
import { colors } from "./utils";
|
||||||
|
|
||||||
|
@Entry
|
||||||
|
export class AnimatedImageDemo extends Panel {
|
||||||
|
build(root: Group) {
|
||||||
|
const imageRef = createRef<Image>();
|
||||||
|
<VLayout
|
||||||
|
parent={root}
|
||||||
|
layoutConfig={layoutConfig().most()}
|
||||||
|
gravity={Gravity.Center}
|
||||||
|
space={20}
|
||||||
|
>
|
||||||
|
<Image
|
||||||
|
scaleType={ScaleType.ScaleToFill}
|
||||||
|
ref={imageRef}
|
||||||
|
imageUrl="https://upload.wikimedia.org/wikipedia/commons/1/14/Animated_PNG_example_bouncing_beach_ball.png"
|
||||||
|
/>
|
||||||
|
<Text
|
||||||
|
textSize={20}
|
||||||
|
backgroundColor={colors[0]}
|
||||||
|
textColor={Color.WHITE}
|
||||||
|
padding={{ left: 10, top: 10, right: 10, bottom: 10 }}
|
||||||
|
onClick={async () => {
|
||||||
|
const isAnimating = await imageRef.current.isAnimating(context);
|
||||||
|
modal(context).alert(`Is Animating: ${isAnimating}`);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
isAnimating
|
||||||
|
</Text>
|
||||||
|
<Text
|
||||||
|
textSize={20}
|
||||||
|
backgroundColor={colors[0]}
|
||||||
|
textColor={Color.WHITE}
|
||||||
|
padding={{ left: 10, top: 10, right: 10, bottom: 10 }}
|
||||||
|
onClick={() => {
|
||||||
|
imageRef.current.startAnimating(context);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
startAnimating
|
||||||
|
</Text>
|
||||||
|
<Text
|
||||||
|
textSize={20}
|
||||||
|
backgroundColor={colors[0]}
|
||||||
|
textColor={Color.WHITE}
|
||||||
|
padding={{ left: 10, top: 10, right: 10, bottom: 10 }}
|
||||||
|
onClick={() => {
|
||||||
|
imageRef.current.stopAnimating(context);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
stopAnimating
|
||||||
|
</Text>
|
||||||
|
</VLayout>;
|
||||||
|
}
|
||||||
|
}
|
@ -501,7 +501,7 @@ - (void)blendView:(UIImageView *)view forPropName:(NSString *)name propValue:(id
|
|||||||
? @(YES)
|
? @(YES)
|
||||||
: @(NO),
|
: @(NO),
|
||||||
#else
|
#else
|
||||||
@"animated": @(false),
|
@"animated": @(NO),
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
},
|
},
|
||||||
@ -558,4 +558,21 @@ - (void)afterBlended:(NSDictionary *)props {
|
|||||||
self.view.image = result;
|
self.view.image = result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
- (NSNumber *)isAnimating {
|
||||||
|
if (self.view.animating) {
|
||||||
|
return @(YES);
|
||||||
|
} else {
|
||||||
|
return @(NO);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)startAnimating {
|
||||||
|
[self.view startAnimating];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)stopAnimating {
|
||||||
|
[self.view stopAnimating];
|
||||||
|
}
|
||||||
@end
|
@end
|
||||||
|
@ -2154,6 +2154,15 @@ var Image = /** @class */ (function (_super) {
|
|||||||
function Image() {
|
function Image() {
|
||||||
return _super !== null && _super.apply(this, arguments) || this;
|
return _super !== null && _super.apply(this, arguments) || this;
|
||||||
}
|
}
|
||||||
|
Image.prototype.isAnimating = function (context) {
|
||||||
|
return this.nativeChannel(context, "isAnimating")();
|
||||||
|
};
|
||||||
|
Image.prototype.startAnimating = function (context) {
|
||||||
|
return this.nativeChannel(context, "startAnimating")();
|
||||||
|
};
|
||||||
|
Image.prototype.stopAnimating = function (context) {
|
||||||
|
return this.nativeChannel(context, "stopAnimating")();
|
||||||
|
};
|
||||||
__decorate$a([
|
__decorate$a([
|
||||||
Property,
|
Property,
|
||||||
__metadata$a("design:type", String)
|
__metadata$a("design:type", String)
|
||||||
|
@ -1619,6 +1619,15 @@ exports.ScaleType = void 0;
|
|||||||
ScaleType[ScaleType["ScaleAspectFill"] = 2] = "ScaleAspectFill";
|
ScaleType[ScaleType["ScaleAspectFill"] = 2] = "ScaleAspectFill";
|
||||||
})(exports.ScaleType || (exports.ScaleType = {}));
|
})(exports.ScaleType || (exports.ScaleType = {}));
|
||||||
class Image extends View {
|
class Image extends View {
|
||||||
|
isAnimating(context) {
|
||||||
|
return this.nativeChannel(context, "isAnimating")();
|
||||||
|
}
|
||||||
|
startAnimating(context) {
|
||||||
|
return this.nativeChannel(context, "startAnimating")();
|
||||||
|
}
|
||||||
|
stopAnimating(context) {
|
||||||
|
return this.nativeChannel(context, "stopAnimating")();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
__decorate$a([
|
__decorate$a([
|
||||||
Property,
|
Property,
|
||||||
|
@ -3140,6 +3140,15 @@ exports.ScaleType = void 0;
|
|||||||
ScaleType[ScaleType["ScaleAspectFill"] = 2] = "ScaleAspectFill";
|
ScaleType[ScaleType["ScaleAspectFill"] = 2] = "ScaleAspectFill";
|
||||||
})(exports.ScaleType || (exports.ScaleType = {}));
|
})(exports.ScaleType || (exports.ScaleType = {}));
|
||||||
class Image extends View {
|
class Image extends View {
|
||||||
|
isAnimating(context) {
|
||||||
|
return this.nativeChannel(context, "isAnimating")();
|
||||||
|
}
|
||||||
|
startAnimating(context) {
|
||||||
|
return this.nativeChannel(context, "startAnimating")();
|
||||||
|
}
|
||||||
|
stopAnimating(context) {
|
||||||
|
return this.nativeChannel(context, "stopAnimating")();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
__decorate$a([
|
__decorate$a([
|
||||||
Property,
|
Property,
|
||||||
|
4
doric-js/index.d.ts
vendored
4
doric-js/index.d.ts
vendored
@ -606,6 +606,7 @@ declare module 'doric/lib/src/widget/text' {
|
|||||||
declare module 'doric/lib/src/widget/image' {
|
declare module 'doric/lib/src/widget/image' {
|
||||||
import { View } from "doric/lib/src/ui/view";
|
import { View } from "doric/lib/src/ui/view";
|
||||||
import { Color } from "doric/lib/src/util/color";
|
import { Color } from "doric/lib/src/util/color";
|
||||||
|
import { BridgeContext } from "doric/lib/src/runtime/global";
|
||||||
export enum ScaleType {
|
export enum ScaleType {
|
||||||
ScaleToFill = 0,
|
ScaleToFill = 0,
|
||||||
ScaleAspectFit = 1,
|
ScaleAspectFit = 1,
|
||||||
@ -674,6 +675,9 @@ declare module 'doric/lib/src/widget/image' {
|
|||||||
right: number;
|
right: number;
|
||||||
bottom: number;
|
bottom: number;
|
||||||
};
|
};
|
||||||
|
isAnimating(context: BridgeContext): Promise<boolean>;
|
||||||
|
startAnimating(context: BridgeContext): Promise<any>;
|
||||||
|
stopAnimating(context: BridgeContext): Promise<any>;
|
||||||
}
|
}
|
||||||
export function image(config: Partial<Image>): Image;
|
export function image(config: Partial<Image>): Image;
|
||||||
}
|
}
|
||||||
|
4
doric-js/lib/src/widget/image.d.ts
vendored
4
doric-js/lib/src/widget/image.d.ts
vendored
@ -1,5 +1,6 @@
|
|||||||
import { View } from "../ui/view";
|
import { View } from "../ui/view";
|
||||||
import { Color } from "../util/color";
|
import { Color } from "../util/color";
|
||||||
|
import { BridgeContext } from "../runtime/global";
|
||||||
export declare enum ScaleType {
|
export declare enum ScaleType {
|
||||||
ScaleToFill = 0,
|
ScaleToFill = 0,
|
||||||
ScaleAspectFit = 1,
|
ScaleAspectFit = 1,
|
||||||
@ -68,5 +69,8 @@ export declare class Image extends View {
|
|||||||
right: number;
|
right: number;
|
||||||
bottom: number;
|
bottom: number;
|
||||||
};
|
};
|
||||||
|
isAnimating(context: BridgeContext): Promise<boolean>;
|
||||||
|
startAnimating(context: BridgeContext): Promise<any>;
|
||||||
|
stopAnimating(context: BridgeContext): Promise<any>;
|
||||||
}
|
}
|
||||||
export declare function image(config: Partial<Image>): Image;
|
export declare function image(config: Partial<Image>): Image;
|
||||||
|
@ -32,6 +32,15 @@ export var ScaleType;
|
|||||||
ScaleType[ScaleType["ScaleAspectFill"] = 2] = "ScaleAspectFill";
|
ScaleType[ScaleType["ScaleAspectFill"] = 2] = "ScaleAspectFill";
|
||||||
})(ScaleType || (ScaleType = {}));
|
})(ScaleType || (ScaleType = {}));
|
||||||
export class Image extends View {
|
export class Image extends View {
|
||||||
|
isAnimating(context) {
|
||||||
|
return this.nativeChannel(context, "isAnimating")();
|
||||||
|
}
|
||||||
|
startAnimating(context) {
|
||||||
|
return this.nativeChannel(context, "startAnimating")();
|
||||||
|
}
|
||||||
|
stopAnimating(context) {
|
||||||
|
return this.nativeChannel(context, "stopAnimating")();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
__decorate([
|
__decorate([
|
||||||
Property,
|
Property,
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
import { View, Property } from "../ui/view"
|
import { View, Property } from "../ui/view"
|
||||||
import { layoutConfig } from "../util/layoutconfig"
|
import { layoutConfig } from "../util/layoutconfig"
|
||||||
import { Color } from "../util/color"
|
import { Color } from "../util/color"
|
||||||
|
import { BridgeContext } from "../runtime/global"
|
||||||
|
|
||||||
export enum ScaleType {
|
export enum ScaleType {
|
||||||
ScaleToFill = 0,
|
ScaleToFill = 0,
|
||||||
@ -107,6 +108,18 @@ export class Image extends View {
|
|||||||
right: number,
|
right: number,
|
||||||
bottom: number
|
bottom: number
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isAnimating(context: BridgeContext) {
|
||||||
|
return this.nativeChannel(context, "isAnimating")() as Promise<boolean>
|
||||||
|
}
|
||||||
|
|
||||||
|
startAnimating(context: BridgeContext) {
|
||||||
|
return this.nativeChannel(context, "startAnimating")()
|
||||||
|
}
|
||||||
|
|
||||||
|
stopAnimating(context: BridgeContext) {
|
||||||
|
return this.nativeChannel(context, "stopAnimating")()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function image(config: Partial<Image>) {
|
export function image(config: Partial<Image>) {
|
||||||
|
9
doric-web/dist/index.js
vendored
9
doric-web/dist/index.js
vendored
@ -3194,6 +3194,15 @@ exports.ScaleType = void 0;
|
|||||||
ScaleType[ScaleType["ScaleAspectFill"] = 2] = "ScaleAspectFill";
|
ScaleType[ScaleType["ScaleAspectFill"] = 2] = "ScaleAspectFill";
|
||||||
})(exports.ScaleType || (exports.ScaleType = {}));
|
})(exports.ScaleType || (exports.ScaleType = {}));
|
||||||
class Image extends View {
|
class Image extends View {
|
||||||
|
isAnimating(context) {
|
||||||
|
return this.nativeChannel(context, "isAnimating")();
|
||||||
|
}
|
||||||
|
startAnimating(context) {
|
||||||
|
return this.nativeChannel(context, "startAnimating")();
|
||||||
|
}
|
||||||
|
stopAnimating(context) {
|
||||||
|
return this.nativeChannel(context, "stopAnimating")();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
__decorate$a([
|
__decorate$a([
|
||||||
Property,
|
Property,
|
||||||
|
2
doric-web/dist/index.js.map
vendored
2
doric-web/dist/index.js.map
vendored
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user