Coder Social home page Coder Social logo

raphamorim / react-ape Goto Github PK

View Code? Open in Web Editor NEW
1.6K 25.0 48.0 38.04 MB

🦍• React Renderer to build UI interfaces using canvas/WebGL (TV and Hardware-Accelerated GPU development based)

Home Page: https://raphamorim.io/react-ape/

License: MIT License

JavaScript 95.02% HTML 1.20% CSS 3.77%
react react-renderer renderer render gl webgl webgl2 canvas canvas-html5 react-ape

react-ape's Introduction

React Renderer to build UI interfaces using Canvas/WebGL

DISCLAIMER: In experimental stage

React Ape is a react renderer to build UI interfaces using canvas/WebGL. React Ape was built to be an optional React-TV renderer. It's mainly a renderer focused on creating things for TV, PS5, PS4, Nintendo Switch, PS Vita, PS3 and low memory devices.

React Ape lets you build Canvas apps using React. React Ape uses the same design as React, letting you compose a rich UI from declarative components.

Understanding the Problem

tl;dr: Crafting a high-performance TV user interface using React (and also good to read: 60 FPS on the mobile web)

Crafting a high-performance TV user interface based on DOM is a real challenge, because of some reasons:

  • Limited graphics acceleration
  • Single core CPUs
  • High Memory Usage for a common TV App

These restrictions make super responsive 60fps experiences especially tricky. The strategy is step in the renderer based on a hardware-accelerated canvas.

Examples

App Name Github App URL
Photo Gallery raphamorim/react-ape-photo-gallery Check it out
Movie List raphamorim/react-ape-movie-list-demo Check it out
Add yours here --------- ---------

API Usage

Install it using NPM or Yarn

# NPM
npm install react-ape

# Yarn
yarn add react-ape

React Ape's API usage example

import React, { Component } from 'react';
import { Text, View } from 'react-ape';

class ReactApeComponent extends Component {
  render() {
    return (
      <View>
        <Text>
          Render this text on Canvas
        </Text>
        <Text>
          You just use React Ape components like 'View' and 'Text',
          just like React Native.
        </Text>
      </View>
    );
  }
}

Demo on PS Vita

Demo on PS Vita

Demo on TV

Demo on TV

Testing it

React-Ape's CI uses macos-latest and since canvas renders a different output based on the operating system (node-canvas have rasterize fonts in different ways based on OS). It requires run the tests on the same OS. Please be aware that if you want to contribute using a different OS, make sure that you have Docker installed.

Roadmap

You can follow React-Ape development status here: Roadmap

Credits

A special thanks to Raphael Eckhardt for making the logo <3

react-ape's People

Contributors

backyardcoder avatar danielruf avatar dependabot[bot] avatar fabiomcosta avatar hayanisaid avatar jeffersonmourak avatar matheusmonte avatar raphamorim avatar skvale avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-ape's Issues

Docs: Getting started and Learning the Basics

"Getting started" and "Learning the Basics" are outdated and contain wrong information. We don't have any boilerplate yet. Would be good to update those sections with valid information. Open to ideas :)

Skärmavbild 2022-06-30 kl  15 59 30

Skärmavbild 2022-06-30 kl  15 59 51

[Spectrum Request] - It would be a good idea to have a community

I've check your project and it seems really cool and ambitious to me, the idea of canvas as a "rendering engine" can have many advantages and use cases (personally i'll love to dig into PS4 UI dev), i'm pretty sure there's a lot of more people who would be interested in contributing.

However it would be great if these people could find a way to communicate, that's why i'm suggesting a spectrum community

Cheers, and never stop doing it! 🔥

Views rendering Views as children

I'm seeing an oddity when rendering something like this

const s = StyleSheet.create({
  container: {
    backgroundColor: 'aliceblue',
    height: 300,
    width: 200,
  },
  child: {
    height: 100,
    width: 100,
  }
})
<View style={s.container}>
  {["bisque", "cadetblue", "darkseagreen"].map((c, i) => (
    <View style={{...s.child, backgroundColor: c}}>
      <Text content={`Child ${i+1}`} />
    </View>
  ))}
</View>

I'd expect to see this, more or less:

Screenshot 2021-01-30 at 17 37 50

instead, it's positioning the parent <View/> after the children. Like this

Screenshot 2021-01-30 at 15 39 00

