forked from pmndrs/react-three-flex
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontext.ts
More file actions
44 lines (38 loc) · 1.16 KB
/
context.ts
File metadata and controls
44 lines (38 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { createContext } from 'react'
import { YogaNode } from 'yoga-layout-prebuilt'
import { Group } from 'three'
import { R3FlexProps } from './props'
export interface SharedFlexContext {
scaleFactor: number
requestReflow(): void
registerBox(node: YogaNode, group: Group, flexProps: R3FlexProps, centerAnchor?: boolean): boolean
unregisterBox(node: YogaNode): void
notInitialized?: boolean
}
const initialSharedFlexContext: SharedFlexContext = {
scaleFactor: 100,
requestReflow() {
console.warn('Flex not initialized! Please report')
},
registerBox() {
console.warn('Flex not initialized! Please report')
return false
},
unregisterBox() {
console.warn('Flex not initialized! Please report')
},
notInitialized: true,
}
export const flexContext = createContext<SharedFlexContext>(initialSharedFlexContext)
export interface SharedBoxContext {
node: YogaNode | null
size: [number, number]
centerAnchor?: boolean
notInitialized?: boolean
}
const initialSharedBoxContext: SharedBoxContext = {
node: null,
size: [0, 0],
notInitialized: true,
}
export const boxContext = createContext<SharedBoxContext>(initialSharedBoxContext)