Skip to content

Commit

Permalink
fix(types): fix canvas types after merging
Browse files Browse the repository at this point in the history
  • Loading branch information
setsun committed Apr 20, 2019
1 parent eba50d5 commit acc831b
Showing 1 changed file with 73 additions and 2 deletions.
75 changes: 73 additions & 2 deletions src/canvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,78 @@ import React, { useRef, useEffect, useMemo, useState, useCallback, useContext }
import ResizeObserver from 'resize-observer-polyfill'
import { invalidate, applyProps, render, unmountComponentAtNode } from './reconciler'

export const stateContext = React.createContext()
export type CanvasContext = {
canvas?: React.MutableRefObject<any>,
subscribers: Array<Function>,
frames: 0,
aspect: 0,
gl?: THREE.WebGLRenderer,
camera?: THREE.Camera,
scene?: THREE.Scene,
canvasRect?: DOMRectReadOnly,
viewport?: { width: number, height: number },
size?: { left: number, top: number, width: number, height: number },
ready: boolean,
manual: boolean,
active: boolean,
captured: boolean,
invalidateFrameloop: boolean,
subscribe?: (callback: Function, main: any) => () => any,
setManual: (takeOverRenderloop: boolean) => any,
setDefaultCamera: (camera: THREE.Camera) => any,
invalidate: () => any,
}

export type CanvasProps = {
children: React.ReactNode;
gl: THREE.WebGLRenderer;
orthographic: THREE.OrthographicCamera | THREE.PerspectiveCamera;
raycaster: THREE.Raycaster;
camera?: THREE.Camera;
style?: React.CSSProperties;
pixelRatio?: number;
invalidateFrameloop?: boolean;
onCreated: Function;
}

export type Measure = [
{ ref: React.MutableRefObject<any> },
{ left: number, top: number, width: number, height: number }
]

export type IntersectObject = Event & THREE.Intersection & {
ray: THREE.Raycaster;
stopped: { current: boolean };
uuid: string;
transform: {
x: Function,
y: Function
};
}

const defaultRef = {
ready: false,
subscribers: [],
manual: false,
active: true,
canvas: undefined,
gl: undefined,
camera: undefined,
scene: undefined,
size: undefined,
canvasRect: undefined,
frames: 0,
aspect: 0,
viewport: undefined,
captured: undefined,
invalidateFrameloop: false,
subscribe: (fn, main) => () => {},
setManual: (takeOverRenderloop) => {},
setDefaultCamera: (cam) => {},
invalidate: () => {}
}

export const stateContext = React.createContext(defaultRef)

function useMeasure() {
const ref = useRef()
Expand All @@ -28,7 +99,7 @@ export const Canvas = React.memo(
invalidateFrameloop = false,
onCreated,
...rest
}) => {
}: CanvasProps) => {
// Local, reactive state
const canvas = useRef()
const [ready, setReady] = useState(false)
Expand Down

0 comments on commit acc831b

Please sign in to comment.