-
Notifications
You must be signed in to change notification settings - Fork 481
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
1 parent
55de322
commit 121ebd4
Showing
6 changed files
with
239 additions
and
264 deletions.
There are no files selected for viewing
This file was deleted.
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,38 @@ | ||
import type { SkRect } from "../skia/types"; | ||
import type { ISkiaViewApi } from "../views/types"; | ||
import type { SkiaPictureView } from "../views/SkiaPictureView.web"; | ||
|
||
export type ISkiaViewApiWeb = ISkiaViewApi & { | ||
views: Record<string, SkiaPictureView>; | ||
registerView(nativeId: string, view: SkiaPictureView): void; | ||
}; | ||
|
||
global.SkiaViewApi = { | ||
views: {}, | ||
web: true, | ||
registerView(nativeId: string, view: SkiaPictureView) { | ||
this.views[nativeId] = view; | ||
}, | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
setJsiProperty(nativeId: number, name: string, value: any) { | ||
if (name === "picture") { | ||
this.views[`${nativeId}`].setPicture(value); | ||
} | ||
}, | ||
requestRedraw(nativeId: number) { | ||
this.views[`${nativeId}`].redraw(); | ||
}, | ||
makeImageSnapshot(nativeId: number, rect?: SkRect) { | ||
return this.views[`${nativeId}`].makeImageSnapshot(rect); | ||
}, | ||
makeImageSnapshotAsync(nativeId: number, rect?: SkRect) { | ||
return new Promise((resolve, reject) => { | ||
const result = this.views[`${nativeId}`].makeImageSnapshot(rect); | ||
if (result) { | ||
resolve(result); | ||
} else { | ||
reject(new Error("Failed to make image snapshot")); | ||
} | ||
}); | ||
}, | ||
} as ISkiaViewApiWeb; |
39 changes: 39 additions & 0 deletions
39
packages/skia/src/specs/SkiaPictureViewNativeComponent.web.ts
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,39 @@ | ||
import type { ViewProps } from "react-native"; | ||
import { createElement, useEffect, useRef } from "react"; | ||
|
||
import { SkiaPictureView } from "../views/SkiaPictureView.web"; | ||
|
||
import type { ISkiaViewApiWeb } from "./NativeSkiaModule.web"; | ||
|
||
export interface NativeProps extends ViewProps { | ||
debug?: boolean; | ||
opaque?: boolean; | ||
nativeID: string; | ||
} | ||
|
||
const SkiaPictureViewNativeComponent = ({ | ||
nativeID, | ||
debug, | ||
opaque, | ||
onLayout, | ||
...viewProps | ||
}: NativeProps) => { | ||
const ref = useRef(null); | ||
useEffect(() => { | ||
if (ref.current) { | ||
(global.SkiaViewApi as ISkiaViewApiWeb).registerView( | ||
nativeID, | ||
ref.current | ||
); | ||
} | ||
}, [nativeID]); | ||
return createElement(SkiaPictureView, { | ||
ref, | ||
debug, | ||
opaque, | ||
onLayout, | ||
...viewProps, | ||
}); | ||
}; | ||
// eslint-disable-next-line import/no-default-export | ||
export default SkiaPictureViewNativeComponent; |
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
Oops, something went wrong.