@@ -3,19 +3,14 @@ import "./style.css"
33import { GraphicsContext } from "../graphics/context" ;
44import { Timeline } from "./timeline" ;
55import { MetacityLabel } from "./label" ;
6+ import { MetacityLayerProps } from "./layer" ;
67
78
89interface MetacityGLProps {
910 background ?: number ;
1011 children ?: React . ReactNode | React . ReactNode [ ] ;
1112}
1213
13-
14- interface ChildProps {
15- context : GraphicsContext ;
16- }
17-
18-
1914export function MetacityGL ( props : MetacityGLProps ) {
2015 const [ context , setContext ] = React . useState < GraphicsContext > ( ) ;
2116 const canvasRef = React . useRef < HTMLCanvasElement > ( null ) ;
@@ -25,6 +20,9 @@ export function MetacityGL(props: MetacityGLProps) {
2520 const [ hoverLocation , setHoverLocation ] = React . useState < { x : number , y : number } | null > ( null ) ;
2621 const children = React . Children . toArray ( props . children ) ;
2722
23+ const [ enableTimeline , setEnableTimeline ] = React . useState < boolean > ( false ) ;
24+ const [ enableUI , setEnableUI ] = React . useState < boolean > ( false ) ;
25+
2826 React . useEffect ( ( ) => {
2927 const canvas = canvasRef . current ;
3028 const container = containerRef . current ;
@@ -67,6 +65,21 @@ export function MetacityGL(props: MetacityGLProps) {
6765 }
6866 } ;
6967
68+ React . useEffect ( ( ) => {
69+ for ( let child of children ) {
70+ if ( React . isValidElement ( child ) ) {
71+ const childProps = child . props as MetacityLayerProps ;
72+ if ( childProps . enableTimeline ) {
73+ setEnableTimeline ( true ) ;
74+ }
75+ if ( childProps . enableUI ) {
76+ setEnableUI ( true ) ;
77+ }
78+ }
79+ }
80+ } , [ children ] ) ;
81+
82+
7083
7184
7285 window . onresize = ( ) => {
@@ -88,22 +101,21 @@ export function MetacityGL(props: MetacityGLProps) {
88101 left : hoverLocation ?. x ,
89102 top : hoverLocation ?. y ,
90103 } }
91-
92104 >
93105 < pre > { JSON . stringify ( metadataHover , null , 2 ) } </ pre >
94106 </ div >
95107 } )
96108 </ div >
97- < Timeline context = { context } />
109+ { enableTimeline && < Timeline context = { context } /> }
98110 </ div >
99- < div className = "MetacityGLSidebar" >
111+ { enableUI && < div className = "MetacityGLSidebar" >
100112 { children . map ( ( child , index ) => {
101- if ( React . isValidElement < ChildProps > ( child ) ) {
113+ if ( React . isValidElement < MetacityLayerProps > ( child ) ) {
102114 return React . cloneElement ( child , { context : context } ) ;
103115 }
104116 } ) }
105117 < MetacityLabel context = { context } />
106- </ div >
118+ </ div > }
107119 </ div >
108120 ) ;
109121}
0 commit comments