Skip to content

Commit

Permalink
Do not opt-out fbsource/xplat/js/react-native-github/packages from CL…
Browse files Browse the repository at this point in the history
…ANGFORMAT

Summary:
As we're working on C++ code for RNTester to integrate Fabric, we should enable CLANGFORMAT for the files over there.

Changelog:
[Internal] [Changed] - Enable CLANGFORMAT on fbsource/xplat/js/react-native-github/packages

Reviewed By: ShikaSD

Differential Revision: D32493605

fbshipit-source-id: 7b5d63f6d2fae1a1aa1e782738953c8cd2cdbe4b
  • Loading branch information
cortinico authored and facebook-github-bot committed Nov 18, 2021
1 parent 8ace78c commit aa4da24
Show file tree
Hide file tree
Showing 62 changed files with 1,468 additions and 1,307 deletions.
4 changes: 2 additions & 2 deletions packages/react-native-codegen/buck_tests/emptyFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@

// TODO: Import every prop and event to asset they're generated

int main(){
return 0;
int main() {
return 0;
}
7 changes: 4 additions & 3 deletions packages/react-native-codegen/buck_tests/emptyFile.mm
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
* LICENSE file in the root directory of this source tree.
*/

#import <FBReactNativeTestSpec/FBReactNativeTestSpec.h>
#import <react/renderer/components/codegen_tests/ComponentDescriptors.h>
#import <react/renderer/components/codegen_tests/ComponentViewHelpers.h>
#import <FBReactNativeTestSpec/FBReactNativeTestSpec.h>
#import <FBReactNativeTestSpec/FBReactNativeTestSpec-generated.mm>

// TODO: Import every prop and event to asset they're generated

int main(){
return 0;
int main()
{
return 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
* LICENSE file in the root directory of this source tree.
*/

#import <UIKit/UIKit.h>
#import <React/RCTViewComponentView.h>
#import <UIKit/UIKit.h>

NS_ASSUME_NONNULL_BEGIN

@interface RNTMyNativeViewComponentView : RCTViewComponentView

- (UIColor *)UIColorFromHexString: (const std::string)hexString;
- (UIColor *)UIColorFromHexString:(const std::string)hexString;

@end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
#import "RNTMyNativeViewComponentView.h"

#import <react/renderer/components/MyNativeViewSpec/ComponentDescriptors.h>
#import <react/renderer/components/MyNativeViewSpec/Props.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"
Expand All @@ -20,7 +20,7 @@ @interface RNTMyNativeViewComponentView () <RCTRNTMyNativeViewViewProtocol>
@end

@implementation RNTMyNativeViewComponentView {
UIView *_view;
UIView *_view;
}

+ (ComponentDescriptorProvider)componentDescriptorProvider
Expand All @@ -35,41 +35,44 @@ - (instancetype)initWithFrame:(CGRect)frame
_props = defaultProps;

_view = [[UIView alloc] init];
_view.backgroundColor = [UIColor redColor];
_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];
- (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];
[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)});
// 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);
RCTRNTMyNativeViewHandleCommand(self, commandName, args);
}

- (void)callNativeMethodToChangeBackgroundColor:(NSString *)colorString
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
* LICENSE file in the root directory of this source tree.
*/

#import <React/RCTViewManager.h>
#import <React/RCTUIManager.h>
#import <React/RCTLog.h>
#import <React/RCTUIManager.h>
#import <React/RCTViewManager.h>

@interface RNTMyNativeViewManager : RCTViewManager
@end
Expand All @@ -18,15 +18,14 @@ @implementation RNTMyNativeViewManager

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;
}
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()
Expand All @@ -35,9 +34,11 @@ @implementation RNTMyNativeViewManager
[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];
}];

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
Expand Down
116 changes: 58 additions & 58 deletions packages/rn-tester/NativeModuleExample/Screenshot.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,71 +13,71 @@ @implementation ScreenshotManager

RCT_EXPORT_MODULE();