You can also see similar drawing setting the container to something like, {position: 'absolute', left: 100, top: 100}

Screenshot 2021-01-30 at 19 51 42

I think the issue is around here, https://github.com/raphamorim/react-ape/blob/master/packages/react-ape/renderer/elements/View.js#L52-L56

Also, it seems as though the views are rendered in order of child to parent. With that in mind, I'm not sure how you can render such a list without recomputing the child positions when you finally know the position of the parent. Although, I could be wrong. That happens often.

Fix React Devtools

After the reconciler update, React DevTools isn't working properly anymore. Need to investigate.

Thoughts on where I can help

I work on UI for the PS4 daily, so I have some investment in this type of work, and over the past year, I have implemented a lot of the ideas here. So if it is welcome, I am going to use this issue to jot down some ideas (some i'm sure you have planned), and see if I can help in any way.

You are probably busy in the weeds for the reconciler.

Things I have implemented that I could maybe bring over:

  • ListView
  • ScrollableView
  • FocusSystem (gamepad for example)
  • Positioning based on parent.
  • Improvements to the Image component, for example pre-loaded state, post-loaded, error, and caching.
  • Accessibility
  • Animation

Another huge win would be to implement flexbox https://github.com/facebook/yoga

Above all of this, I have a ps4 devkit that I can help test on.

Let me know if you need/want help, and if it is too early, I can check back later.

fix publish GH workflow: publish and tests should not run tests twice

Currently the Publish workflow runs together with test, executing the same yarn ci (running tests again) it shouldn't be happening. Should wait for the test workflow check and the follow up with publish.

There's few approaches that could fix it:

  • check if the tests have passed
  • move the publish workflow to tests as a step but only runs if commit message have [publish]

Docs: Create a boilerplate for start with React Ape

Create a boilerplate project to start with React Ape. It should be quite simple, just one component and "live reload" working. I'm open to ideas to start the project, but I really don't to add a CLI for it. It can be a script on gh (ex: sh https://github.com/raphamorim/react-ape/raw/scripts/start.sh) that can clone and install the dependencies.

React Ape 0.1.0 🔥🐒

Related #16 #19

Docs

Components

APIs

  • dimensions #28

Core

  • Virtual Canvas algorithm #21 ⚡️⚡️⚡️
  • Allows to inspect using React DevTools 💯(dependent of #21)

Support for life-cycle events on Renderer elements

Please add support for life-cycle events to basic Renderer elements such as:

  • componentDidMount
  • componentWillUnmount
  • componentDidUpdate

I currently work with a fps-based rendering engine operating on canvas, and I wanted to try implementing those elements based on the existing Components on this engine.

ListView

  • Create ListView Component
  • ListView Scroll Horizontal
  • ListView Scroll Vertical
  • Automatically distribute items coordinates based on width/height of each child

onClick on View

Currently we don't have support to onClick on any element, we could start with view maybe reusing spatial information in the view object.

Fix some style heritage issue

Currently, if isn't setting parent styles into the children it just uses the default styles, for example:

<View style={{ color: 'orange' }}><Text/></View>

ˆ Text should use color orange instead of black (which is the default).

[Discussion] Support custom Components to have CanvasContext access

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'));

react ape roadmap and future

Hi, @raphamorim

This project looks really cool and I want to help it also to develop and learn.

  • are you thinking about in a roadmap? like review the already done things and update?
  • is the react functional components features inside of the roadmap?
  • bonus: fix the roadmap hyperlink on docs
    image

React Ape examples

image

Added few sections about why/examples and I will start to work on few example Apps to stress the renderer to make it close to something stable. If you're interested in create an example app would be great (for now I am targeting TV devices to test), add a comment here or a PR adding your example in the README.md

Dropping frames ~ Render perfomance in TV devices

Currently React Ape drop frames when rendering a lot of components in the same time. This issue was reported by @raphaelpor originally. The reason of problem is known: It renders using stack logic so basically waits for the JavaScript to process the forEach then render each item per order which isn't the best solution. I will be working in a rewrite of the core render logic and also porting logic to Web components (as a performance test, e.g: https://engineering.icf.com/reusable-canvas-based-web-components/) if it's available in the window context.

image

Add Flexbox support

Add flexbox support over View, Text and Image components. Should follow similar API to React Native.

Fix update type render issue

Currently, if you change the render based on state, for example: View to Text it just doesn't clean the View on unmount.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.