Skip to content
This repository was archived by the owner on Nov 24, 2022. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 34 additions & 14 deletions lib/components/Signature.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//@flow
import React from 'react';
import { GLView } from 'expo-gl';
import { PanResponder, PixelRatio } from 'react-native';
import { Platform, PanResponder, PixelRatio } from 'react-native';
import { vec2 } from 'gl-matrix';

import PIXI from '../Pixi';
Expand Down Expand Up @@ -41,7 +41,7 @@ export default class Signature extends React.Component<Props> {
this._setupPanResponder();
}

componentWillMount() {
UNSAFE_componentWillMount() {
global.__ExpoSignatureId++;
}

Expand Down Expand Up @@ -127,8 +127,12 @@ export default class Signature extends React.Component<Props> {
return null;
};

takeSnapshotAsync = (...args) => {
return takeSnapshotAsync(this.glView, ...args);
takeSnapshotAsync = async (...args) => {
if (Platform.OS === "web") {
this.renderer._update();
return await GLView.takeSnapshotAsync(this.context, ...args);
}
return await takeSnapshotAsync(this.glView, ...args);
};

onContextCreate = async (context: WebGLRenderingContext) => {
Expand All @@ -138,7 +142,10 @@ export default class Signature extends React.Component<Props> {
this.stage = new PIXI.Container();
this.stage.addChild(this.graphicsTmp);

const getAttributes = context.getContextAttributes || (() => ({}));
const getAttributes = (Platform.OS === 'web') ?
(() => ({})) :
context.getContextAttributes || (() => ({}));

context.getContextAttributes = () => {
const contextAttributes = getAttributes();
return {
Expand Down Expand Up @@ -182,15 +189,28 @@ export default class Signature extends React.Component<Props> {
};

render() {
if (Platform.OS === 'web') {
const glView = (
<GLView
{...this.panResponder.panHandlers}
onLayout={this.onLayout}
key={'Expo.Signature-' + global.__ExpoSignatureId}
{...this.props}
onContextCreate={this.onContextCreate}
/>
);
this.setRef(glView);
return glView;
}
return (
<GLView
{...this.panResponder.panHandlers}
onLayout={this.onLayout}
key={'Expo.Signature-' + global.__ExpoSignatureId}
ref={this.setRef}
{...this.props}
onContextCreate={this.onContextCreate}
/>
);
<GLView
{...this.panResponder.panHandlers}
onLayout={this.onLayout}
ref={this.setRef}
key={'Expo.Signature-' + global.__ExpoSignatureId}
{...this.props}
onContextCreate={this.onContextCreate}
/>
)
}
}