mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Reviewed By: aaronabramov Differential Revision: D33367752 fbshipit-source-id: 4ce94d184485e5ee0a62cf67ad2d3ba16e285c8f
89 lines
2.6 KiB
Plaintext
89 lines
2.6 KiB
Plaintext
/*
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*/
|
|
|
|
#import "RNTMyNativeViewComponentView.h"
|
|
|
|
#import <react/renderer/components/MyNativeViewSpec/ComponentDescriptors.h>
|
|
#import <react/renderer/components/MyNativeViewSpec/EventEmitters.h>
|
|
#import <react/renderer/components/MyNativeViewSpec/Props.h>
|
|
#import <react/renderer/components/MyNativeViewSpec/RCTComponentViewHelpers.h>
|
|
|
|
#import "RCTFabricComponentsPlugins.h"
|
|
|
|
using namespace facebook::react;
|
|
|
|
@interface RNTMyNativeViewComponentView () <RCTRNTMyNativeViewViewProtocol>
|
|
@end
|
|
|
|
@implementation RNTMyNativeViewComponentView {
|
|
UIView *_view;
|
|
}
|
|
|
|
+ (ComponentDescriptorProvider)componentDescriptorProvider
|
|
{
|
|
return concreteComponentDescriptorProvider<RNTMyNativeViewComponentDescriptor>();
|
|
}
|
|
|
|
- (instancetype)initWithFrame:(CGRect)frame
|
|
{
|
|
if (self = [super initWithFrame:frame]) {
|
|
static const auto defaultProps = std::make_shared<const RNTMyNativeViewProps>();
|
|
_props = defaultProps;
|
|
|
|
_view = [[UIView alloc] init];
|
|
_view.backgroundColor = [UIColor redColor];
|
|
|
|
self.contentView = _view;
|
|
}
|
|
|
|
return self;
|
|
}
|
|
|
|
- (UIColor *)UIColorFromHexString:(const std::string)hexString
|
|
{
|
|
unsigned rgbValue = 0;
|
|
NSString *colorString = [NSString stringWithCString:hexString.c_str() encoding:[NSString defaultCStringEncoding]];
|
|
NSScanner *scanner = [NSScanner scannerWithString:colorString];
|
|
[scanner setScanLocation:1]; // bypass '#' character
|
|
[scanner scanHexInt:&rgbValue];
|
|
return [UIColor colorWithRed:((rgbValue & 0xFF0000) >> 16) / 255.0
|
|
green:((rgbValue & 0xFF00) >> 8) / 255.0
|
|
blue:(rgbValue & 0xFF) / 255.0
|
|
alpha:1.0];
|
|
}
|
|
|
|
- (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps
|
|
{
|
|
[super updateProps:props oldProps:oldProps];
|
|
}
|
|
|
|
- (void)onChange:(UIView *)sender
|
|
{
|
|
// No-op
|
|
// std::dynamic_pointer_cast<const ViewEventEmitter>(_eventEmitter)
|
|
// ->onChange(ViewEventEmitter::OnChange{.value = static_cast<bool>(sender.on)});
|
|
}
|
|
|
|
#pragma mark - Native Commands
|
|
|
|
- (void)handleCommand:(const NSString *)commandName args:(const NSArray *)args
|
|
{
|
|
RCTRNTMyNativeViewHandleCommand(self, commandName, args);
|
|
}
|
|
|
|
- (void)callNativeMethodToChangeBackgroundColor:(NSString *)colorString
|
|
{
|
|
UIColor *color = [self UIColorFromHexString:std::string([colorString UTF8String])];
|
|
_view.backgroundColor = color;
|
|
}
|
|
@end
|
|
|
|
Class<RCTComponentViewProtocol> RNTMyNativeViewCls(void)
|
|
{
|
|
return RNTMyNativeViewComponentView.class;
|
|
}
|