mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/36610 This change add to RNTester examples of a legacy Native Component, loaded in the New Architecture through the Interop Layer, that uses the APIs described in the [Direct Manipulation](https://reactnative.dev/docs/direct-manipulation) sectioon of the website. ## Changelog: [iOS][Added] - Added examples of direct manipulation Reviewed By: sammy-SC Differential Revision: D43978674 fbshipit-source-id: 1cbc56f28034f84f309166e3e392ad97a8164e64
76 lines
2.2 KiB
Plaintext
76 lines
2.2 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"
|
|
|
|
@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) {
|
|
UIView *view = viewRegistry[reactTag];
|
|
if (!view || ![view isKindOfClass:[RNTLegacyView class]]) {
|
|
RCTLogError(@"Cannot find RNTLegacyView 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];
|
|
|
|
UIColor *newColor = [UIColor colorWithRed:((rgbValue & 0xFF0000) >> 16) / 255.0
|
|
green:((rgbValue & 0xFF00) >> 8) / 255.0
|
|
blue:(rgbValue & 0xFF) / 255.0
|
|
alpha:1.0];
|
|
view.backgroundColor = newColor;
|
|
}];
|
|
}
|
|
|
|
- (UIView *)view
|
|
{
|
|
RNTLegacyView *view = [[RNTLegacyView alloc] init];
|
|
view.backgroundColor = UIColor.redColor;
|
|
return view;
|
|
}
|
|
|
|
- (NSDictionary *)constantsToExport
|
|
{
|
|
return @{@"PI" : @3.14};
|
|
}
|
|
@end
|