Open codeReader52 opened 2 years ago
I am having the same issue. Were you able to get this resolved?
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, {
...
})
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} />
);
};
Something with the TypeScript code is off :/
Hi experts, I was attempting to initialise the
Expo2DContext
according to the example inREADME.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:options
probably should be optional? This code suggests that we can just plug in anull
orundefined
and it should default correctly.gl
is probably notnumber
? From the example in theREADME.md
file, it should really be the input of theonContextCreate
props of theGLView
component? MaybeExpoWebGLRenderingContext
or at leastWebGL2RenderingContext
would be more appropriate thannumber
?Thanks for looking at my queries!!! 🙏 🙏