-
Notifications
You must be signed in to change notification settings - Fork 483
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
cd6ae25
commit e84fb1b
Showing
13 changed files
with
126 additions
and
65 deletions.
There are no files selected for viewing
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
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,35 @@ | ||
import type { DeclarationNode, DrawingContext, Node } from "../types"; | ||
import { NodeType } from "../types"; | ||
import type { ChildrenProps } from "../types/Common"; | ||
import type { SkPaint } from "../../skia"; | ||
|
||
import { JsiRenderNode } from "./RenderNode"; | ||
import type { NodeContext } from "./Node"; | ||
import { JsiDeclarationNode } from "./Node"; | ||
|
||
const isLayer = ( | ||
node: Node<unknown> | ||
): node is DeclarationNode<unknown, SkPaint> => | ||
node instanceof JsiDeclarationNode && node.isPaint(); | ||
|
||
export class LayerNode extends JsiRenderNode<ChildrenProps> { | ||
constructor(ctx: NodeContext, props: ChildrenProps) { | ||
super(ctx, NodeType.Layer, props); | ||
} | ||
|
||
renderNode(ctx: DrawingContext): void { | ||
const [layer, ...children] = this.children(); | ||
if (isLayer(layer)) { | ||
const paint = layer.materialize() as SkPaint; | ||
ctx.canvas.saveLayer(paint); | ||
} | ||
children.map((child) => { | ||
if (child instanceof JsiRenderNode) { | ||
child.render(ctx); | ||
} | ||
}); | ||
if (isLayer(layer)) { | ||
ctx.canvas.restore(); | ||
} | ||
} | ||
} |
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
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 |
---|---|---|
@@ -1,8 +1,21 @@ | ||
import React from "react"; | ||
import React, { isValidElement } from "react"; | ||
|
||
import type { SkiaProps } from "../processors"; | ||
import type { GroupProps } from "../../dom/types"; | ||
import type { ChildrenProps } from "../../dom/types/Common"; | ||
|
||
export const Group = (props: SkiaProps<GroupProps>) => { | ||
return <skGroup {...props} />; | ||
export interface PublicGroupProps extends Omit<GroupProps, "layer"> { | ||
layer?: GroupProps["layer"] | ChildrenProps["children"]; | ||
} | ||
|
||
export const Group = ({ layer, ...props }: SkiaProps<PublicGroupProps>) => { | ||
if (isValidElement(layer) && typeof layer === "object") { | ||
return ( | ||
<skLayer> | ||
{layer} | ||
<skGroup {...props} /> | ||
</skLayer> | ||
); | ||
} | ||
return <skGroup layer={layer as GroupProps["layer"]} {...props} />; | ||
}; |
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