RCT_EXPORT_METHOD(takeScreenshot:(id /* NSString or NSNumber */)target
withOptions:(NSDictionary *)options
resolve:(RCTPromiseResolveBlock)resolve
reject:(RCTPromiseRejectBlock)reject)
RCT_EXPORT_METHOD(takeScreenshot
: (id /* NSString or NSNumber */)target withOptions
: (NSDictionary *)options resolve
: (RCTPromiseResolveBlock)resolve reject
: (RCTPromiseRejectBlock)reject)
{
[self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) {

// Get view
UIView *view;
if (target == nil || [target isEqual:@"window"]) {
view = RCTKeyWindow();
} else if ([target isKindOfClass:[NSNumber class]]) {
view = viewRegistry[target];
if (!view) {
RCTLogError(@"No view found with reactTag: %@", target);
return;
}
}

// Get options
CGSize size = [RCTConvert CGSize:options];
NSString *format = [RCTConvert NSString:options[@"format"] ?: @"png"];

// Capture image
if (size.width < 0.1 || size.height < 0.1) {
size = view.bounds.size;
}
UIGraphicsBeginImageContextWithOptions(size, NO, 0);
BOOL success = [view drawViewHierarchyInRect:(CGRect){CGPointZero, size} afterScreenUpdates:YES];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

if (!success || !image) {
reject(RCTErrorUnspecified, @"Failed to capture view snapshot.", nil);
return;
}
[self.bridge.uiManager
addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) {
// Get view
UIView *view;
if (target == nil || [target isEqual:@"window"]) {
view = RCTKeyWindow();
} else if ([target isKindOfClass:[NSNumber class]]) {
view = viewRegistry[target];
if (!view) {
RCTLogError(@"No view found with reactTag: %@", target);
return;
}
}

// Convert image to data (on a background thread)
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
// Get options
CGSize size = [RCTConvert CGSize:options];
NSString *format = [RCTConvert NSString:options[@"format"] ?: @"png"];

NSData *data;
if ([format isEqualToString:@"png"]) {
data = UIImagePNGRepresentation(image);
} else if ([format isEqualToString:@"jpeg"]) {
CGFloat quality = [RCTConvert CGFloat:options[@"quality"] ?: @1];
data = UIImageJPEGRepresentation(image, quality);
} else {
RCTLogError(@"Unsupported image format: %@", format);
return;
}
// Capture image
if (size.width < 0.1 || size.height < 0.1) {
size = view.bounds.size;
}
UIGraphicsBeginImageContextWithOptions(size, NO, 0);
BOOL success = [view drawViewHierarchyInRect:(CGRect){CGPointZero, size} afterScreenUpdates:YES];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

// Save to a temp file
NSError *error = nil;
NSString *tempFilePath = RCTTempFilePath(format, &error);
if (tempFilePath) {
if ([data writeToFile:tempFilePath options:(NSDataWritingOptions)0 error:&error]) {
resolve(tempFilePath);
if (!success || !image) {
reject(RCTErrorUnspecified, @"Failed to capture view snapshot.", nil);
return;
}
}

// If we reached here, something went wrong
reject(RCTErrorUnspecified, error.localizedDescription, error);
});
}];
// Convert image to data (on a background thread)
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSData *data;
if ([format isEqualToString:@"png"]) {
data = UIImagePNGRepresentation(image);
} else if ([format isEqualToString:@"jpeg"]) {
CGFloat quality = [RCTConvert CGFloat:options[@"quality"] ?: @1];
data = UIImageJPEGRepresentation(image, quality);
} else {
RCTLogError(@"Unsupported image format: %@", format);
return;
}

// Save to a temp file
NSError *error = nil;
NSString *tempFilePath = RCTTempFilePath(format, &error);
if (tempFilePath) {
if ([data writeToFile:tempFilePath options:(NSDataWritingOptions)0 error:&error]) {
resolve(tempFilePath);
return;
}
}

// If we reached here, something went wrong
reject(RCTErrorUnspecified, error.localizedDescription, error);
});
}];
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ extern NSString *const FBReferenceImageFilePathKey;
/**
Record snapshots.
**/
@property(readwrite, nonatomic, assign) BOOL recordMode;
@property (readwrite, nonatomic, assign) BOOL recordMode;

/**
@param testClass The subclass of FBSnapshotTestCase that is using this controller.
Expand All @@ -55,7 +55,8 @@ extern NSString *const FBReferenceImageFilePathKey;
@param view The view to snapshot.
@param selector selector
@param identifier An optional identifier, used is there are multiple snapshot tests in a given -test method.
@param errorPtr An error to log in an XCTAssert() macro if the method fails (missing reference image, images differ, etc).
@param errorPtr An error to log in an XCTAssert() macro if the method fails (missing reference image, images differ,
etc).
@returns YES if the comparison (or saving of the reference image) succeeded.
*/
- (BOOL)compareSnapshotOfView:(UIView *)view
Expand All @@ -75,9 +76,7 @@ extern NSString *const FBReferenceImageFilePathKey;
@param error An error, if this methods returns nil, the error will be something useful.
@returns An image.
*/
- (UIImage *)referenceImageForSelector:(SEL)selector
identifier:(NSString *)identifier
error:(NSError **)error;
- (UIImage *)referenceImageForSelector:(SEL)selector identifier:(NSString *)identifier error:(NSError **)error;

/**
Saves a reference image.
Expand All @@ -98,9 +97,7 @@ extern NSString *const FBReferenceImageFilePathKey;
@param errorPtr An error that indicates why the comparison failed if it does.
@returns YES if the comparison succeeded and the images are the same.
*/
- (BOOL)compareReferenceImage:(UIImage *)referenceImage
toImage:(UIImage *)image
error:(NSError **)errorPtr;
- (BOOL)compareReferenceImage:(UIImage *)referenceImage toImage:(UIImage *)image error:(NSError **)errorPtr;

/**
Saves the reference image and the test image to `failedOutputDirectory`.
Expand Down
Loading

0 comments on commit aa4da24

Please sign in to comment.