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

Introducing WebAssembly, Specs, ReactApeTree and Platform module #129

Open raphamorim opened 2 years ago

raphamorim commented 2 years ago

Summary

This PR introduces:

Below the explanation/overview for each of the features

Specs

This pull request introduces specs. Specs are formal agreement and documentation regarding React Ape Elements behavior, example below:

Screen Shot 2022-07-13 at 21 14 48

Render with WASM/Canvas (fallback to JS/Canvas)

More information soon.

ReactApeTree Overview

Since React Ape render using canvas, it can't properly read parent styles correctly. The idea behind this PR is to reduce issues regarding hierarchy, those problems makes the App looks super weird unless you rule/specify intentionally in every View which style it should carry (it's how Ape works nowaday ~unfortanelly~).

This PR introduces a tree that contains the layout and style property for each node, so can easily propagate it between children

Related #67

Known issues:

Demo

return (
  <View style={{width: 80, height: 80, backgroundColor: 'grey', color: 'orange'}}>
    <View>
      <View style={{width: 80, height: 80, backgroundColor: 'powderblue'}}>
        <View
          style={{
            width: 30,
            height: 30
          }}>
          <Text>should be in orange</Text>
        </View>
      </View>
    </View>
  </View>
);

Before

Skärmavbild 2022-06-22 kl  06 46 07

After

Usage of _reactApeTree when process.env.NODE_ENV !== 'production'

Screen Shot 2022-07-11 at 19 52 03

Platform

When building a cross-platform app, you'll want to re-use as much code as possible. You'll probably have different scenarios where different code might be necessary. For instance, you may want to implement separated visual components for LG-webOS and Samsung-Tizen.

This PR also introduces the Platform module to easily organize your code and separate it by platform:

import { Platform } from 'react-ape';

console.log(Platform('webos')) // true
console.log(Platform('tizen')) // false
console.log(Platform('orsay')) // false