Skip to content

Commit

Permalink
ClippingBoxes Context (#13)
Browse files Browse the repository at this point in the history
Contextを<Stage>内にブリッジする
  • Loading branch information
okathira authored Feb 23, 2021
1 parent 057ba42 commit 21677f8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
6 changes: 4 additions & 2 deletions src/ClippingBoxes.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import React from "react";
import { Image } from "react-konva";
import { useBoxesProps } from "./contextData";

const ClippingBoxes: React.FC<{
currentFrame: CanvasImageSource;
boxesProps: BoxProps[]; // TODO: コンテキストにするとレンダリングされないのを治す
}> = ({ currentFrame, boxesProps }) => {
}> = ({ currentFrame }) => {
const boxesProps = useBoxesProps();

return (
<>
{(() =>
Expand Down
14 changes: 8 additions & 6 deletions src/OutputArea.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import React from "react";
import { Stage, Layer, Image } from "react-konva";
import ClippingBoxes from "./ClippingBoxes";
import { useBoxesProps } from "./contextData";
import { useBoxesProps, boxesPropsContext } from "./contextData";

const OutputArea: React.FC<{
layoutSize: RectSize;
baseCanvas: CanvasImageSource;
}> = ({ layoutSize, baseCanvas }) => {
// TODO: 子に渡しているだけのため消したい
// Contextは<Stage>を通り抜けないためブリッジする必要がある
const boxesProps = useBoxesProps();

return (
Expand All @@ -16,10 +16,12 @@ const OutputArea: React.FC<{
width={layoutSize.width}
height={layoutSize.height}
>
<Layer>
<Image image={baseCanvas} />
<ClippingBoxes currentFrame={baseCanvas} boxesProps={boxesProps} />
</Layer>
<boxesPropsContext.Provider value={boxesProps}>
<Layer>
<Image image={baseCanvas} />
<ClippingBoxes currentFrame={baseCanvas} />
</Layer>
</boxesPropsContext.Provider>
</Stage>
);
};
Expand Down

0 comments on commit 21677f8

Please sign in to comment.