mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
8bd3edec88
Reviewed By: aaronabramov Differential Revision: D33367752 fbshipit-source-id: 4ce94d184485e5ee0a62cf67ad2d3ba16e285c8f
50 lines
1.6 KiB
Plaintext
50 lines
1.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 <React/RCTLog.h>
|
|
#import <React/RCTUIManager.h>
|
|
#import <React/RCTViewManager.h>
|
|
|
|
@interface RNTMyNativeViewManager : RCTViewManager
|
|
@end
|
|
|
|
@implementation RNTMyNativeViewManager
|
|
|
|
RCT_EXPORT_MODULE(RNTMyNativeView)
|
|
|
|
RCT_EXPORT_VIEW_PROPERTY(backgroundColor, UIColor)
|
|
|
|
RCT_EXPORT_METHOD(callNativeMethodToChangeBackgroundColor : (nonnull NSNumber *)reactTag color : (NSString *)color)
|
|
{
|
|
[self.bridge.uiManager addUIBlock:^(RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) {
|
|
UIView *view = viewRegistry[reactTag];
|
|
if (!view || ![view isKindOfClass:[UIView class]]) {
|
|
RCTLogError(@"Cannot find NativeView with tag #%@", reactTag);
|
|
return;
|
|
}
|
|
|
|
unsigned rgbValue = 0;
|
|
NSString *colorString = [NSString stringWithCString:std::string([color UTF8String]).c_str()
|
|
encoding:[NSString defaultCStringEncoding]];
|
|
NSScanner *scanner = [NSScanner scannerWithString:colorString];
|
|
[scanner setScanLocation:1]; // bypass '#' character
|
|
[scanner scanHexInt:&rgbValue];
|
|
|
|
view.backgroundColor = [UIColor colorWithRed:((rgbValue & 0xFF0000) >> 16) / 255.0
|
|
green:((rgbValue & 0xFF00) >> 8) / 255.0
|
|
blue:(rgbValue & 0xFF) / 255.0
|
|
alpha:1.0];
|
|
}];
|
|
}
|
|
|
|
- (UIView *)view
|
|
{
|
|
return [[UIView alloc] init];
|
|
}
|
|
|
|
@end
|