From 003d6944ba16b62f94b2e2b67037bf4295fb8098 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Renaudeau?= Date: Tue, 16 Feb 2016 22:46:58 +0100 Subject: [PATCH] replace opaque by backgroundColor props --- .../java/com/projectseptember/RNGL/GLCanvas.java | 11 +++++++---- .../projectseptember/RNGL/GLCanvasManager.java | 5 ----- example/src/AdvancedEffects/Banner.js | 2 +- example/src/AdvancedEffects/Transition.js | 2 +- example/src/AdvancedEffects/Vignette.js | 2 +- example/src/Simple/index.js | 2 +- example/src/Tests/TransparentNonPremultiplied.js | 2 +- example/src/Tests/index.js | 6 +++--- ios/GLCanvas.h | 1 - ios/GLCanvas.m | 16 ++++++---------- ios/GLCanvasManager.m | 1 - 11 files changed, 21 insertions(+), 29 deletions(-) diff --git a/android/src/main/java/com/projectseptember/RNGL/GLCanvas.java b/android/src/main/java/com/projectseptember/RNGL/GLCanvas.java index 2eb9cc1..ae36001 100644 --- a/android/src/main/java/com/projectseptember/RNGL/GLCanvas.java +++ b/android/src/main/java/com/projectseptember/RNGL/GLCanvas.java @@ -3,6 +3,7 @@ package com.projectseptember.RNGL; import static android.opengl.GLES20.*; import android.graphics.Bitmap; +import android.graphics.Color; import android.graphics.Matrix; import android.graphics.PixelFormat; import android.net.Uri; @@ -262,12 +263,14 @@ public class GLCanvas extends GLSurfaceView } } - public void setOpaque(boolean opaque) { - if (opaque) { - this.getHolder().setFormat(PixelFormat.RGB_888); + @Override + public void setBackgroundColor(int color) { + super.setBackgroundColor(color); + if (color == Color.TRANSPARENT) { + this.getHolder().setFormat(PixelFormat.TRANSLUCENT); } else { - this.getHolder().setFormat(PixelFormat.TRANSLUCENT); + this.getHolder().setFormat(PixelFormat.RGB_888); } this.requestRender(); } diff --git a/android/src/main/java/com/projectseptember/RNGL/GLCanvasManager.java b/android/src/main/java/com/projectseptember/RNGL/GLCanvasManager.java index 734c9b3..b5265e3 100644 --- a/android/src/main/java/com/projectseptember/RNGL/GLCanvasManager.java +++ b/android/src/main/java/com/projectseptember/RNGL/GLCanvasManager.java @@ -42,11 +42,6 @@ public class GLCanvasManager extends SimpleViewManager { view.setRenderId(renderId); } - @ReactProp(name="opaque") - public void setOpaque (GLCanvas view, boolean opaque) { - view.setOpaque(opaque); - } - @ReactProp(name = "autoRedraw") public void setAutoRedraw (GLCanvas view, boolean autoRedraw) { view.setAutoRedraw(autoRedraw); diff --git a/example/src/AdvancedEffects/Banner.js b/example/src/AdvancedEffects/Banner.js index b442f6c..5eab1b6 100644 --- a/example/src/AdvancedEffects/Banner.js +++ b/example/src/AdvancedEffects/Banner.js @@ -27,7 +27,7 @@ void main( void ) { class Banner extends React.Component { render () { const { width, height, time } = this.props; - return console.log("Banner onLoad")} onProgress={e => console.log("Banner onProgress", e.nativeEvent)}> diff --git a/example/src/AdvancedEffects/Transition.js b/example/src/AdvancedEffects/Transition.js index dd89ad5..adb7043 100644 --- a/example/src/AdvancedEffects/Transition.js +++ b/example/src/AdvancedEffects/Transition.js @@ -9,7 +9,7 @@ module.exports = GL.createComponent( shader={shader} width={width} height={height} - opaque={false} + backgroundColor="transparent" uniforms={{ progress, from, diff --git a/example/src/AdvancedEffects/Vignette.js b/example/src/AdvancedEffects/Vignette.js index 9340108..8539830 100644 --- a/example/src/AdvancedEffects/Vignette.js +++ b/example/src/AdvancedEffects/Vignette.js @@ -59,7 +59,7 @@ class Vignette extends React.Component { return true} onMoveShouldSetResponder={() => true} diff --git a/example/src/Simple/index.js b/example/src/Simple/index.js index 29f9d22..471a2bf 100644 --- a/example/src/Simple/index.js +++ b/example/src/Simple/index.js @@ -205,7 +205,7 @@ class Simple extends Component { /> - + diff --git a/example/src/Tests/TransparentNonPremultiplied.js b/example/src/Tests/TransparentNonPremultiplied.js index 5bc8110..39518a6 100644 --- a/example/src/Tests/TransparentNonPremultiplied.js +++ b/example/src/Tests/TransparentNonPremultiplied.js @@ -20,7 +20,7 @@ module.exports = GL.createComponent( ({ children: t, ...rest }) => , diff --git a/example/src/Tests/index.js b/example/src/Tests/index.js index e136f33..d6d1086 100644 --- a/example/src/Tests/index.js +++ b/example/src/Tests/index.js @@ -94,7 +94,7 @@ class Tests extends React.Component { - + @@ -109,7 +109,7 @@ class Tests extends React.Component { - + http://i.imgur.com/mp79p5T.png @@ -121,7 +121,7 @@ class Tests extends React.Component { - + http://i.imgur.com/mp79p5T.png diff --git a/ios/GLCanvas.h b/ios/GLCanvas.h index 9084b4b..69faeee 100644 --- a/ios/GLCanvas.h +++ b/ios/GLCanvas.h @@ -6,7 +6,6 @@ @interface GLCanvas: GLKView @property (nonatomic) GLData *data; -@property (nonatomic) BOOL opaque; @property (nonatomic) BOOL autoRedraw; @property (nonatomic) BOOL eventsThrough; @property (nonatomic) BOOL visibleContent; diff --git a/ios/GLCanvas.m b/ios/GLCanvas.m index e2607be..ad769f9 100644 --- a/ios/GLCanvas.m +++ b/ios/GLCanvas.m @@ -47,8 +47,6 @@ NSArray* diff (NSArray* a, NSArray* b) { NSArray *_contentTextures; 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) GLint defaultFBO; @@ -117,12 +115,6 @@ RCT_NOT_IMPLEMENTED(-init) [self requestSyncData]; } -- (void)setOpaque:(BOOL)opaque -{ - _opaque = opaque; - [self setNeedsDisplay]; -} - - (void)setRenderId:(NSNumber *)renderId { if ([_nbContentTextures intValue] > 0) { @@ -180,6 +172,12 @@ RCT_NOT_IMPLEMENTED(-init) _nbContentTextures = nbContentTextures; } +- (void)setBackgroundColor:(UIColor *)backgroundColor +{ + CGFloat alpha = CGColorGetAlpha(backgroundColor.CGColor); + self.opaque = (alpha == 1.0); +} + //// Sync methods (called from props setters) - (void)requestSyncData @@ -379,8 +377,6 @@ RCT_NOT_IMPLEMENTED(-init) - (void)drawRect:(CGRect)rect { - self.layer.opaque = _opaque; - if (_neverRendered) { _neverRendered = false; glClearColor(0.0, 0.0, 0.0, 0.0); diff --git a/ios/GLCanvasManager.m b/ios/GLCanvasManager.m index c2fd5d6..d9b2045 100644 --- a/ios/GLCanvasManager.m +++ b/ios/GLCanvasManager.m @@ -24,7 +24,6 @@ RCT_EXPORT_MODULE(); } RCT_EXPORT_VIEW_PROPERTY(nbContentTextures, NSNumber); -RCT_EXPORT_VIEW_PROPERTY(opaque, BOOL); RCT_EXPORT_VIEW_PROPERTY(autoRedraw, BOOL); RCT_EXPORT_VIEW_PROPERTY(data, GLData); RCT_EXPORT_VIEW_PROPERTY(renderId, NSNumber); -- 2.26.2