Commit 003d6944 authored by Gaëtan Renaudeau's avatar Gaëtan Renaudeau

replace opaque by backgroundColor props

parent 42baa42e
...@@ -3,6 +3,7 @@ package com.projectseptember.RNGL; ...@@ -3,6 +3,7 @@ package com.projectseptember.RNGL;
import static android.opengl.GLES20.*; import static android.opengl.GLES20.*;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.Matrix; import android.graphics.Matrix;
import android.graphics.PixelFormat; import android.graphics.PixelFormat;
import android.net.Uri; import android.net.Uri;
...@@ -262,12 +263,14 @@ public class GLCanvas extends GLSurfaceView ...@@ -262,12 +263,14 @@ public class GLCanvas extends GLSurfaceView
} }
} }
public void setOpaque(boolean opaque) { @Override
if (opaque) { public void setBackgroundColor(int color) {
this.getHolder().setFormat(PixelFormat.RGB_888); super.setBackgroundColor(color);
if (color == Color.TRANSPARENT) {
this.getHolder().setFormat(PixelFormat.TRANSLUCENT);
} }
else { else {
this.getHolder().setFormat(PixelFormat.TRANSLUCENT); this.getHolder().setFormat(PixelFormat.RGB_888);
} }
this.requestRender(); this.requestRender();
} }
......
...@@ -42,11 +42,6 @@ public class GLCanvasManager extends SimpleViewManager<GLCanvas> { ...@@ -42,11 +42,6 @@ public class GLCanvasManager extends SimpleViewManager<GLCanvas> {
view.setRenderId(renderId); view.setRenderId(renderId);
} }
@ReactProp(name="opaque")
public void setOpaque (GLCanvas view, boolean opaque) {
view.setOpaque(opaque);
}
@ReactProp(name = "autoRedraw") @ReactProp(name = "autoRedraw")
public void setAutoRedraw (GLCanvas view, boolean autoRedraw) { public void setAutoRedraw (GLCanvas view, boolean autoRedraw) {
view.setAutoRedraw(autoRedraw); view.setAutoRedraw(autoRedraw);
......
...@@ -27,7 +27,7 @@ void main( void ) { ...@@ -27,7 +27,7 @@ void main( void ) {
class Banner extends React.Component { class Banner extends React.Component {
render () { render () {
const { width, height, time } = this.props; const { width, height, time } = this.props;
return <Surface width={width} height={height} opaque={false} return <Surface width={width} height={height} backgroundColor="transparent"
onLoad={() => console.log("Banner onLoad")} onLoad={() => console.log("Banner onLoad")}
onProgress={e => console.log("Banner onProgress", e.nativeEvent)}> onProgress={e => console.log("Banner onProgress", e.nativeEvent)}>
<GL.Node shader={shaders.banner} uniforms={{ time }} /> <GL.Node shader={shaders.banner} uniforms={{ time }} />
......
...@@ -9,7 +9,7 @@ module.exports = GL.createComponent( ...@@ -9,7 +9,7 @@ module.exports = GL.createComponent(
shader={shader} shader={shader}
width={width} width={width}
height={height} height={height}
opaque={false} backgroundColor="transparent"
uniforms={{ uniforms={{
progress, progress,
from, from,
......
...@@ -59,7 +59,7 @@ class Vignette extends React.Component { ...@@ -59,7 +59,7 @@ class Vignette extends React.Component {
return <Surface return <Surface
width={width} width={width}
height={height} height={height}
opaque={false} backgroundColor="transparent"
preload preload
onStartShouldSetResponder={() => true} onStartShouldSetResponder={() => true}
onMoveShouldSetResponder={() => true} onMoveShouldSetResponder={() => true}
......
...@@ -205,7 +205,7 @@ class Simple extends Component { ...@@ -205,7 +205,7 @@ class Simple extends Component {
/> />
</TouchableOpacity> </TouchableOpacity>
<View pointerEvents="box-none" style={{ position: "absolute", top: 0, left: 0, backgroundColor: "transparent" }}> <View pointerEvents="box-none" style={{ position: "absolute", top: 0, left: 0, backgroundColor: "transparent" }}>
<Surface width={256} height={180} opaque={false} eventsThrough> <Surface width={256} height={180} backgroundColor="transparent" eventsThrough>
<PieProgress progress={progress} /> <PieProgress progress={progress} />
</Surface> </Surface>
</View> </View>
......
...@@ -20,7 +20,7 @@ module.exports = GL.createComponent( ...@@ -20,7 +20,7 @@ module.exports = GL.createComponent(
({ children: t, ...rest }) => ({ children: t, ...rest }) =>
<GL.Node <GL.Node
{...rest} {...rest}
opaque={false} backgroundColor="transparent"
shader={shaders.TransparentNonPremultiplied} shader={shaders.TransparentNonPremultiplied}
uniforms={{ t }} uniforms={{ t }}
/>, />,
......
...@@ -94,7 +94,7 @@ class Tests extends React.Component { ...@@ -94,7 +94,7 @@ class Tests extends React.Component {
<NativeLayer width={debugSize} height={debugSize}> <NativeLayer width={debugSize} height={debugSize}>
<Image source={{ uri: "http://i.imgur.com/S22HNaU.png" }} width={debugSize} height={debugSize} /> <Image source={{ uri: "http://i.imgur.com/S22HNaU.png" }} width={debugSize} height={debugSize} />
<Surface width={debugSize} height={debugSize} opaque={false}> <Surface width={debugSize} height={debugSize} backgroundColor="transparent">
<Copy last> <Copy last>
<Copy> <Copy>
<Copy> <Copy>
...@@ -109,7 +109,7 @@ class Tests extends React.Component { ...@@ -109,7 +109,7 @@ class Tests extends React.Component {
<NativeLayer width={debugSize} height={debugSize}> <NativeLayer width={debugSize} height={debugSize}>
<Image source={{ uri: "http://i.imgur.com/S22HNaU.png" }} width={debugSize} height={debugSize} /> <Image source={{ uri: "http://i.imgur.com/S22HNaU.png" }} width={debugSize} height={debugSize} />
<Surface width={debugSize} height={debugSize} opaque={false}> <Surface width={debugSize} height={debugSize} backgroundColor="transparent">
<Layer> <Layer>
http://i.imgur.com/mp79p5T.png http://i.imgur.com/mp79p5T.png
<TransparentNonPremultiplied> <TransparentNonPremultiplied>
...@@ -121,7 +121,7 @@ class Tests extends React.Component { ...@@ -121,7 +121,7 @@ class Tests extends React.Component {
<NativeLayer width={debugSize} height={debugSize}> <NativeLayer width={debugSize} height={debugSize}>
<Image source={{ uri: "http://i.imgur.com/S22HNaU.png" }} width={debugSize} height={debugSize} /> <Image source={{ uri: "http://i.imgur.com/S22HNaU.png" }} width={debugSize} height={debugSize} />
<Surface width={debugSize} height={debugSize} opaque={false}> <Surface width={debugSize} height={debugSize} backgroundColor="transparent">
<Layer> <Layer>
http://i.imgur.com/mp79p5T.png http://i.imgur.com/mp79p5T.png
<TransparentNonPremultiplied> <TransparentNonPremultiplied>
......
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
@interface GLCanvas: GLKView @interface GLCanvas: GLKView
@property (nonatomic) GLData *data; @property (nonatomic) GLData *data;
@property (nonatomic) BOOL opaque;
@property (nonatomic) BOOL autoRedraw; @property (nonatomic) BOOL autoRedraw;
@property (nonatomic) BOOL eventsThrough; @property (nonatomic) BOOL eventsThrough;
@property (nonatomic) BOOL visibleContent; @property (nonatomic) BOOL visibleContent;
......
...@@ -47,8 +47,6 @@ NSArray* diff (NSArray* a, NSArray* b) { ...@@ -47,8 +47,6 @@ NSArray* diff (NSArray* a, NSArray* b) {
NSArray *_contentTextures; NSArray *_contentTextures;
NSDictionary *_images; // This caches the currently used images (imageSrc -> GLReactImage) NSDictionary *_images; // This caches the currently used images (imageSrc -> GLReactImage)
BOOL _opaque; // opaque prop (if false, the GLCanvas will become transparent)
BOOL _deferredRendering; // This flag indicates a render has been deferred to the next frame (when using contents) BOOL _deferredRendering; // This flag indicates a render has been deferred to the next frame (when using contents)
GLint defaultFBO; GLint defaultFBO;
...@@ -117,12 +115,6 @@ RCT_NOT_IMPLEMENTED(-init) ...@@ -117,12 +115,6 @@ RCT_NOT_IMPLEMENTED(-init)
[self requestSyncData]; [self requestSyncData];
} }
- (void)setOpaque:(BOOL)opaque
{
_opaque = opaque;
[self setNeedsDisplay];
}
- (void)setRenderId:(NSNumber *)renderId - (void)setRenderId:(NSNumber *)renderId
{ {
if ([_nbContentTextures intValue] > 0) { if ([_nbContentTextures intValue] > 0) {
...@@ -180,6 +172,12 @@ RCT_NOT_IMPLEMENTED(-init) ...@@ -180,6 +172,12 @@ RCT_NOT_IMPLEMENTED(-init)
_nbContentTextures = nbContentTextures; _nbContentTextures = nbContentTextures;
} }
- (void)setBackgroundColor:(UIColor *)backgroundColor
{
CGFloat alpha = CGColorGetAlpha(backgroundColor.CGColor);
self.opaque = (alpha == 1.0);
}
//// Sync methods (called from props setters) //// Sync methods (called from props setters)
- (void)requestSyncData - (void)requestSyncData
...@@ -379,8 +377,6 @@ RCT_NOT_IMPLEMENTED(-init) ...@@ -379,8 +377,6 @@ RCT_NOT_IMPLEMENTED(-init)
- (void)drawRect:(CGRect)rect - (void)drawRect:(CGRect)rect
{ {
self.layer.opaque = _opaque;
if (_neverRendered) { if (_neverRendered) {
_neverRendered = false; _neverRendered = false;
glClearColor(0.0, 0.0, 0.0, 0.0); glClearColor(0.0, 0.0, 0.0, 0.0);
......
...@@ -24,7 +24,6 @@ RCT_EXPORT_MODULE(); ...@@ -24,7 +24,6 @@ RCT_EXPORT_MODULE();
} }
RCT_EXPORT_VIEW_PROPERTY(nbContentTextures, NSNumber); RCT_EXPORT_VIEW_PROPERTY(nbContentTextures, NSNumber);
RCT_EXPORT_VIEW_PROPERTY(opaque, BOOL);
RCT_EXPORT_VIEW_PROPERTY(autoRedraw, BOOL); RCT_EXPORT_VIEW_PROPERTY(autoRedraw, BOOL);
RCT_EXPORT_VIEW_PROPERTY(data, GLData); RCT_EXPORT_VIEW_PROPERTY(data, GLData);
RCT_EXPORT_VIEW_PROPERTY(renderId, NSNumber); RCT_EXPORT_VIEW_PROPERTY(renderId, NSNumber);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment