Skip to content

Commit

Permalink
Add tint color for iOS
Browse files Browse the repository at this point in the history
The tint color can be used with a texture to tint the texture, or alone
to set a flat color for the model if no texture property is specified.
The tint property has to be a javascript object of the following format:
{r: 1.0, g: 1.0, b: 1.0, a: 1.0}.
  • Loading branch information
PatriceVignola committed Apr 3, 2018
1 parent d5f9af4 commit 55d1130
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ GLModelView.propTypes = {

model: PropTypes.string.isRequired,
texture: PropTypes.string,
tint: PropTypes.object,

rotateX: PropTypes.number,
rotateY: PropTypes.number,
Expand Down
2 changes: 1 addition & 1 deletion ios/RNGLModelView.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ - (void)didMoveToWindow
[super didMoveToWindow];

// Setup GLViewModel
self.blendColor = nil;
//self.blendColor = [UIColor colorWithRed:1.0 green:0.0 blue:0.0 alpha:1.0];

if (self.window) {
// Render with our applied props!
Expand Down
13 changes: 13 additions & 0 deletions ios/RNGLModelViewManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,19 @@ - (UIView *)view
view.texture = [GLImage imageNamed:[RCTConvert NSString:json]];
}

RCT_CUSTOM_VIEW_PROPERTY(tint, NSDictionary, RNGLModelView)
{
NSDictionary *tint = [RCTConvert NSDictionary:json];

// If the alpha is not specified, we assume that the user wants a fully opaque object
float alpha = [tint objectForKey:@"a"] == nil ? 1.0 : [[tint valueForKey:@"a"] floatValue];
float red = [[tint valueForKey:@"r"] floatValue];
float green = [[tint valueForKey:@"g"] floatValue];
float blue = [[tint valueForKey:@"b"] floatValue];

view.blendColor = [UIColor colorWithRed:red green:green blue:blue alpha:alpha];
}

// Starts or stops the animation loop to automatically re-render each 1/60 second
RCT_CUSTOM_VIEW_PROPERTY(animate, BOOL, RNGLModelView)
{
Expand Down

0 comments on commit 55d1130

Please sign in to comment.