Skip to content

Commit

Permalink
Start fixing new flow errors (facebookarchive#753)
Browse files Browse the repository at this point in the history
Start fixing new flow errors
  • Loading branch information
andrewimm authored Oct 9, 2019
1 parent f5be836 commit 65d3a4f
Show file tree
Hide file tree
Showing 13 changed files with 60 additions and 30 deletions.
19 changes: 15 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,22 @@ jobs:
- checkout
- run: yarn
- run: yarn build
flow:
working_directory: ~/react-360
docker:
- image: circleci/node:10
steps:
- checkout
- run: yarn
- run: yarn flow
test-unit:
working_directory: ~/react-360
docker:
- image: circleci/node:10
steps:
- checkout
- run: yarn
- run: yarn build
- run: yarn test
render-tests:
working_directory: ~/react-360/render-tests
Expand All @@ -30,8 +40,9 @@ workflows:
jobs:
- build
- test-unit:
requires:
- build
requires:
- build
- render-tests:
requires:
- build
requires:
- build
- flow
15 changes: 3 additions & 12 deletions .flowconfig
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
[ignore]
.*/Libraries/.*
.*/docs/.*
.*/EndToEnd/.*
.*/jest/.*
.*/website/.*
.*/__tests__/.*
<PROJECT_ROOT>/addons/.*
<PROJECT_ROOT>/node_modules/.*
<PROJECT_ROOT>/packages/react-webgl/.*
<PROJECT_ROOT>/packages/react-webgl-video-manager/.*
<PROJECT_ROOT>/packages/webgl-lite/.*
<PROJECT_ROOT>/packages/webgl-ui/.*
<PROJECT_ROOT>/packages/react-360-common-ui/.*
<PROJECT_ROOT>/Libraries/.*
<PROJECT_ROOT>/React360/.*

[include]

Expand All @@ -21,7 +16,3 @@ defs/
emoji=true

module.ignore_non_literal_requires=true
module.name_mapper='^ovrui$' -> '<PROJECT_ROOT>/OVRUI/src/OVRUI.js'

[version]
0.63.1
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@
"@babel/plugin-transform-flow-strip-types": "7.2.3",
"@babel/plugin-transform-modules-commonjs": "7.2.0",
"@babel/preset-react": "7.0.0",
"flow-bin": "^0.109.0",
"jest": "^24.9.0",
"lerna": "3.16.4"
},
"scripts": {
"build": "lerna run build",
"flow": "flow",
"test": "jest"
}
}
4 changes: 4 additions & 0 deletions packages/react-360/src/Container.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ export default class Container {
this._canvas = document.createElement('canvas');
this._canvas.style.backgroundColor = '#000000';
const gl = this._canvas.getContext('webgl', {xrCompatible: true, alpha: false});
if (gl == null) {
throw new Error('Unable to construct WebGL context');
}
// $FlowFixMe: Flow thinks gl might be a canvas 2d context?
this._gl = gl;
this._sharedTextureManager = new GLUI.TextureManager(gl);
this.group = new WebGL.RenderGroup(gl);
Expand Down
14 changes: 11 additions & 3 deletions packages/react-webgl/src/CanvasRoot.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,15 @@ export type CanvasRootOptions = {
};

export default class CanvasRoot extends GLRoot {
_canvas: HTMLCanvasElement;

constructor(options: CanvasRootOptions = {}) {
const canvas = options.canvas || document.createElement('canvas');
canvas.style.backgroundColor = 'transparent';
const gl = canvas.getContext('webgl', {alpha: true, premultipliedAlpha: false});
if (gl == null) {
throw new Error('Unable to construct WebGL context');
}
super(gl, options.text);
this._canvas = canvas;

Expand Down Expand Up @@ -71,8 +76,11 @@ export default class CanvasRoot extends GLRoot {
let offsetLeft = 0;
let offsetTarget = e.target;
while (offsetTarget != null) {
// $FlowFixMe
offsetTop += offsetTarget.offsetTop;
// $FlowFixMe
offsetLeft += offsetTarget.offsetLeft;
// $FlowFixMe
offsetTarget = offsetTarget.offsetTarget;
}
this.getSurface().setCursor(
Expand Down Expand Up @@ -100,17 +108,17 @@ export default class CanvasRoot extends GLRoot {
});
};

_onTouchStart = e => {
_onTouchStart = (e: TouchEvent) => {
this._setCursorFromTouch(e, true);
this._onPressIn();
e.preventDefault();
};

_onTouchMove = e => {
_onTouchMove = (e: TouchEvent) => {
this._setCursorFromTouch(e, false);
};

_onMouseMove = e => {
_onMouseMove = (e: MouseEvent) => {
this.getSurface().setCursor(e.offsetX, e.offsetY);
};

Expand Down
8 changes: 5 additions & 3 deletions packages/react-webgl/src/Elements.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
* @flow
*/

import type GLRoot from './GLRoot';

import {Image, Text, View} from 'webgl-ui';

export const quad = {
create: root => root.getSurface().createView(),
create: (root: GLRoot) => root.getSurface().createView(),
dispatchers: (() => {
const d = {};
View.registerBindings(d);
Expand All @@ -21,7 +23,7 @@ export const quad = {
};

export const text = {
create: root => root.getSurface().createText(),
create: (root: GLRoot) => root.getSurface().createText(),
dispatchers: (() => {
const d = {};
Text.registerBindings(d);
Expand All @@ -30,7 +32,7 @@ export const text = {
};

export const image = {
create: root => root.getSurface().createImage(),
create: (root: GLRoot) => root.getSurface().createImage(),
dispatchers: (() => {
const d = {};
Image.registerBindings(d);
Expand Down
9 changes: 7 additions & 2 deletions packages/react-webgl/src/GLRoot.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,15 @@
* @flow
*/

import {Surface, TextureManager, type TextImplementation} from 'webgl-ui';
import {Surface, TextureManager, type ShadowViewWebGL, type TextImplementation} from 'webgl-ui';
import {FontImplementation} from 'webgl-ui-system-font';

export default class GLRoot {
_gl: WebGLRenderingContext;
_surface: Surface;
_textImplementation: TextImplementation;
_textureManager: TextureManager;

constructor(gl: WebGLRenderingContext, text?: TextImplementation) {
this._gl = gl;
this._surface = new Surface(gl);
Expand All @@ -22,7 +27,7 @@ export default class GLRoot {
this._surface.useTextureManager(this._textureManager);
}

setRoot(child) {
setRoot(child: ShadowViewWebGL<*>) {
this._surface.setRootNode(child);
}

Expand Down
2 changes: 0 additions & 2 deletions packages/react-webgl/src/HostConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @flow
*/

import * as Elements from './Elements';
Expand Down
4 changes: 3 additions & 1 deletion packages/react-webgl/src/Pressable.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@ type State = {|
pressed: boolean,
|};

type Event = {buttonClass?: string, action?: 'up' | 'down'};

export default class Pressable extends React.PureComponent<Props, State> {
state = {hovered: false, pressed: false};

_onInput = event => {
_onInput = (event: Event) => {
if (event.buttonClass !== 'confirm') {
return;
}
Expand Down
3 changes: 2 additions & 1 deletion packages/react-webgl/src/ReactWGL.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* @flow
*/

// $FlowFixMe
import Reconciler from 'react-reconciler';
import * as HostConfig from './HostConfig';
import GLRoot from './GLRoot';
Expand All @@ -21,7 +22,7 @@ import Video from './Video.react';

const Renderer = Reconciler(HostConfig);

export function render(element, container, callback) {
export function render(element: Element, container: any, callback: any) {
if (!container.__rootContainer) {
container.__rootContainer = Renderer.createContainer(container, false);
}
Expand Down
2 changes: 2 additions & 0 deletions packages/react-webgl/src/RenderTargetRoot.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export type RenderTargetRootOptions = {
* which can then be used in a larger WebGL scene.
*/
export default class RenderTargetRoot extends GLRoot {
_fb: WebGL.FrameBuffer;

constructor(gl: WebGLRenderingContext, options: RenderTargetRootOptions = {}) {
super(gl, options.text);
const width = options.width || 0;
Expand Down
2 changes: 1 addition & 1 deletion packages/react-webgl/src/applyProps.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const EVENTS = {
onInput: 'input',
};

export default function applyProps(view, oldProps, newProps, dispatchers) {
export default function applyProps(view: any, oldProps: Object, newProps: Object, dispatchers: {[string]: (any, any) => void}) {
for (const p in newProps) {
if (p === 'children') {
continue;
Expand Down
6 changes: 5 additions & 1 deletion packages/webgl-ui-system-font/src/FontMeasure.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ export default class FontMeasure {
this._lineMetrics.appendChild(this._lineOne);
this._lineMetrics.appendChild(document.createElement('br'));
this._lineMetrics.appendChild(this._lineTwo);
document.body.appendChild(this._lineMetrics);
const body = document.body;
if (body == null) {
throw new Error('Cannot measure font metrics without a valid document body');
}
body.appendChild(this._lineMetrics);
}

measureGlyph(glyph: string) {
Expand Down

0 comments on commit 65d3a4f

Please sign in to comment.