Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ class <%- project.name -%>ViewManager : SimpleViewManager<<%- project.name -%>Vi
}

@ReactProp(name = "color")
override fun setColor(view: <%- project.name -%>View?, color: String?) {
view?.setBackgroundColor(Color.parseColor(color))
override fun setColor(view: <%- project.name -%>View?, color: Int?) {
view?.setBackgroundColor(color ?: Color.TRANSPARENT)
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { codegenNativeComponent, type ViewProps } from 'react-native';
import {
codegenNativeComponent,
type ColorValue,
type ViewProps,
} from 'react-native';

interface NativeProps extends ViewProps {
color?: string;
color?: ColorValue;
}

export default codegenNativeComponent<NativeProps>('<%- project.name -%>View');
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ import androidx.core.graphics.toColorInt
@DoNotStrip
class Hybrid<%- project.name %>(val context: ThemedReactContext) : Hybrid<%- project.name %>Spec() {

// View
override val view: View = View(context)

// Props
private var _color = "#000"
override var color: String
get() = _color
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
#import "<%- project.name -%>View.h"

#import <React/RCTConversions.h>

#import <react/renderer/components/<%- project.name -%>ViewSpec/ComponentDescriptors.h>
#import <react/renderer/components/<%- project.name -%>ViewSpec/EventEmitters.h>
#import <react/renderer/components/<%- project.name -%>ViewSpec/Props.h>
#import <react/renderer/components/<%- project.name -%>ViewSpec/RCTComponentViewHelpers.h>

#import "RCTFabricComponentsPlugins.h"

using namespace facebook::react;

@interface <%- project.name -%>View () <RCT<%- project.name -%>ViewViewProtocol>

@end

@implementation <%- project.name -%>View {
UIView * _view;
}
Expand Down Expand Up @@ -42,30 +39,10 @@ - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &
const auto &newViewProps = *std::static_pointer_cast<<%- project.name -%>ViewProps const>(props);

if (oldViewProps.color != newViewProps.color) {
NSString * colorToConvert = [[NSString alloc] initWithUTF8String: newViewProps.color.c_str()];
[_view setBackgroundColor:[self hexStringToColor:colorToConvert]];
[_view setBackgroundColor: RCTUIColorFromSharedColor(newViewProps.color)];
}

[super updateProps:props oldProps:oldProps];
}

Class<RCTComponentViewProtocol> <%- project.name -%>ViewCls(void)
{
return <%- project.name -%>View.class;
}

- hexStringToColor:(NSString *)stringToConvert
{
NSString *noHashString = [stringToConvert stringByReplacingOccurrencesOfString:@"#" withString:@""];
NSScanner *stringScanner = [NSScanner scannerWithString:noHashString];

unsigned hex;
if (![stringScanner scanHexInt:&hex]) return nil;
int r = (hex >> 16) & 0xFF;
int g = (hex >> 8) & 0xFF;
int b = (hex) & 0xFF;

return [UIColor colorWithRed:r / 255.0f green:g / 255.0f blue:b / 255.0f alpha:1.0f];
}

@end