-
-
Notifications
You must be signed in to change notification settings - Fork 171
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
136 additions
and
15 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { QLabel, NodeWidget, QMovie, QSize } from "@nodegui/nodegui"; | ||
import { TextProps, setTextProps } from "../Text/RNText"; | ||
import { RNWidget } from "../config"; | ||
import { throwUnsupported } from "../../utils/helpers"; | ||
|
||
export interface AnimatedImageProps extends TextProps { | ||
src?: string; | ||
} | ||
|
||
const setAnimatedImageProps = ( | ||
widget: RNAnimatedImage, | ||
newProps: AnimatedImageProps, | ||
oldProps: AnimatedImageProps | ||
) => { | ||
const setter: AnimatedImageProps = { | ||
set src(imageUrl: string) { | ||
if (!imageUrl) { | ||
return; | ||
} | ||
const movie = new QMovie(); | ||
movie.setFileName(imageUrl); | ||
widget.setMovie(movie); | ||
const size = widget.size(); | ||
movie.setScaledSize(size); | ||
} | ||
}; | ||
Object.assign(setter, newProps); | ||
setTextProps(widget, newProps, oldProps); | ||
}; | ||
|
||
/** | ||
* @ignore | ||
*/ | ||
export class RNAnimatedImage extends QLabel implements RNWidget { | ||
setProps(newProps: AnimatedImageProps, oldProps: AnimatedImageProps): void { | ||
setAnimatedImageProps(this, newProps, oldProps); | ||
} | ||
appendInitialChild(child: NodeWidget): void { | ||
throwUnsupported(this); | ||
} | ||
appendChild(child: NodeWidget): void { | ||
throwUnsupported(this); | ||
} | ||
insertBefore(child: NodeWidget, beforeChild: NodeWidget): void { | ||
throwUnsupported(this); | ||
} | ||
removeChild(child: NodeWidget): void { | ||
throwUnsupported(this); | ||
} | ||
static tagName = "animatedimage"; | ||
scaleMovie(size: QSize) { | ||
const movie = this.movie(); | ||
movie?.setScaledSize(size); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { Fiber } from "react-reconciler"; | ||
import { registerComponent, ComponentConfig } from "../config"; | ||
import { RNAnimatedImage, AnimatedImageProps } from "./RNAnimatedImage"; | ||
import { AppContainer } from "../../reconciler"; | ||
import { QLabelEvents } from "@nodegui/nodegui"; | ||
|
||
class AnimatedImageConfig extends ComponentConfig { | ||
tagName = RNAnimatedImage.tagName; | ||
shouldSetTextContent(nextProps: AnimatedImageProps): boolean { | ||
return true; | ||
} | ||
createInstance( | ||
newProps: AnimatedImageProps, | ||
rootInstance: AppContainer, | ||
context: any, | ||
workInProgress: Fiber | ||
): RNAnimatedImage { | ||
const widget = new RNAnimatedImage(); | ||
widget.setProps(newProps, {}); | ||
widget.movie()?.start(); | ||
widget.addEventListener(QLabelEvents.Resize, () => { | ||
widget.scaleMovie(widget.size()); | ||
}); | ||
return widget; | ||
} | ||
commitMount( | ||
instance: RNAnimatedImage, | ||
newProps: AnimatedImageProps, | ||
internalInstanceHandle: any | ||
): void { | ||
if (newProps.visible !== false) { | ||
instance.show(); | ||
} | ||
return; | ||
} | ||
commitUpdate( | ||
instance: RNAnimatedImage, | ||
updatePayload: any, | ||
oldProps: AnimatedImageProps, | ||
newProps: AnimatedImageProps, | ||
finishedWork: Fiber | ||
): void { | ||
instance.setProps(newProps, oldProps); | ||
} | ||
} | ||
|
||
export const AnimatedImage = registerComponent<AnimatedImageProps>( | ||
new AnimatedImageConfig() | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters