Files
react-native/packages/rn-tester/NativeComponentExample/ios/RNTMyLegacyNativeViewManager.mm
generatedunixname89002005287564 4553f87489 Fix CQS signal readability-implicit-bool-conversion in xplat/js/react-native-github/packages (#53591)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/53591

Reviewed By: rshest

Differential Revision: D81571883

fbshipit-source-id: 479a0764eabeac968028814ec6aafa32687b0905
2025-09-04 03:13:49 -07:00

89 lines
2.5 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>
#import "RNTLegacyView.h"
#import "RNTMyNativeViewComponentView.h"
#import "UIView+ColorOverlays.h"
@interface RNTMyLegacyNativeViewManager : RCTViewManager
@end
@implementation RNTMyLegacyNativeViewManager
+ (BOOL)requiresMainQueueSetup
{
return NO;
}
RCT_EXPORT_MODULE()
RCT_REMAP_VIEW_PROPERTY(color, backgroundColor, UIColor)
RCT_REMAP_VIEW_PROPERTY(opacity, alpha, CGFloat)
RCT_EXPORT_VIEW_PROPERTY(onColorChanged, RCTBubblingEventBlock)
RCT_CUSTOM_VIEW_PROPERTY(cornerRadius, CGFloat, RNTLegacyView)
{
view.clipsToBounds = true;
NSNumber *cornerRadius = (NSNumber *)json;
view.layer.cornerRadius = [cornerRadius floatValue];
}
RCT_EXPORT_METHOD(changeBackgroundColor : (nonnull NSNumber *)reactTag color : (NSString *)color)
{
[self.bridge.uiManager addUIBlock:^(RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) {
if (UIView *view = [RNTMyLegacyNativeViewManager getViewByTag:viewRegistry reactTag:reactTag]) {
[view setBackgroundColorWithColorString:color];
}
}];
}
RCT_EXPORT_METHOD(addOverlays : (nonnull NSNumber *)reactTag overlayColors : (NSArray *)overlayColors)
{
[self.bridge.uiManager addUIBlock:^(RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) {
if (UIView *view = [RNTMyLegacyNativeViewManager getViewByTag:viewRegistry reactTag:reactTag]) {
[view addColorOverlays:overlayColors];
}
}];
}
RCT_EXPORT_METHOD(removeOverlays : (nonnull NSNumber *)reactTag)
{
[self.bridge.uiManager addUIBlock:^(RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) {
if (UIView *view = [RNTMyLegacyNativeViewManager getViewByTag:viewRegistry reactTag:reactTag]) {
[view removeOverlays];
}
}];
}
+ (UIView *)getViewByTag:(NSDictionary<NSNumber *, UIView *> *)viewRegistry reactTag:(nonnull NSNumber *)reactTag
{
UIView *view = viewRegistry[reactTag];
if ((view == nullptr) || ![view isKindOfClass:[RNTLegacyView class]]) {
RCTLogError(@"Cannot find RNTLegacyView with tag #%@", reactTag);
return NULL;
}
return view;
}
- (UIView *)view
{
RNTLegacyView *view = [[RNTLegacyView alloc] init];
return view;
}
- (NSDictionary *)constantsToExport
{
return @{@"PI" : @3.14};
}
@end