|
| 1 | +import { QLabel, NodeWidget, QMovie, QSize } from "@nodegui/nodegui"; |
| 2 | +import { TextProps, setTextProps } from "../Text/RNText"; |
| 3 | +import { RNWidget } from "../config"; |
| 4 | +import { throwUnsupported } from "../../utils/helpers"; |
| 5 | + |
| 6 | +export interface AnimatedImageProps extends TextProps { |
| 7 | + src?: string; |
| 8 | +} |
| 9 | + |
| 10 | +const setAnimatedImageProps = ( |
| 11 | + widget: RNAnimatedImage, |
| 12 | + newProps: AnimatedImageProps, |
| 13 | + oldProps: AnimatedImageProps |
| 14 | +) => { |
| 15 | + const setter: AnimatedImageProps = { |
| 16 | + set src(imageUrl: string) { |
| 17 | + if (!imageUrl) { |
| 18 | + return; |
| 19 | + } |
| 20 | + const movie = new QMovie(); |
| 21 | + movie.setFileName(imageUrl); |
| 22 | + widget.setMovie(movie); |
| 23 | + const size = widget.size(); |
| 24 | + movie.setScaledSize(size); |
| 25 | + } |
| 26 | + }; |
| 27 | + Object.assign(setter, newProps); |
| 28 | + setTextProps(widget, newProps, oldProps); |
| 29 | +}; |
| 30 | + |
| 31 | +/** |
| 32 | + * @ignore |
| 33 | + */ |
| 34 | +export class RNAnimatedImage extends QLabel implements RNWidget { |
| 35 | + setProps(newProps: AnimatedImageProps, oldProps: AnimatedImageProps): void { |
| 36 | + setAnimatedImageProps(this, newProps, oldProps); |
| 37 | + } |
| 38 | + appendInitialChild(child: NodeWidget): void { |
| 39 | + throwUnsupported(this); |
| 40 | + } |
| 41 | + appendChild(child: NodeWidget): void { |
| 42 | + throwUnsupported(this); |
| 43 | + } |
| 44 | + insertBefore(child: NodeWidget, beforeChild: NodeWidget): void { |
| 45 | + throwUnsupported(this); |
| 46 | + } |
| 47 | + removeChild(child: NodeWidget): void { |
| 48 | + throwUnsupported(this); |
| 49 | + } |
| 50 | + static tagName = "animatedimage"; |
| 51 | + scaleMovie(size: QSize) { |
| 52 | + const movie = this.movie(); |
| 53 | + movie?.setScaledSize(size); |
| 54 | + } |
| 55 | +} |
0 commit comments