raphamorim / react-ape

🦍• React Renderer to build UI interfaces using canvas/WebGL (TV and Hardware-Accelerated GPU development based)
https://raphamorim.io/react-ape/
MIT License
1.57k stars 48 forks source link

[Discussion] Support custom Components to have CanvasContext access #11

Closed raphamorim closed 4 years ago

raphamorim commented 6 years ago

first draft:

import React, { Component } from 'react'
import { render, createComponent } from 'react-ape'

const MyComponent = createComponent(function(props, children, ctx) {
  ctx.rect(20,20,150,100);
  ctx.stroke();
})

//class MyComponent extend React.Component {
//  render
//}

render(MyComponent, document.querySelector('canvas'));
raphamorim commented 6 years ago

hmm, maybe something like would be better:

import React from 'react';
import { registerComponent, View, render } from 'reactApe';

function Carousel(props, canvasContext) {
    // ctx.rect();
    // draws carosel
}

registerComponent('Carousel', Carousel);

const myApp = () => (
   <View>
      <Carousel dataSource={...}/>
   </View>
);

render(myApp, documentQuerySelector('#canvas-id'));