expo-gl 13.2.0 → 13.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -10,6 +10,20 @@
10
10
 
11
11
  ### 💡 Others
12
12
 
13
+ ## 13.4.0 — 2023-10-17
14
+
15
+ ### 🛠 Breaking changes
16
+
17
+ - Dropped support for Android SDK 21 and 22. ([#24201](https://github.com/expo/expo/pull/24201) by [@behenate](https://github.com/behenate))
18
+
19
+ ### 💡 Others
20
+
21
+ - Ship untranspiled JSX to support custom handling of `jsx` and `createElement`. ([#24889](https://github.com/expo/expo/pull/24889) by [@EvanBacon](https://github.com/EvanBacon))
22
+
23
+ ## 13.3.0 — 2023-09-15
24
+
25
+ _This version does not introduce any user-facing changes._
26
+
13
27
  ## 13.2.0 — 2023-09-04
14
28
 
15
29
  ### 🎉 New features
@@ -6,7 +6,7 @@ apply plugin: 'maven-publish'
6
6
  apply plugin: "de.undercouch.download"
7
7
 
8
8
  group = 'host.exp.exponent'
9
- version = '13.2.0'
9
+ version = '13.4.0'
10
10
 
11
11
  def REACT_NATIVE_BUILD_FROM_SOURCE = findProject(":ReactAndroid") != null
12
12
  def REACT_NATIVE_DIR = REACT_NATIVE_BUILD_FROM_SOURCE
@@ -26,13 +26,18 @@ def reactNativeArchitectures() {
26
26
  return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
27
27
  }
28
28
 
29
- buildscript {
30
- def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
31
- if (expoModulesCorePlugin.exists()) {
32
- apply from: expoModulesCorePlugin
33
- applyKotlinExpoModulesCorePlugin()
29
+ def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
30
+ if (expoModulesCorePlugin.exists()) {
31
+ apply from: expoModulesCorePlugin
32
+ applyKotlinExpoModulesCorePlugin()
33
+ // Remove this check, but keep the contents after SDK49 support is dropped
34
+ if (safeExtGet("expoProvidesDefaultConfig", false)) {
35
+ useExpoPublishing()
36
+ useCoreDependencies()
34
37
  }
38
+ }
35
39
 
40
+ buildscript {
36
41
  // Simple helper that allows the root project to override versions declared by this library.
37
42
  ext.safeExtGet = { prop, fallback ->
38
43
  rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
@@ -57,23 +62,44 @@ buildscript {
57
62
  }
58
63
  }
59
64
 
60
- afterEvaluate {
61
- publishing {
62
- publications {
63
- release(MavenPublication) {
64
- from components.release
65
+ // Remove this if and it's contents, when support for SDK49 is dropped
66
+ if (!safeExtGet("expoProvidesDefaultConfig", false)) {
67
+ afterEvaluate {
68
+ publishing {
69
+ publications {
70
+ release(MavenPublication) {
71
+ from components.release
72
+ }
65
73
  }
66
- }
67
- repositories {
68
- maven {
69
- url = mavenLocal().url
74
+ repositories {
75
+ maven {
76
+ url = mavenLocal().url
77
+ }
70
78
  }
71
79
  }
72
80
  }
73
81
  }
74
82
 
75
83
  android {
76
- compileSdkVersion safeExtGet("compileSdkVersion", 33)
84
+ // Remove this if and it's contents, when support for SDK49 is dropped
85
+ if (!safeExtGet("expoProvidesDefaultConfig", false)) {
86
+ compileSdkVersion safeExtGet("compileSdkVersion", 33)
87
+
88
+ defaultConfig {
89
+ minSdkVersion safeExtGet("minSdkVersion", 23)
90
+ targetSdkVersion safeExtGet("targetSdkVersion", 33)
91
+ }
92
+
93
+ publishing {
94
+ singleVariant("release") {
95
+ withSourcesJar()
96
+ }
97
+ }
98
+
99
+ lintOptions {
100
+ abortOnError false
101
+ }
102
+ }
77
103
 
78
104
  if (rootProject.hasProperty("ndkPath")) {
79
105
  ndkPath rootProject.ext.ndkPath
@@ -96,10 +122,8 @@ android {
96
122
 
97
123
  namespace "expo.modules.gl"
98
124
  defaultConfig {
99
- minSdkVersion safeExtGet("minSdkVersion", 21)
100
- targetSdkVersion safeExtGet("targetSdkVersion", 33)
101
125
  versionCode 31
102
- versionName "13.2.0"
126
+ versionName "13.4.0"
103
127
 
104
128
  externalNativeBuild {
105
129
  cmake {
@@ -137,15 +161,6 @@ android {
137
161
  extractHeaders
138
162
  extractJNI
139
163
  }
140
-
141
- lintOptions {
142
- abortOnError false
143
- }
144
- publishing {
145
- singleVariant("release") {
146
- withSourcesJar()
147
- }
148
- }
149
164
  }
150
165
 
151
166
  repositories {
@@ -154,9 +169,10 @@ repositories {
154
169
 
155
170
  dependencies {
156
171
  compileOnly 'com.facebook.soloader:soloader:0.8.2'
157
- implementation project(':expo-modules-core')
158
-
159
- implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${getKotlinVersion()}"
172
+ if (!safeExtGet("expoProvidesDefaultConfig", false)) {
173
+ implementation project(':expo-modules-core')
174
+ implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${getKotlinVersion()}"
175
+ }
160
176
 
161
177
  // Remove this when we drop SDK 47
162
178
  if (REACT_NATIVE_TARGET_VERSION >= 71) {
package/build/Canvas.js CHANGED
@@ -74,9 +74,10 @@ const CanvasWrapper = ({ pointerEvents, children, ...props }) => {
74
74
  }
75
75
  setRef(props.canvasRef, canvas);
76
76
  }, [_canvasRef]);
77
- return (React.createElement(View, { ...props, pointerEvents: "box-none", ref: ref, onLayout: onLayout },
78
- React.createElement(Canvas, { ref: _canvasRef, pointerEvents: pointerEvents, style: StyleSheet.absoluteFill }),
79
- children));
77
+ return (<View {...props} pointerEvents="box-none" ref={ref} onLayout={onLayout}>
78
+ <Canvas ref={_canvasRef} pointerEvents={pointerEvents} style={StyleSheet.absoluteFill}/>
79
+ {children}
80
+ </View>);
80
81
  };
81
82
  export default CanvasWrapper;
82
83
  //# sourceMappingURL=Canvas.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Canvas.js","sourceRoot":"","sources":["../src/Canvas.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,KAAK,KAAK,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,CAAC,KAAK,CAAC,CAAC;aACvB;SACF;IACH,CAAC,CAAC;IAEF,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACnB,IAAI,GAAG,CAAC,OAAO,IAAI,IAAI,EAAE;YACvB,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;SACpB;IACH,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IAEV,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACnB,gBAAgB,EAAE,CAAC;IACrB,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC;IAEX,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACnB,MAAM,MAAM,GAAG,UAAU,CAAC,OAAO,CAAC;QAClC,IAAI,MAAM,EAAE;YACV,gBAAgB,EAAE,CAAC;SACpB;QACD,MAAM,CAAC,KAAK,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;IAClC,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC;IAEjB,OAAO,CACL,oBAAC,IAAI,OAAK,KAAK,EAAE,aAAa,EAAC,UAAU,EAAC,GAAG,EAAE,GAAG,EAAE,QAAQ,EAAE,QAAQ;QACpE,oBAAC,MAAM,IAAC,GAAG,EAAE,UAAU,EAAE,aAAa,EAAE,aAAa,EAAE,KAAK,EAAE,UAAU,CAAC,YAAY,GAAI;QACxF,QAAQ,CACJ,CACR,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,aAAa,CAAC","sourcesContent":["import { Platform } from 'expo-modules-core';\nimport * as React from 'react';\nimport { findDOMNode } from 'react-dom';\nimport { LayoutChangeEvent, PixelRatio, StyleSheet, View, ViewProps } from 'react-native';\nimport createElement from 'react-native-web/dist/exports/createElement';\n\nfunction getElement(component) {\n try {\n return findDOMNode(component);\n } catch {\n return component;\n }\n}\n\nfunction setRef<T>(refProp: React.Ref<T>, ref: T | null) {\n if (!refProp) return;\n\n if (typeof refProp === 'function') {\n refProp(ref);\n } else if ('current' in refProp) {\n // @ts-ignore\n refProp.current = ref;\n }\n}\n\nconst Canvas = React.forwardRef(\n (props: React.ComponentProps<typeof View>, ref: React.Ref<HTMLCanvasElement>) =>\n createElement('canvas', { ...props, ref })\n);\n\nconst CanvasWrapper: React.FunctionComponent<\n ViewProps & {\n canvasRef: React.Ref<HTMLCanvasElement>;\n }\n> = ({ pointerEvents, children, ...props }) => {\n const [size, setSize] = React.useState<{ width: number; height: number } | null>(null);\n\n const ref = React.useRef<View>(null);\n const _canvasRef = React.useRef<HTMLCanvasElement>(null);\n\n function updateCanvasSize(): void {\n const canvas = _canvasRef.current;\n // eslint-disable-next-line no-undef\n if (typeof HTMLCanvasElement !== 'undefined' && canvas instanceof HTMLCanvasElement) {\n const size = getSize();\n const scale = PixelRatio.get();\n\n canvas.style.width = `${size.width}px`;\n canvas.style.height = `${size.height}px`;\n\n canvas.width = size.width * scale;\n canvas.height = size.height * scale;\n }\n }\n\n function getSize(): { width: number; height: number } {\n if (size) {\n return size;\n } else if (!ref.current || !Platform.isDOMAvailable) {\n return { width: 0, height: 0 };\n }\n const element = getElement(ref.current);\n const { offsetWidth: width = 0, offsetHeight: height = 0 } = element;\n return { width, height };\n }\n\n const onLayout = (event: LayoutChangeEvent) => {\n const {\n nativeEvent: {\n layout: { width, height },\n },\n } = event;\n\n if (width !== size?.width || height !== size.height) {\n setSize({ width, height });\n\n if (props.onLayout) {\n props.onLayout(event);\n }\n }\n };\n\n React.useEffect(() => {\n if (ref.current != null) {\n setSize(getSize());\n }\n }, [ref]);\n\n React.useEffect(() => {\n updateCanvasSize();\n }, [size]);\n\n React.useEffect(() => {\n const canvas = _canvasRef.current;\n if (canvas) {\n updateCanvasSize();\n }\n setRef(props.canvasRef, canvas);\n }, [_canvasRef]);\n\n return (\n <View {...props} pointerEvents=\"box-none\" ref={ref} onLayout={onLayout}>\n <Canvas ref={_canvasRef} pointerEvents={pointerEvents} style={StyleSheet.absoluteFill} />\n {children}\n </View>\n );\n};\n\nexport default CanvasWrapper;\n"]}
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port { LayoutChangeEvent, PixelRatio, StyleSheet, View, ViewProps } from 'react-native';\nimport createElement from 'react-native-web/dist/exports/createElement';\n\nfunction getElement(component) {\n try {\n return findDOMNode(component);\n } catch {\n return component;\n }\n}\n\nfunction setRef<T>(refProp: React.Ref<T>, ref: T | null) {\n if (!refProp) return;\n\n if (typeof refProp === 'function') {\n refProp(ref);\n } else if ('current' in refProp) {\n // @ts-ignore\n refProp.current = ref;\n }\n}\n\nconst Canvas = React.forwardRef(\n (props: React.ComponentProps<typeof View>, ref: React.Ref<HTMLCanvasElement>) =>\n createElement('canvas', { ...props, ref })\n);\n\nconst CanvasWrapper: React.FunctionComponent<\n ViewProps & {\n canvasRef: React.Ref<HTMLCanvasElement>;\n }\n> = ({ pointerEvents, children, ...props }) => {\n const [size, setSize] = React.useState<{ width: number; height: number } | null>(null);\n\n const ref = React.useRef<View>(null);\n const _canvasRef = React.useRef<HTMLCanvasElement>(null);\n\n function updateCanvasSize(): void {\n const canvas = _canvasRef.current;\n // eslint-disable-next-line no-undef\n if (typeof HTMLCanvasElement !== 'undefined' && canvas instanceof HTMLCanvasElement) {\n const size = getSize();\n const scale = PixelRatio.get();\n\n canvas.style.width = `${size.width}px`;\n canvas.style.height = `${size.height}px`;\n\n canvas.width = size.width * scale;\n canvas.height = size.height * scale;\n }\n }\n\n function getSize(): { width: number; height: number } {\n if (size) {\n return size;\n } else if (!ref.current || !Platform.isDOMAvailable) {\n return { width: 0, height: 0 };\n }\n const element = getElement(ref.current);\n const { offsetWidth: width = 0, offsetHeight: height = 0 } = element;\n return { width, height };\n }\n\n const onLayout = (event: LayoutChangeEvent) => {\n const {\n nativeEvent: {\n layout: { width, height },\n },\n } = event;\n\n if (width !== size?.width || height !== size.height) {\n setSize({ width, height });\n\n if (props.onLayout) {\n props.onLayout(event);\n }\n }\n };\n\n React.useEffect(() => {\n if (ref.current != null) {\n setSize(getSize());\n }\n }, [ref]);\n\n React.useEffect(() => {\n updateCanvasSize();\n }, [size]);\n\n React.useEffect(() => {\n const canvas = _canvasRef.current;\n if (canvas) {\n updateCanvasSize();\n }\n setRef(props.canvasRef, canvas);\n }, [_canvasRef]);\n\n return (\n <View {...props} pointerEvents=\"box-none\" ref={ref} onLayout={onLayout}>\n <Canvas ref={_canvasRef} pointerEvents={pointerEvents} style={StyleSheet.absoluteFill} />\n {children}\n </View>\n );\n};\n\nexport default CanvasWrapper;\n"]}
package/build/GLView.js CHANGED
@@ -56,15 +56,16 @@ export class GLView extends React.Component {
56
56
  render() {
57
57
  const { onContextCreate, // eslint-disable-line no-unused-vars
58
58
  msaaSamples, enableExperimentalWorkletSupport, ...viewProps } = this.props;
59
- return (React.createElement(View, { ...viewProps },
60
- React.createElement(NativeView, { ref: this._setNativeRef, style: {
61
- flex: 1,
62
- ...(Platform.OS === 'ios'
63
- ? {
64
- backgroundColor: 'transparent',
65
- }
66
- : {}),
67
- }, onSurfaceCreate: this._onSurfaceCreate, enableExperimentalWorkletSupport: enableExperimentalWorkletSupport, msaaSamples: Platform.OS === 'ios' ? msaaSamples : undefined })));
59
+ return (<View {...viewProps}>
60
+ <NativeView ref={this._setNativeRef} style={{
61
+ flex: 1,
62
+ ...(Platform.OS === 'ios'
63
+ ? {
64
+ backgroundColor: 'transparent',
65
+ }
66
+ : {}),
67
+ }} onSurfaceCreate={this._onSurfaceCreate} enableExperimentalWorkletSupport={enableExperimentalWorkletSupport} msaaSamples={Platform.OS === 'ios' ? msaaSamples : undefined}/>
68
+ </View>);
68
69
  }
69
70
  _setNativeRef = (nativeRef) => {
70
71
  if (this.props.nativeRef_EXPERIMENTAL) {
@@ -1 +1 @@
1
- {"version":3,"file":"GLView.js","sourceRoot":"","sources":["../src/GLView.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,mBAAmB,EACnB,wBAAwB,EACxB,UAAU,GACX,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAA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AAI,OAAO,SAAS,KAAK,QAAQ,EAAE;QAC/C,MAAM,IAAI,KAAK,CAAC,2BAA2B,MAAM,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;KACjE;IACD,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC","sourcesContent":["import {\n NativeModulesProxy,\n UnavailabilityError,\n requireNativeModule,\n requireNativeViewManager,\n CodedError,\n} from 'expo-modules-core';\nimport * as React from 'react';\nimport { Platform, View, findNodeHandle } from 'react-native';\n\nimport { configureLogging } from './GLUtils';\nimport {\n ComponentOrHandle,\n SurfaceCreateEvent,\n GLSnapshot,\n ExpoWebGLRenderingContext,\n SnapshotOptions,\n GLViewProps,\n} from './GLView.types';\nimport { createWorkletContextManager } from './GLWorkletContextManager';\n\n// @docsMissing\nexport type WebGLObject = {\n id: number;\n};\n\ndeclare let global: any;\n\nconst ExponentGLObjectManager = requireNativeModule('ExponentGLObjectManager');\nconst { ExponentGLViewManager } = NativeModulesProxy;\n\nconst NativeView = requireNativeViewManager('ExponentGLView');\nconst workletContextManager = createWorkletContextManager();\n\n// @needsAudit\n/**\n * A View that acts as an OpenGL ES render target. On mounting, an OpenGL ES context is created.\n * Its drawing buffer is presented as the contents of the View every frame.\n */\nexport class GLView extends React.Component<GLViewProps> {\n static NativeView: any;\n\n static defaultProps = {\n msaaSamples: 4,\n enableExperimentalWorkletSupport: false,\n };\n\n /**\n * Imperative API that creates headless context which is devoid of underlying view.\n * It's useful for headless rendering or in case you want to keep just one context per application and share it between multiple components.\n * It is slightly faster than usual context as it doesn't swap framebuffers and doesn't present them on the canvas,\n * however it may require you to take a snapshot in order to present its results.\n * Also, keep in mind that you need to set up a viewport and create your own framebuffer and texture that you will be drawing to, before you take a snapshot.\n * @return A promise that resolves to WebGL context object. See [WebGL API](#webgl-api) for more details.\n */\n static async createContextAsync(): Promise<ExpoWebGLRenderingContext> {\n const { exglCtxId } = await ExponentGLObjectManager.createContextAsync();\n return getGl(exglCtxId);\n }\n\n /**\n * Destroys given context.\n * @param exgl WebGL context to destroy.\n * @return A promise that resolves to boolean value that is `true` if given context existed and has been destroyed successfully.\n */\n static async destroyContextAsync(exgl?: ExpoWebGLRenderingContext | number): Promise<boolean> {\n const exglCtxId = getContextId(exgl);\n unregisterGLContext(exglCtxId);\n return ExponentGLObjectManager.destroyContextAsync(exglCtxId);\n }\n\n /**\n * Takes a snapshot of the framebuffer and saves it as a file to app's cache directory.\n * @param exgl WebGL context to take a snapshot from.\n * @param options\n * @return A promise that resolves to `GLSnapshot` object.\n */\n static async takeSnapshotAsync(\n exgl?: ExpoWebGLRenderingContext | number,\n options: SnapshotOptions = {}\n ): Promise<GLSnapshot> {\n const exglCtxId = getContextId(exgl);\n return ExponentGLObjectManager.takeSnapshotAsync(exglCtxId, options);\n }\n\n static getWorkletContext: (contextId: number) => ExpoWebGLRenderingContext | undefined =\n workletContextManager.getContext;\n\n nativeRef: ComponentOrHandle = null;\n exglCtxId?: number;\n\n render() {\n const {\n onContextCreate, // eslint-disable-line no-unused-vars\n msaaSamples,\n enableExperimentalWorkletSupport,\n ...viewProps\n } = this.props;\n\n return (\n <View {...viewProps}>\n <NativeView\n ref={this._setNativeRef}\n style={{\n flex: 1,\n ...(Platform.OS === 'ios'\n ? {\n backgroundColor: 'transparent',\n }\n : {}),\n }}\n onSurfaceCreate={this._onSurfaceCreate}\n enableExperimentalWorkletSupport={enableExperimentalWorkletSupport}\n msaaSamples={Platform.OS === 'ios' ? msaaSamples : undefined}\n />\n </View>\n );\n }\n\n _setNativeRef = (nativeRef: ComponentOrHandle): void => {\n if (this.props.nativeRef_EXPERIMENTAL) {\n this.props.nativeRef_EXPERIMENTAL(nativeRef);\n }\n this.nativeRef = nativeRef;\n };\n\n _onSurfaceCreate = ({ nativeEvent: { exglCtxId } }: SurfaceCreateEvent): void => {\n const gl = getGl(exglCtxId);\n\n this.exglCtxId = exglCtxId;\n\n if (this.props.onContextCreate) {\n this.props.onContextCreate(gl);\n }\n };\n\n componentWillUnmount(): void {\n if (this.exglCtxId) {\n unregisterGLContext(this.exglCtxId);\n }\n }\n\n componentDidUpdate(prevProps: GLViewProps): void {\n if (\n this.props.enableExperimentalWorkletSupport !== prevProps.enableExperimentalWorkletSupport\n ) {\n console.warn('Updating prop enableExperimentalWorkletSupport is not supported');\n }\n }\n\n // @docsMissing\n async startARSessionAsync(): Promise<any> {\n if (!ExponentGLViewManager.startARSessionAsync) {\n throw new UnavailabilityError('expo-gl', 'startARSessionAsync');\n }\n return await ExponentGLViewManager.startARSessionAsync(findNodeHandle(this.nativeRef));\n }\n\n // @docsMissing\n async createCameraTextureAsync(cameraRefOrHandle: ComponentOrHandle): Promise<WebGLTexture> {\n if (!ExponentGLObjectManager.createCameraTextureAsync) {\n throw new UnavailabilityError('expo-gl', 'createCameraTextureAsync');\n }\n\n const { exglCtxId } = this;\n\n if (!exglCtxId) {\n throw new Error(\"GLView's surface is not created yet!\");\n }\n\n const cameraTag = findNodeHandle(cameraRefOrHandle);\n const { exglObjId } = await ExponentGLObjectManager.createCameraTextureAsync(\n exglCtxId,\n cameraTag\n );\n return { id: exglObjId } as WebGLTexture;\n }\n\n // @docsMissing\n async destroyObjectAsync(glObject: WebGLObject): Promise<boolean> {\n if (!ExponentGLObjectManager.destroyObjectAsync) {\n throw new UnavailabilityError('expo-gl', 'destroyObjectAsync');\n }\n return await ExponentGLObjectManager.destroyObjectAsync(glObject.id);\n }\n\n /**\n * Same as static [`takeSnapshotAsync()`](#glviewtakesnapshotasyncgl-options),\n * but uses WebGL context that is associated with the view on which the method is called.\n * @param options\n */\n async takeSnapshotAsync(options: SnapshotOptions = {}): Promise<GLSnapshot> {\n if (!GLView.takeSnapshotAsync) {\n throw new UnavailabilityError('expo-gl', 'takeSnapshotAsync');\n }\n const { exglCtxId } = this;\n return await GLView.takeSnapshotAsync(exglCtxId, options);\n }\n}\n\nGLView.NativeView = NativeView;\n\nfunction unregisterGLContext(exglCtxId: number) {\n if (global.__EXGLContexts) {\n delete global.__EXGLContexts[String(exglCtxId)];\n }\n workletContextManager.unregister?.(exglCtxId);\n}\n\n// Get the GL interface from an EXGLContextId\nconst getGl = (exglCtxId: number): ExpoWebGLRenderingContext => {\n if (!global.__EXGLContexts) {\n throw new CodedError(\n 'ERR_GL_NOT_AVAILABLE',\n 'GL is currently not available. (Have you enabled remote debugging? GL is not available while debugging remotely.)'\n );\n }\n const gl = global.__EXGLContexts[String(exglCtxId)];\n\n configureLogging(gl);\n\n return gl;\n};\n\nconst getContextId = (exgl?: ExpoWebGLRenderingContext | number): number => {\n const exglCtxId = exgl && typeof exgl === 'object' ? exgl.contextId : exgl;\n\n if (!exglCtxId || typeof exglCtxId !== 'number') {\n throw new Error(`Invalid EXGLContext id: ${String(exglCtxId)}`);\n }\n return exglCtxId;\n};\n"]}
1
+ {"version":3,"file":"GLView.js","sourceRoot":"","sources":["../src/GLView.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,mBAAmB,EACnB,wBAAwB,EACxB,UAAU,GACX,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAE9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAS7C,OAAO,EAAE,2BAA2B,EAAE,MAAM,2BAA2B,CAAC;AASxE,MAAM,uBAAuB,GAAG,mBAAmB,CAAC,yBAAyB,CAAC,CAAC;AAC/E,MAAM,EAAE,qBAAqB,EAAE,GAAG,kBAAkB,CAAC;AAErD,MAAM,UAAU,GAAG,wBAAwB,CAAC,gBAAgB,CAAC,CAAC;AAC9D,MAAM,qBAAqB,GAAG,2BAA2B,EAAE,CAAC;AAE5D,cAAc;AACd;;;GAGG;AACH,MAAM,OAAO,MAAO,SAAQ,KAAK,CAAC,SAAsB;IACtD,MAAM,CAAC,UAAU,CAAM;IAEvB,MAAM,CAAC,YAAY,G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AAGH,MAAM,CAAC,UAAU,GAAG,UAAU,CAAC;AAE/B,SAAS,mBAAmB,CAAC,SAAiB;IAC5C,IAAI,MAAM,CAAC,cAAc,EAAE;QACzB,OAAO,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC;KACjD;IACD,qBAAqB,CAAC,UAAU,EAAE,CAAC,SAAS,CAAC,CAAC;AAChD,CAAC;AAED,6CAA6C;AAC7C,MAAM,KAAK,GAAG,CAAC,SAAiB,EAA6B,EAAE;IAC7D,IAAI,CAAC,MAAM,CAAC,cAAc,EAAE;QAC1B,MAAM,IAAI,UAAU,CAClB,sBAAsB,EACtB,mHAAmH,CACpH,CAAC;KACH;IACD,MAAM,EAAE,GAAG,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC;IAEpD,gBAAgB,CAAC,EAAE,CAAC,CAAC;IAErB,OAAO,EAAE,CAAC;AACZ,CAAC,CAAC;AAEF,MAAM,YAAY,GAAG,CAAC,IAAyC,EAAU,EAAE;IACzE,MAAM,SAAS,GAAG,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC;IAE3E,IAAI,CAAC,SAAS,IAAI,OAAO,SAAS,KAAK,QAAQ,EAAE;QAC/C,MAAM,IAAI,KAAK,CAAC,2BAA2B,MAAM,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;KACjE;IACD,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC","sourcesContent":["import {\n NativeModulesProxy,\n UnavailabilityError,\n requireNativeModule,\n requireNativeViewManager,\n CodedError,\n} from 'expo-modules-core';\nimport * as React from 'react';\nimport { Platform, View, findNodeHandle } from 'react-native';\n\nimport { configureLogging } from './GLUtils';\nimport {\n ComponentOrHandle,\n SurfaceCreateEvent,\n GLSnapshot,\n ExpoWebGLRenderingContext,\n SnapshotOptions,\n GLViewProps,\n} from './GLView.types';\nimport { createWorkletContextManager } from './GLWorkletContextManager';\n\n// @docsMissing\nexport type WebGLObject = {\n id: number;\n};\n\ndeclare let global: any;\n\nconst ExponentGLObjectManager = requireNativeModule('ExponentGLObjectManager');\nconst { ExponentGLViewManager } = NativeModulesProxy;\n\nconst NativeView = requireNativeViewManager('ExponentGLView');\nconst workletContextManager = createWorkletContextManager();\n\n// @needsAudit\n/**\n * A View that acts as an OpenGL ES render target. On mounting, an OpenGL ES context is created.\n * Its drawing buffer is presented as the contents of the View every frame.\n */\nexport class GLView extends React.Component<GLViewProps> {\n static NativeView: any;\n\n static defaultProps = {\n msaaSamples: 4,\n enableExperimentalWorkletSupport: false,\n };\n\n /**\n * Imperative API that creates headless context which is devoid of underlying view.\n * It's useful for headless rendering or in case you want to keep just one context per application and share it between multiple components.\n * It is slightly faster than usual context as it doesn't swap framebuffers and doesn't present them on the canvas,\n * however it may require you to take a snapshot in order to present its results.\n * Also, keep in mind that you need to set up a viewport and create your own framebuffer and texture that you will be drawing to, before you take a snapshot.\n * @return A promise that resolves to WebGL context object. See [WebGL API](#webgl-api) for more details.\n */\n static async createContextAsync(): Promise<ExpoWebGLRenderingContext> {\n const { exglCtxId } = await ExponentGLObjectManager.createContextAsync();\n return getGl(exglCtxId);\n }\n\n /**\n * Destroys given context.\n * @param exgl WebGL context to destroy.\n * @return A promise that resolves to boolean value that is `true` if given context existed and has been destroyed successfully.\n */\n static async destroyContextAsync(exgl?: ExpoWebGLRenderingContext | number): Promise<boolean> {\n const exglCtxId = getContextId(exgl);\n unregisterGLContext(exglCtxId);\n return ExponentGLObjectManager.destroyContextAsync(exglCtxId);\n }\n\n /**\n * Takes a snapshot of the framebuffer and saves it as a file to app's cache directory.\n * @param exgl WebGL context to take a snapshot from.\n * @param options\n * @return A promise that resolves to `GLSnapshot` object.\n */\n static async takeSnapshotAsync(\n exgl?: ExpoWebGLRenderingContext | number,\n options: SnapshotOptions = {}\n ): Promise<GLSnapshot> {\n const exglCtxId = getContextId(exgl);\n return ExponentGLObjectManager.takeSnapshotAsync(exglCtxId, options);\n }\n\n static getWorkletContext: (contextId: number) => ExpoWebGLRenderingContext | undefined =\n workletContextManager.getContext;\n\n nativeRef: ComponentOrHandle = null;\n exglCtxId?: number;\n\n render() {\n const {\n onContextCreate, // eslint-disable-line no-unused-vars\n msaaSamples,\n enableExperimentalWorkletSupport,\n ...viewProps\n } = this.props;\n\n return (\n <View {...viewProps}>\n <NativeView\n ref={this._setNativeRef}\n style={{\n flex: 1,\n ...(Platform.OS === 'ios'\n ? {\n backgroundColor: 'transparent',\n }\n : {}),\n }}\n onSurfaceCreate={this._onSurfaceCreate}\n enableExperimentalWorkletSupport={enableExperimentalWorkletSupport}\n msaaSamples={Platform.OS === 'ios' ? msaaSamples : undefined}\n />\n </View>\n );\n }\n\n _setNativeRef = (nativeRef: ComponentOrHandle): void => {\n if (this.props.nativeRef_EXPERIMENTAL) {\n this.props.nativeRef_EXPERIMENTAL(nativeRef);\n }\n this.nativeRef = nativeRef;\n };\n\n _onSurfaceCreate = ({ nativeEvent: { exglCtxId } }: SurfaceCreateEvent): void => {\n const gl = getGl(exglCtxId);\n\n this.exglCtxId = exglCtxId;\n\n if (this.props.onContextCreate) {\n this.props.onContextCreate(gl);\n }\n };\n\n componentWillUnmount(): void {\n if (this.exglCtxId) {\n unregisterGLContext(this.exglCtxId);\n }\n }\n\n componentDidUpdate(prevProps: GLViewProps): void {\n if (\n this.props.enableExperimentalWorkletSupport !== prevProps.enableExperimentalWorkletSupport\n ) {\n console.warn('Updating prop enableExperimentalWorkletSupport is not supported');\n }\n }\n\n // @docsMissing\n async startARSessionAsync(): Promise<any> {\n if (!ExponentGLViewManager.startARSessionAsync) {\n throw new UnavailabilityError('expo-gl', 'startARSessionAsync');\n }\n return await ExponentGLViewManager.startARSessionAsync(findNodeHandle(this.nativeRef));\n }\n\n // @docsMissing\n async createCameraTextureAsync(cameraRefOrHandle: ComponentOrHandle): Promise<WebGLTexture> {\n if (!ExponentGLObjectManager.createCameraTextureAsync) {\n throw new UnavailabilityError('expo-gl', 'createCameraTextureAsync');\n }\n\n const { exglCtxId } = this;\n\n if (!exglCtxId) {\n throw new Error(\"GLView's surface is not created yet!\");\n }\n\n const cameraTag = findNodeHandle(cameraRefOrHandle);\n const { exglObjId } = await ExponentGLObjectManager.createCameraTextureAsync(\n exglCtxId,\n cameraTag\n );\n return { id: exglObjId } as WebGLTexture;\n }\n\n // @docsMissing\n async destroyObjectAsync(glObject: WebGLObject): Promise<boolean> {\n if (!ExponentGLObjectManager.destroyObjectAsync) {\n throw new UnavailabilityError('expo-gl', 'destroyObjectAsync');\n }\n return await ExponentGLObjectManager.destroyObjectAsync(glObject.id);\n }\n\n /**\n * Same as static [`takeSnapshotAsync()`](#glviewtakesnapshotasyncgl-options),\n * but uses WebGL context that is associated with the view on which the method is called.\n * @param options\n */\n async takeSnapshotAsync(options: SnapshotOptions = {}): Promise<GLSnapshot> {\n if (!GLView.takeSnapshotAsync) {\n throw new UnavailabilityError('expo-gl', 'takeSnapshotAsync');\n }\n const { exglCtxId } = this;\n return await GLView.takeSnapshotAsync(exglCtxId, options);\n }\n}\n\nGLView.NativeView = NativeView;\n\nfunction unregisterGLContext(exglCtxId: number) {\n if (global.__EXGLContexts) {\n delete global.__EXGLContexts[String(exglCtxId)];\n }\n workletContextManager.unregister?.(exglCtxId);\n}\n\n// Get the GL interface from an EXGLContextId\nconst getGl = (exglCtxId: number): ExpoWebGLRenderingContext => {\n if (!global.__EXGLContexts) {\n throw new CodedError(\n 'ERR_GL_NOT_AVAILABLE',\n 'GL is currently not available. (Have you enabled remote debugging? GL is not available while debugging remotely.)'\n );\n }\n const gl = global.__EXGLContexts[String(exglCtxId)];\n\n configureLogging(gl);\n\n return gl;\n};\n\nconst getContextId = (exgl?: ExpoWebGLRenderingContext | number): number => {\n const exglCtxId = exgl && typeof exgl === 'object' ? exgl.contextId : exgl;\n\n if (!exglCtxId || typeof exglCtxId !== 'number') {\n throw new Error(`Invalid EXGLContext id: ${String(exglCtxId)}`);\n }\n return exglCtxId;\n};\n"]}
@@ -29,7 +29,7 @@ export type SnapshotOptions = {
29
29
  * Specifies what type of compression should be used and what is the result file extension.
30
30
  * PNG compression is lossless but slower, JPEG is faster but the image has visible artifacts.
31
31
  * > **Note:** When using WebP format, the iOS version will print a warning, and generate a `'png'` file instead.
32
- * > It is recommendable to use platform dependant code in this case. You can refer to the [documentation on platform specific code](/versions/latest/react-native/platform-specific-code).
32
+ * > It is recommended to use [platform-specific](https://reactnative.dev/docs/platform-specific-code) code in this case.
33
33
  * @default 'jpeg'
34
34
  */
35
35
  format?: 'jpeg' | 'png' | 'webp';
@@ -1 +1 @@
1
- {"version":3,"file":"GLView.types.js","sourceRoot":"","sources":["../src/GLView.types.ts"],"names":[],"mappings":"AAwGA,cAAc;AACd,MAAM,CAAN,IAAY,eA2BX;AA3BD,WAAY,eAAe;IACzB;;OAEG;IACH,6DAAY,CAAA;IACZ;;OAEG;IACH,qEAAgB,CAAA;IAChB;;;OAGG;IACH,iEAAc,CAAA;IACd;;OAEG;IACH,+EAAqB,CAAA;IACrB;;;OAGG;IACH,6EAAoB,CAAA;IACpB;;OAEG;IACH,oDAAsE,CAAA;AACxE,CAAC,EA3BW,eAAe,KAAf,eAAe,QA2B1B","sourcesContent":["import { Component, ComponentClass } from 'react';\nimport { ViewProps } from 'react-native';\n\n// @docsMissing\nexport type SurfaceCreateEvent = {\n nativeEvent: {\n exglCtxId: number;\n };\n};\n\n// @needsAudit\nexport type SnapshotOptions = {\n /**\n * Whether to flip the snapshot vertically.\n * @default false\n */\n flip?: boolean;\n /**\n * Specify the framebuffer that we will be reading from.\n * Defaults to underlying framebuffer that is presented in the view or the current framebuffer if context is headless.\n */\n framebuffer?: WebGLFramebuffer;\n /**\n * Rect to crop the snapshot. It's passed directly to `glReadPixels`.\n */\n rect?: {\n x: number;\n y: number;\n width: number;\n height: number;\n };\n /**\n * Specifies what type of compression should be used and what is the result file extension.\n * PNG compression is lossless but slower, JPEG is faster but the image has visible artifacts.\n * > **Note:** When using WebP format, the iOS version will print a warning, and generate a `'png'` file instead.\n * > It is recommendable to use platform dependant code in this case. You can refer to the [documentation on platform specific code](/versions/latest/react-native/platform-specific-code).\n * @default 'jpeg'\n */\n format?: 'jpeg' | 'png' | 'webp';\n /**\n * A value in range `0` to `1.0` specifying compression level of the result image.\n * `1.0` means no compression and `0` the highest compression.\n * @default 1.0\n */\n compress?: number;\n};\n\n// @needsAudit\nexport type GLSnapshot = {\n /**\n * URI to the snapshot.\n */\n uri: string | Blob | null;\n /**\n * Synonym for `uri`. Makes snapshot object compatible with `texImage2D`.\n */\n localUri: string;\n /**\n * Width of the snapshot.\n */\n width: number;\n /**\n * Height of the snapshot.\n */\n height: number;\n};\n\n// @docsMissing\nexport interface ExpoWebGLRenderingContext extends WebGL2RenderingContext {\n contextId: number;\n endFrameEXP(): void;\n flushEXP(): void;\n __expoSetLogging(option: GLLoggingOption): void;\n}\n\n// @docsMissing\nexport type ComponentOrHandle = null | number | Component<any, any> | ComponentClass<any>;\n\n// @needsAudit\nexport type GLViewProps = {\n /**\n * A function that will be called when the OpenGL ES context is created.\n * The function is passed a single argument `gl` that extends a [WebGLRenderingContext](https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14) interface.\n */\n onContextCreate(gl: ExpoWebGLRenderingContext): void;\n /**\n * `GLView` can enable iOS's built-in [multisampling](https://www.khronos.org/registry/OpenGL/extensions/APPLE/APPLE_framebuffer_multisample.txt).\n * This prop specifies the number of samples to use. Setting this to `0` turns off multisampling.\n * @platform ios\n * @default 4\n */\n msaaSamples: number;\n /**\n * Enables support for interacting with a `gl` object from code running on the Reanimated worklet thread.\n * @default false\n */\n enableExperimentalWorkletSupport: boolean;\n /**\n * @hidden\n * A ref callback for the native GLView\n */\n nativeRef_EXPERIMENTAL?(callback: ComponentOrHandle | null);\n} & ViewProps;\n\n// @needsAudit\nexport enum GLLoggingOption {\n /**\n * Disables logging entirely.\n */\n DISABLED = 0,\n /**\n * Logs method calls, their parameters and results.\n */\n METHOD_CALLS = 1,\n /**\n * Calls `gl.getError()` after each other method call and prints an error if any is returned.\n * This option has a significant impact on the performance as this method is blocking.\n */\n GET_ERRORS = 2,\n /**\n * Resolves parameters of type `number` to their constant names.\n */\n RESOLVE_CONSTANTS = 4,\n /**\n * When this option is enabled, long strings will be truncated.\n * It's useful if your shaders are really big and logging them significantly reduces performance.\n */\n TRUNCATE_STRINGS = 8,\n /**\n * Enables all other options. It implies `GET_ERRORS` so be aware of the slowdown.\n */\n ALL = METHOD_CALLS | GET_ERRORS | RESOLVE_CONSTANTS | TRUNCATE_STRINGS,\n}\n"]}
1
+ {"version":3,"file":"GLView.types.js","sourceRoot":"","sources":["../src/GLView.types.ts"],"names":[],"mappings":"AAwGA,cAAc;AACd,MAAM,CAAN,IAAY,eA2BX;AA3BD,WAAY,eAAe;IACzB;;OAEG;IACH,6DAAY,CAAA;IACZ;;OAEG;IACH,qEAAgB,CAAA;IAChB;;;OAGG;IACH,iEAAc,CAAA;IACd;;OAEG;IACH,+EAAqB,CAAA;IACrB;;;OAGG;IACH,6EAAoB,CAAA;IACpB;;OAEG;IACH,oDAAsE,CAAA;AACxE,CAAC,EA3BW,eAAe,KAAf,eAAe,QA2B1B","sourcesContent":["import { Component, ComponentClass } from 'react';\nimport { ViewProps } from 'react-native';\n\n// @docsMissing\nexport type SurfaceCreateEvent = {\n nativeEvent: {\n exglCtxId: number;\n };\n};\n\n// @needsAudit\nexport type SnapshotOptions = {\n /**\n * Whether to flip the snapshot vertically.\n * @default false\n */\n flip?: boolean;\n /**\n * Specify the framebuffer that we will be reading from.\n * Defaults to underlying framebuffer that is presented in the view or the current framebuffer if context is headless.\n */\n framebuffer?: WebGLFramebuffer;\n /**\n * Rect to crop the snapshot. It's passed directly to `glReadPixels`.\n */\n rect?: {\n x: number;\n y: number;\n width: number;\n height: number;\n };\n /**\n * Specifies what type of compression should be used and what is the result file extension.\n * PNG compression is lossless but slower, JPEG is faster but the image has visible artifacts.\n * > **Note:** When using WebP format, the iOS version will print a warning, and generate a `'png'` file instead.\n * > It is recommended to use [platform-specific](https://reactnative.dev/docs/platform-specific-code) code in this case.\n * @default 'jpeg'\n */\n format?: 'jpeg' | 'png' | 'webp';\n /**\n * A value in range `0` to `1.0` specifying compression level of the result image.\n * `1.0` means no compression and `0` the highest compression.\n * @default 1.0\n */\n compress?: number;\n};\n\n// @needsAudit\nexport type GLSnapshot = {\n /**\n * URI to the snapshot.\n */\n uri: string | Blob | null;\n /**\n * Synonym for `uri`. Makes snapshot object compatible with `texImage2D`.\n */\n localUri: string;\n /**\n * Width of the snapshot.\n */\n width: number;\n /**\n * Height of the snapshot.\n */\n height: number;\n};\n\n// @docsMissing\nexport interface ExpoWebGLRenderingContext extends WebGL2RenderingContext {\n contextId: number;\n endFrameEXP(): void;\n flushEXP(): void;\n __expoSetLogging(option: GLLoggingOption): void;\n}\n\n// @docsMissing\nexport type ComponentOrHandle = null | number | Component<any, any> | ComponentClass<any>;\n\n// @needsAudit\nexport type GLViewProps = {\n /**\n * A function that will be called when the OpenGL ES context is created.\n * The function is passed a single argument `gl` that extends a [WebGLRenderingContext](https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14) interface.\n */\n onContextCreate(gl: ExpoWebGLRenderingContext): void;\n /**\n * `GLView` can enable iOS's built-in [multisampling](https://www.khronos.org/registry/OpenGL/extensions/APPLE/APPLE_framebuffer_multisample.txt).\n * This prop specifies the number of samples to use. Setting this to `0` turns off multisampling.\n * @platform ios\n * @default 4\n */\n msaaSamples: number;\n /**\n * Enables support for interacting with a `gl` object from code running on the Reanimated worklet thread.\n * @default false\n */\n enableExperimentalWorkletSupport: boolean;\n /**\n * @hidden\n * A ref callback for the native GLView\n */\n nativeRef_EXPERIMENTAL?(callback: ComponentOrHandle | null);\n} & ViewProps;\n\n// @needsAudit\nexport enum GLLoggingOption {\n /**\n * Disables logging entirely.\n */\n DISABLED = 0,\n /**\n * Logs method calls, their parameters and results.\n */\n METHOD_CALLS = 1,\n /**\n * Calls `gl.getError()` after each other method call and prints an error if any is returned.\n * This option has a significant impact on the performance as this method is blocking.\n */\n GET_ERRORS = 2,\n /**\n * Resolves parameters of type `number` to their constant names.\n */\n RESOLVE_CONSTANTS = 4,\n /**\n * When this option is enabled, long strings will be truncated.\n * It's useful if your shaders are really big and logging them significantly reduces performance.\n */\n TRUNCATE_STRINGS = 8,\n /**\n * Enables all other options. It implies `GET_ERRORS` so be aware of the slowdown.\n */\n ALL = METHOD_CALLS | GET_ERRORS | RESOLVE_CONSTANTS | TRUNCATE_STRINGS,\n}\n"]}
@@ -116,7 +116,7 @@ export class GLView extends React.Component {
116
116
  const { onContextCreate, onContextRestored, onContextLost, webglContextAttributes, msaaSamples, nativeRef_EXPERIMENTAL,
117
117
  // @ts-ignore: ref does not exist
118
118
  ref, ...domProps } = this.props;
119
- return React.createElement(Canvas, { ...domProps, canvasRef: this.setCanvasRef });
119
+ return <Canvas {...domProps} canvasRef={this.setCanvasRef}/>;
120
120
  }
121
121
  componentDidUpdate(prevProps) {
122
122
  const { webglContextAttributes } = this.props;
@@ -1 +1 @@
1
- {"version":3,"file":"GLView.web.js","sourceRoot":"","sources":["../src/GLView.web.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAC9E,OAAO,SAAS,MAAM,WAAW,CAAC;AAClC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,OAAO,MAAM,MAAM,UAAU,CAAC;AAU9B,SAAS,gBAAgB,CAAC,KAIzB;IACC,IAAI,KAAK,IAAI,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,aAAa,EAAE;QACrE,MAAM,OAAO,GAAG,KAAK,CAAC,QAAQ,IAAI,KAAK,CAAC,GAAG,IAAI,EAAE,CAAC;QA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E;YAC3D,IAAI,CAAC,KAAK,CAAC,sBAAsB,CAAC,MAAM,CAAC,CAAC;SAC3C;QAED,IAAI,IAAI,CAAC,MAAM,EAAE;YACf,IAAI,CAAC,MAAM,CAAC,gBAAgB,CAAC,kBAAkB,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;YACrE,IAAI,CAAC,MAAM,CAAC,gBAAgB,CAAC,sBAAsB,EAAE,IAAI,CAAC,iBAAiB,CAAC,CAAC;YAE7E,IAAI,CAAC,YAAY,EAAE,CAAC;SACrB;IACH,CAAC,CAAC;IAEK,KAAK,CAAC,iBAAiB,CAAC,UAA2B,EAAE;QAC1D,IAAI,CAAC,MAAM,CAAC,iBAAiB,EAAE;YAC7B,MAAM,IAAI,mBAAmB,CAAC,SAAS,EAAE,mBAAmB,CAAC,CAAC;SAC/D;QAED,MAAM,EAAE,GAAG,IAAI,CAAC,oBAAoB,EAAE,CAAC;QACvC,OAAO,MAAM,MAAM,CAAC,iBAAiB,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC;IACrD,CAAC;IAEM,KAAK,CAAC,mBAAmB;QAC9B,MAAM,IAAI,mBAAmB,CAAC,QAAQ,EAAE,qBAAqB,CAAC,CAAC;IACjE,CAAC;IAEM,KAAK,CAAC,wBAAwB;QACnC,MAAM,IAAI,mBAAmB,CAAC,QAAQ,EAAE,0BAA0B,CAAC,CAAC;IACtE,CAAC;IAEM,KAAK,CAAC,kBAAkB,CAAC,QAAqB;QACnD,MAAM,IAAI,mBAAmB,CAAC,QAAQ,EAAE,oBAAoB,CAAC,CAAC;IAChE,CAAC;CACF","sourcesContent":["import { CodedError, Platform, UnavailabilityError } from 'expo-modules-core';\nimport invariant from 'invariant';\nimport * as React from 'react';\nimport { Dimensions } from 'react-native';\n\nimport Canvas from './Canvas';\nimport { WebGLObject } from './GLView';\nimport {\n GLViewProps,\n ExpoWebGLRenderingContext,\n GLSnapshot,\n SnapshotOptions,\n ComponentOrHandle,\n} from './GLView.types';\n\nfunction getImageForAsset(asset: {\n downloadAsync?: () => Promise<any>;\n uri?: string;\n localUri?: string;\n}): HTMLImageElement | any {\n if (asset != null && typeof asset === 'object' && asset.downloadAsync) {\n const dataURI = asset.localUri || asset.uri || '';\n const image = new Image();\n image.src = dataURI;\n return image;\n }\n return asset;\n}\n\nfunction isOffscreenCanvas(element: any): element is OffscreenCanvas {\n return element && typeof element.convertToBlob === 'function';\n}\n\nfunction asExpoContext(gl: ExpoWebGLRenderingContext): WebGLRenderingContext {\n gl.endFrameEXP = function glEndFrameEXP(): void {};\n\n if (!gl['_expo_texImage2D']) {\n gl['_expo_texImage2D'] = gl.texImage2D;\n gl.texImage2D = (...props: any[]): any => {\n const nextProps = [...props];\n nextProps.push(getImageForAsset(nextProps.pop()));\n return gl['_expo_texImage2D'](...nextProps);\n };\n }\n\n if (!gl['_expo_texSubImage2D']) {\n gl['_expo_texSubImage2D'] = gl.texSubImage2D;\n gl.texSubImage2D = (...props: any[]): any => {\n const nextProps = [...props];\n nextProps.push(getImageForAsset(nextProps.pop()));\n return gl['_expo_texSubImage2D'](...nextProps);\n };\n }\n\n return gl;\n}\n\nfunction ensureContext(\n canvas?: HTMLCanvasElement,\n contextAttributes?: WebGLContextAttributes\n): WebGLRenderingContext {\n if (!canvas) {\n throw new CodedError(\n 'ERR_GL_INVALID',\n 'Attempting to use the GL context before it has been created.'\n );\n }\n\n // Apple disables WebGL 2.0 and doesn't provide any way to detect if it's disabled.\n const isIOS = !!navigator.platform && /iPad|iPhone|iPod/.test(navigator.platform);\n\n const context =\n (!isIOS && canvas.getContext('webgl2', contextAttributes)) ||\n canvas.getContext('webgl', contextAttributes) ||\n canvas.getContext('webgl-experimental', contextAttributes) ||\n canvas.getContext('experimental-webgl', contextAttributes);\n invariant(context, 'Browser does not support WebGL');\n return asExpoContext(context as ExpoWebGLRenderingContext);\n}\n\n// @needsAudit @docsMissing\nexport type GLViewWebProps = GLViewProps & {\n onContextCreate: (gl: WebGLRenderingContext) => void;\n onContextRestored?: (gl?: WebGLRenderingContext) => void;\n onContextLost?: () => void;\n webglContextAttributes?: WebGLContextAttributes;\n // type overwrite\n nativeRef_EXPERIMENTAL?(callback: ComponentOrHandle | HTMLCanvasElement | null);\n};\n\nasync function getBlobFromWebGLRenderingContext(\n gl: WebGLRenderingContext,\n options: SnapshotOptions = {}\n): Promise<{ width: number; height: number; blob: Blob | null }> {\n invariant(gl, 'getBlobFromWebGLRenderingContext(): WebGL Rendering Context is not defined');\n\n const { canvas } = gl;\n\n let blob: Blob | null = null;\n\n if (typeof (canvas as any).msToBlob === 'function') {\n // @ts-ignore: polyfill: https://stackoverflow.com/a/29815058/4047926\n blob = await canvas.msToBlob();\n } else if (isOffscreenCanvas(canvas)) {\n blob = await canvas.convertToBlob({ quality: options.compress, type: options.format });\n } else {\n blob = await new Promise((resolve) => {\n canvas.toBlob((blob: Blob | null) => resolve(blob), options.format, options.compress);\n });\n }\n\n return {\n blob,\n width: canvas.width,\n height: canvas.height,\n };\n}\n\nexport class GLView extends React.Component<GLViewWebProps> {\n canvas?: HTMLCanvasElement;\n\n gl?: WebGLRenderingContext;\n\n static async createContextAsync(): Promise<WebGLRenderingContext | null> {\n if (!Platform.isDOMAvailable) {\n return null;\n }\n const canvas = document.createElement('canvas');\n const { width, height, scale } = Dimensions.get('window');\n canvas.width = width * scale;\n canvas.height = height * scale;\n return ensureContext(canvas);\n }\n\n static async destroyContextAsync(exgl?: WebGLRenderingContext | number): Promise<boolean> {\n // Do nothing\n return true;\n }\n\n static async takeSnapshotAsync(\n gl: WebGLRenderingContext,\n options: SnapshotOptions = {}\n ): Promise<GLSnapshot> {\n const { blob, width, height } = await getBlobFromWebGLRenderingContext(gl, options);\n\n if (!blob) {\n throw new CodedError('ERR_GL_SNAPSHOT', 'Failed to save the GL context');\n }\n\n return {\n uri: blob,\n localUri: '',\n width,\n height,\n };\n }\n\n componentWillUnmount() {\n if (this.gl) {\n const loseContextExt = this.gl.getExtension('WEBGL_lose_context');\n if (loseContextExt) {\n loseContextExt.loseContext();\n }\n this.gl = undefined;\n }\n if (this.canvas) {\n this.canvas.removeEventListener('webglcontextlost', this.onContextLost);\n this.canvas.removeEventListener('webglcontextrestored', this.onContextRestored);\n }\n }\n\n render() {\n const {\n onContextCreate,\n onContextRestored,\n onContextLost,\n webglContextAttributes,\n msaaSamples,\n nativeRef_EXPERIMENTAL,\n // @ts-ignore: ref does not exist\n ref,\n ...domProps\n } = this.props;\n\n return <Canvas {...domProps} canvasRef={this.setCanvasRef} />;\n }\n\n componentDidUpdate(prevProps) {\n const { webglContextAttributes } = this.props;\n if (this.canvas && webglContextAttributes !== prevProps.webglContextAttributes) {\n this.onContextLost(null);\n this.onContextRestored();\n }\n }\n\n private getGLContextOrReject(): WebGLRenderingContext {\n const gl = this.getGLContext();\n if (!gl) {\n throw new CodedError(\n 'ERR_GL_INVALID',\n 'Attempting to use the GL context before it has been created.'\n );\n }\n return gl;\n }\n\n private onContextLost = (event: Event | null): void => {\n if (event && event.preventDefault) {\n event.preventDefault();\n }\n this.gl = undefined;\n\n if (typeof this.props.onContextLost === 'function') {\n this.props.onContextLost();\n }\n };\n\n private onContextRestored = (): void => {\n this.gl = undefined;\n if (this.getGLContext() == null) {\n throw new CodedError('ERR_GL_INVALID', 'Failed to restore GL context.');\n }\n };\n\n private getGLContext(): WebGLRenderingContext | null {\n if (this.gl) return this.gl;\n\n if (this.canvas) {\n this.gl = ensureContext(this.canvas, this.props.webglContextAttributes);\n if (typeof this.props.onContextCreate === 'function') {\n this.props.onContextCreate(this.gl);\n }\n return this.gl;\n }\n return null;\n }\n\n private setCanvasRef = (canvas: HTMLCanvasElement): void => {\n this.canvas = canvas;\n\n if (typeof this.props.nativeRef_EXPERIMENTAL === 'function') {\n this.props.nativeRef_EXPERIMENTAL(canvas);\n }\n\n if (this.canvas) {\n this.canvas.addEventListener('webglcontextlost', this.onContextLost);\n this.canvas.addEventListener('webglcontextrestored', this.onContextRestored);\n\n this.getGLContext();\n }\n };\n\n public async takeSnapshotAsync(options: SnapshotOptions = {}): Promise<GLSnapshot> {\n if (!GLView.takeSnapshotAsync) {\n throw new UnavailabilityError('expo-gl', 'takeSnapshotAsync');\n }\n\n const gl = this.getGLContextOrReject();\n return await GLView.takeSnapshotAsync(gl, options);\n }\n\n public async startARSessionAsync(): Promise<void> {\n throw new UnavailabilityError('GLView', 'startARSessionAsync');\n }\n\n public async createCameraTextureAsync(): Promise<void> {\n throw new UnavailabilityError('GLView', 'createCameraTextureAsync');\n }\n\n public async destroyObjectAsync(glObject: WebGLObject): Promise<void> {\n throw new UnavailabilityError('GLView', 'destroyObjectAsync');\n }\n}\n"]}
1
+ {"version":3,"file":"GLView.web.js","sourceRoot":"","sources":["../src/GLView.web.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAC9E,OAAO,SAAS,MAAM,WAAW,CAAC;AAClC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,OAAO,MAAM,MAAM,UAAU,CAAC;AAU9B,SAAS,gBAAgB,CAAC,KAIzB;IACC,IAAI,KAAK,IAAI,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,aAAa,EAAE;QACrE,MAAM,OAAO,GAAG,KAAK,CAAC,QAAQ,IAAI,KAAK,CAAC,GAAG,IAAI,EAAE,CAAC;QAClD,MAAM,KAAK,GAAG,IAAI,KAAK,EAAE,CAAC;QAC1B,KAAK,CAAC,GAAG,GAAG,OAAO,CAAC;QACpB,OAAO,KAAK,CAAC;KACd;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,iBAAiB,CAAC,OAAY;IACrC,OAAO,OAAO,IAAI,OAAO,OAAO,CAAC,aAAa,KAAK,UAAU,CAAC;AAChE,CAAC;AAED,SAAS,aAAa,CAAC,EAA6B;IAClD,EAAE,CAAC,WAA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E7E,IAAI,CAAC,YAAY,EAAE,CAAC;SACrB;IACH,CAAC,CAAC;IAEK,KAAK,CAAC,iBAAiB,CAAC,UAA2B,EAAE;QAC1D,IAAI,CAAC,MAAM,CAAC,iBAAiB,EAAE;YAC7B,MAAM,IAAI,mBAAmB,CAAC,SAAS,EAAE,mBAAmB,CAAC,CAAC;SAC/D;QAED,MAAM,EAAE,GAAG,IAAI,CAAC,oBAAoB,EAAE,CAAC;QACvC,OAAO,MAAM,MAAM,CAAC,iBAAiB,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC;IACrD,CAAC;IAEM,KAAK,CAAC,mBAAmB;QAC9B,MAAM,IAAI,mBAAmB,CAAC,QAAQ,EAAE,qBAAqB,CAAC,CAAC;IACjE,CAAC;IAEM,KAAK,CAAC,wBAAwB;QACnC,MAAM,IAAI,mBAAmB,CAAC,QAAQ,EAAE,0BAA0B,CAAC,CAAC;IACtE,CAAC;IAEM,KAAK,CAAC,kBAAkB,CAAC,QAAqB;QACnD,MAAM,IAAI,mBAAmB,CAAC,QAAQ,EAAE,oBAAoB,CAAC,CAAC;IAChE,CAAC;CACF","sourcesContent":["import { CodedError, Platform, UnavailabilityError } from 'expo-modules-core';\nimport invariant from 'invariant';\nimport * as React from 'react';\nimport { Dimensions } from 'react-native';\n\nimport Canvas from './Canvas';\nimport { WebGLObject } from './GLView';\nimport {\n GLViewProps,\n ExpoWebGLRenderingContext,\n GLSnapshot,\n SnapshotOptions,\n ComponentOrHandle,\n} from './GLView.types';\n\nfunction getImageForAsset(asset: {\n downloadAsync?: () => Promise<any>;\n uri?: string;\n localUri?: string;\n}): HTMLImageElement | any {\n if (asset != null && typeof asset === 'object' && asset.downloadAsync) {\n const dataURI = asset.localUri || asset.uri || '';\n const image = new Image();\n image.src = dataURI;\n return image;\n }\n return asset;\n}\n\nfunction isOffscreenCanvas(element: any): element is OffscreenCanvas {\n return element && typeof element.convertToBlob === 'function';\n}\n\nfunction asExpoContext(gl: ExpoWebGLRenderingContext): WebGLRenderingContext {\n gl.endFrameEXP = function glEndFrameEXP(): void {};\n\n if (!gl['_expo_texImage2D']) {\n gl['_expo_texImage2D'] = gl.texImage2D;\n gl.texImage2D = (...props: any[]): any => {\n const nextProps = [...props];\n nextProps.push(getImageForAsset(nextProps.pop()));\n return gl['_expo_texImage2D'](...nextProps);\n };\n }\n\n if (!gl['_expo_texSubImage2D']) {\n gl['_expo_texSubImage2D'] = gl.texSubImage2D;\n gl.texSubImage2D = (...props: any[]): any => {\n const nextProps = [...props];\n nextProps.push(getImageForAsset(nextProps.pop()));\n return gl['_expo_texSubImage2D'](...nextProps);\n };\n }\n\n return gl;\n}\n\nfunction ensureContext(\n canvas?: HTMLCanvasElement,\n contextAttributes?: WebGLContextAttributes\n): WebGLRenderingContext {\n if (!canvas) {\n throw new CodedError(\n 'ERR_GL_INVALID',\n 'Attempting to use the GL context before it has been created.'\n );\n }\n\n // Apple disables WebGL 2.0 and doesn't provide any way to detect if it's disabled.\n const isIOS = !!navigator.platform && /iPad|iPhone|iPod/.test(navigator.platform);\n\n const context =\n (!isIOS && canvas.getContext('webgl2', contextAttributes)) ||\n canvas.getContext('webgl', contextAttributes) ||\n canvas.getContext('webgl-experimental', contextAttributes) ||\n canvas.getContext('experimental-webgl', contextAttributes);\n invariant(context, 'Browser does not support WebGL');\n return asExpoContext(context as ExpoWebGLRenderingContext);\n}\n\n// @needsAudit @docsMissing\nexport type GLViewWebProps = GLViewProps & {\n onContextCreate: (gl: WebGLRenderingContext) => void;\n onContextRestored?: (gl?: WebGLRenderingContext) => void;\n onContextLost?: () => void;\n webglContextAttributes?: WebGLContextAttributes;\n // type overwrite\n nativeRef_EXPERIMENTAL?(callback: ComponentOrHandle | HTMLCanvasElement | null);\n};\n\nasync function getBlobFromWebGLRenderingContext(\n gl: WebGLRenderingContext,\n options: SnapshotOptions = {}\n): Promise<{ width: number; height: number; blob: Blob | null }> {\n invariant(gl, 'getBlobFromWebGLRenderingContext(): WebGL Rendering Context is not defined');\n\n const { canvas } = gl;\n\n let blob: Blob | null = null;\n\n if (typeof (canvas as any).msToBlob === 'function') {\n // @ts-ignore: polyfill: https://stackoverflow.com/a/29815058/4047926\n blob = await canvas.msToBlob();\n } else if (isOffscreenCanvas(canvas)) {\n blob = await canvas.convertToBlob({ quality: options.compress, type: options.format });\n } else {\n blob = await new Promise((resolve) => {\n canvas.toBlob((blob: Blob | null) => resolve(blob), options.format, options.compress);\n });\n }\n\n return {\n blob,\n width: canvas.width,\n height: canvas.height,\n };\n}\n\nexport class GLView extends React.Component<GLViewWebProps> {\n canvas?: HTMLCanvasElement;\n\n gl?: WebGLRenderingContext;\n\n static async createContextAsync(): Promise<WebGLRenderingContext | null> {\n if (!Platform.isDOMAvailable) {\n return null;\n }\n const canvas = document.createElement('canvas');\n const { width, height, scale } = Dimensions.get('window');\n canvas.width = width * scale;\n canvas.height = height * scale;\n return ensureContext(canvas);\n }\n\n static async destroyContextAsync(exgl?: WebGLRenderingContext | number): Promise<boolean> {\n // Do nothing\n return true;\n }\n\n static async takeSnapshotAsync(\n gl: WebGLRenderingContext,\n options: SnapshotOptions = {}\n ): Promise<GLSnapshot> {\n const { blob, width, height } = await getBlobFromWebGLRenderingContext(gl, options);\n\n if (!blob) {\n throw new CodedError('ERR_GL_SNAPSHOT', 'Failed to save the GL context');\n }\n\n return {\n uri: blob,\n localUri: '',\n width,\n height,\n };\n }\n\n componentWillUnmount() {\n if (this.gl) {\n const loseContextExt = this.gl.getExtension('WEBGL_lose_context');\n if (loseContextExt) {\n loseContextExt.loseContext();\n }\n this.gl = undefined;\n }\n if (this.canvas) {\n this.canvas.removeEventListener('webglcontextlost', this.onContextLost);\n this.canvas.removeEventListener('webglcontextrestored', this.onContextRestored);\n }\n }\n\n render() {\n const {\n onContextCreate,\n onContextRestored,\n onContextLost,\n webglContextAttributes,\n msaaSamples,\n nativeRef_EXPERIMENTAL,\n // @ts-ignore: ref does not exist\n ref,\n ...domProps\n } = this.props;\n\n return <Canvas {...domProps} canvasRef={this.setCanvasRef} />;\n }\n\n componentDidUpdate(prevProps) {\n const { webglContextAttributes } = this.props;\n if (this.canvas && webglContextAttributes !== prevProps.webglContextAttributes) {\n this.onContextLost(null);\n this.onContextRestored();\n }\n }\n\n private getGLContextOrReject(): WebGLRenderingContext {\n const gl = this.getGLContext();\n if (!gl) {\n throw new CodedError(\n 'ERR_GL_INVALID',\n 'Attempting to use the GL context before it has been created.'\n );\n }\n return gl;\n }\n\n private onContextLost = (event: Event | null): void => {\n if (event && event.preventDefault) {\n event.preventDefault();\n }\n this.gl = undefined;\n\n if (typeof this.props.onContextLost === 'function') {\n this.props.onContextLost();\n }\n };\n\n private onContextRestored = (): void => {\n this.gl = undefined;\n if (this.getGLContext() == null) {\n throw new CodedError('ERR_GL_INVALID', 'Failed to restore GL context.');\n }\n };\n\n private getGLContext(): WebGLRenderingContext | null {\n if (this.gl) return this.gl;\n\n if (this.canvas) {\n this.gl = ensureContext(this.canvas, this.props.webglContextAttributes);\n if (typeof this.props.onContextCreate === 'function') {\n this.props.onContextCreate(this.gl);\n }\n return this.gl;\n }\n return null;\n }\n\n private setCanvasRef = (canvas: HTMLCanvasElement): void => {\n this.canvas = canvas;\n\n if (typeof this.props.nativeRef_EXPERIMENTAL === 'function') {\n this.props.nativeRef_EXPERIMENTAL(canvas);\n }\n\n if (this.canvas) {\n this.canvas.addEventListener('webglcontextlost', this.onContextLost);\n this.canvas.addEventListener('webglcontextrestored', this.onContextRestored);\n\n this.getGLContext();\n }\n };\n\n public async takeSnapshotAsync(options: SnapshotOptions = {}): Promise<GLSnapshot> {\n if (!GLView.takeSnapshotAsync) {\n throw new UnavailabilityError('expo-gl', 'takeSnapshotAsync');\n }\n\n const gl = this.getGLContextOrReject();\n return await GLView.takeSnapshotAsync(gl, options);\n }\n\n public async startARSessionAsync(): Promise<void> {\n throw new UnavailabilityError('GLView', 'startARSessionAsync');\n }\n\n public async createCameraTextureAsync(): Promise<void> {\n throw new UnavailabilityError('GLView', 'createCameraTextureAsync');\n }\n\n public async destroyObjectAsync(glObject: WebGLObject): Promise<void> {\n throw new UnavailabilityError('GLView', 'destroyObjectAsync');\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expo-gl",
3
- "version": "13.2.0",
3
+ "version": "13.4.0",
4
4
  "description": "Provides GLView that acts as OpenGL ES render target and gives GL context object implementing WebGL 2.0 specification.",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -49,5 +49,5 @@
49
49
  "peerDependencies": {
50
50
  "expo": "*"
51
51
  },
52
- "gitHead": "79607a7325f47aa17c36d266100d09a4ff2cc544"
52
+ "gitHead": "da25937e2a99661cbe5eb60ca1d8d6245fc96a50"
53
53
  }
@@ -33,7 +33,7 @@ export type SnapshotOptions = {
33
33
  * Specifies what type of compression should be used and what is the result file extension.
34
34
  * PNG compression is lossless but slower, JPEG is faster but the image has visible artifacts.
35
35
  * > **Note:** When using WebP format, the iOS version will print a warning, and generate a `'png'` file instead.
36
- * > It is recommendable to use platform dependant code in this case. You can refer to the [documentation on platform specific code](/versions/latest/react-native/platform-specific-code).
36
+ * > It is recommended to use [platform-specific](https://reactnative.dev/docs/platform-specific-code) code in this case.
37
37
  * @default 'jpeg'
38
38
  */
39
39
  format?: 'jpeg' | 'png' | 'webp';