Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript error for Expo2DContext #30

Open
codeReader52 opened this issue Dec 29, 2021 · 4 comments
Open

Typescript error for Expo2DContext #30

codeReader52 opened this issue Dec 29, 2021 · 4 comments

Comments

@codeReader52
Copy link

codeReader52 commented Dec 29, 2021

Hi experts,
I was attempting to initialise the Expo2DContext according to the example in README.md (here) and got some typescript errors on both parameters in the constructor. Currently, the type specified in the constructor is: constructor(gl: number, options: Expo2dContextOptions). Specifically:

  • The type of options probably should be optional? This code suggests that we can just plug in a null or undefined and it should default correctly.
  • The type of gl is probably not number? From the example in the README.md file, it should really be the input of the onContextCreate props of the GLView component? Maybe ExpoWebGLRenderingContext or at least WebGL2RenderingContext would be more appropriate than number?

Thanks for looking at my queries!!! 🙏 🙏

@natemunk
Copy link

I am having the same issue. Were you able to get this resolved?

@egordorichev
Copy link

I've been researching this issue, looks like the gl object has contextId property, that is used for the constructor.
So

var ctx = new Expo2DContext(gl.contextId, {
  ...
})

@Kana00
Copy link

Kana00 commented Feb 2, 2023

var ctx = new Expo2DContext(gl.contextId, {
  ...
})

This solution doesn't work in some cases when the context needs the functions in gl, it doesn't find them if you put a number... I propose an alternative that I am using for the moment, until this issue is solved

import { ExpoWebGLRenderingContext, GLView } from "expo-gl";
import Expo2DContext, { Expo2dContextOptions } from "expo-2d-context";

interface YOUR_PROPS {}

const options: Expo2dContextOptions = {
  fastFillTesselation: true,
  maxGradStops: 128,
  renderWithOffscreenBuffer: false
}

export const YOUR_COMPONENT: React.FC<YOUR_PROPS> = (props) => {

  const onGLContextCreate = (gl: ExpoWebGLRenderingContext) => {
    // @ts-ignore
    var ctx = new Expo2DContext(gl, options);

    // draw shapes
    ctx.beginPath();
    ctx.arc(40, 40, 40, 0, 2 * Math.PI);
    ctx.stroke();
    ctx.flush();
  };

  return (
    <GLView style={{ width: 80, height: 80, backgroundColor: '#00000011' }} onContextCreate={onGLContextCreate} />
  );
};

@tomdoeslinux
Copy link

Something with the TypeScript code is off :/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants