|
1 |
| -import { registerComponent } from "../config"; |
2 |
| -import { QPixmap, QLabelEvents, AspectRatioMode } from "@nodegui/nodegui"; |
| 1 | +import { |
| 2 | + QPixmap, |
| 3 | + QLabelEvents, |
| 4 | + AspectRatioMode, |
| 5 | + NodeWidget |
| 6 | +} from "@nodegui/nodegui"; |
| 7 | +import { Fiber } from "react-reconciler"; |
| 8 | +import { registerComponent, ComponentConfig } from "../config"; |
3 | 9 | import { ImageLabel } from "./ImageLabel";
|
4 | 10 | import { TextProps, setProps as setTextProps } from "../Text";
|
5 | 11 | interface ImageProps extends TextProps {
|
@@ -30,39 +36,34 @@ const setProps = (
|
30 | 36 | setTextProps(widget, newProps, oldProps);
|
31 | 37 | };
|
32 | 38 |
|
33 |
| -export const Image = registerComponent<ImageProps>({ |
34 |
| - id: "image", |
35 |
| - getContext() { |
36 |
| - return {}; |
37 |
| - }, |
38 |
| - shouldSetTextContent: () => { |
39 |
| - return false; |
40 |
| - }, |
41 |
| - createInstance: newProps => { |
| 39 | +class ImageConfig extends ComponentConfig { |
| 40 | + id = "image"; |
| 41 | + shouldSetTextContent(nextProps: object): boolean { |
| 42 | + return true; |
| 43 | + } |
| 44 | + createInstance( |
| 45 | + newProps: object, |
| 46 | + rootInstance: Set<NodeWidget>, |
| 47 | + context: any, |
| 48 | + workInProgress: Fiber |
| 49 | + ): NodeWidget { |
42 | 50 | const widget = new ImageLabel();
|
43 | 51 | setProps(widget, newProps, {});
|
44 | 52 | widget.addEventListener(QLabelEvents.Resize, () => {
|
45 | 53 | const size = widget.size();
|
46 | 54 | widget.scalePixmap(size.width, size.height);
|
47 | 55 | });
|
48 | 56 | return widget;
|
49 |
| - }, |
50 |
| - finalizeInitialChildren: () => { |
51 |
| - return false; |
52 |
| - }, |
53 |
| - commitMount: (instance, newProps, internalInstanceHandle) => { |
54 |
| - return; |
55 |
| - }, |
56 |
| - prepareUpdate: ( |
57 |
| - instance, |
58 |
| - oldProps, |
59 |
| - newProps, |
60 |
| - rootContainerInstance, |
61 |
| - hostContext |
62 |
| - ) => { |
63 |
| - return true; |
64 |
| - }, |
65 |
| - commitUpdate: (instance, updatePayload, oldProps, newProps, finishedWork) => { |
| 57 | + } |
| 58 | + commitUpdate( |
| 59 | + instance: NodeWidget, |
| 60 | + updatePayload: any, |
| 61 | + oldProps: object, |
| 62 | + newProps: object, |
| 63 | + finishedWork: Fiber |
| 64 | + ): void { |
66 | 65 | setProps(instance as ImageLabel, newProps, oldProps);
|
67 | 66 | }
|
68 |
| -}); |
| 67 | +} |
| 68 | + |
| 69 | +export const Image = registerComponent<ImageProps>(new ImageConfig()); |
0 commit comments