Run CLANGFORMAT on sample

Summary: This diff runs CLANGFORMAT lint on sample. I have added CLANGFORMAT as the lint engined for objc files in xplat/sonar. Right now the iOS folder is not formatted according to CLANGFORMAT.

Reviewed By: passy

Differential Revision: D19942174

fbshipit-source-id: bef3e67bf31f13bb52417c81c4c330d6c258872d
This commit is contained in:
Pritesh Nandgaonkar
2020-02-17 10:46:43 -08:00
committed by Facebook Github Bot
parent e8b20d5b15
commit 0e4250b4af
9 changed files with 236 additions and 181 deletions

View File

@@ -7,51 +7,61 @@
#import "AppDelegate.h" #import "AppDelegate.h"
#import <FlipperKit/FlipperClient.h> #import <FlipperKit/FlipperClient.h>
#import <FlipperKitExamplePlugin/FlipperKitExamplePlugin.h>
#import <FlipperKitLayoutComponentKitSupport/FlipperKitLayoutComponentKitSupport.h>
#import <FlipperKitLayoutPlugin/FlipperKitLayoutPlugin.h> #import <FlipperKitLayoutPlugin/FlipperKitLayoutPlugin.h>
#import <FlipperKitNetworkPlugin/FlipperKitNetworkPlugin.h> #import <FlipperKitNetworkPlugin/FlipperKitNetworkPlugin.h>
#import <FlipperKitUserDefaultsPlugin/FKUserDefaultsPlugin.h>
#import <FlipperKitLayoutComponentKitSupport/FlipperKitLayoutComponentKitSupport.h>
#import <FlipperKitExamplePlugin/FlipperKitExamplePlugin.h>
#import <SKIOSNetworkPlugin/SKIOSNetworkAdapter.h>
#import <FlipperKitReactPlugin/FlipperKitReactPlugin.h> #import <FlipperKitReactPlugin/FlipperKitReactPlugin.h>
#import <FlipperKitUserDefaultsPlugin/FKUserDefaultsPlugin.h> #import <FlipperKitUserDefaultsPlugin/FKUserDefaultsPlugin.h>
#import <SKIOSNetworkPlugin/SKIOSNetworkAdapter.h>
#import "MainViewController.h" #import "MainViewController.h"
#import "RootViewController.h" #import "RootViewController.h"
#if !FB_SONARKIT_ENABLED #if !FB_SONARKIT_ENABLED
#error "Sample need to be run with SonarKit enabled in order to properly interact with Sonar. SonarKit is enabled by default if its a debug build." #error \
"Sample need to be run with SonarKit enabled in order to properly interact with Sonar. SonarKit is enabled by default if its a debug build."
#endif #endif
@implementation AppDelegate { @implementation AppDelegate {
UIWindow* _window; UIWindow* _window;
} }
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions - (BOOL)application:(UIApplication*)application
{ didFinishLaunchingWithOptions:(NSDictionary*)launchOptions {
_window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; _window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
FlipperClient* client = [FlipperClient sharedClient]; FlipperClient* client = [FlipperClient sharedClient];
SKDescriptorMapper *layoutDescriptorMapper = [[SKDescriptorMapper alloc] initWithDefaults]; SKDescriptorMapper* layoutDescriptorMapper =
[FlipperKitLayoutComponentKitSupport setUpWithDescriptorMapper: layoutDescriptorMapper]; [[SKDescriptorMapper alloc] initWithDefaults];
[client addPlugin: [[FlipperKitLayoutPlugin alloc] initWithRootNode: application [FlipperKitLayoutComponentKitSupport
setUpWithDescriptorMapper:layoutDescriptorMapper];
[client addPlugin:[[FlipperKitLayoutPlugin alloc]
initWithRootNode:application
withDescriptorMapper:layoutDescriptorMapper]]; withDescriptorMapper:layoutDescriptorMapper]];
[client addPlugin:[[FKUserDefaultsPlugin alloc] initWithSuiteName:nil]]; [client addPlugin:[[FKUserDefaultsPlugin alloc] initWithSuiteName:nil]];
[[FlipperClient sharedClient] addPlugin: [[FlipperKitNetworkPlugin alloc] initWithNetworkAdapter:[SKIOSNetworkAdapter new]]]; [[FlipperClient sharedClient]
addPlugin:[[FlipperKitNetworkPlugin alloc]
initWithNetworkAdapter:[SKIOSNetworkAdapter new]]];
[client addPlugin:[FlipperKitExamplePlugin sharedInstance]]; [client addPlugin:[FlipperKitExamplePlugin sharedInstance]];
[client addPlugin:[FlipperKitReactPlugin new]]; [client addPlugin:[FlipperKitReactPlugin new]];
[client start]; [client start];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryBoard" bundle:nil]; UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"MainStoryBoard"
MainViewController *mainViewController = [storyboard instantiateViewControllerWithIdentifier:@"MainViewController"]; bundle:nil];
MainViewController* mainViewController = [storyboard
instantiateViewControllerWithIdentifier:@"MainViewController"];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController: mainViewController]; UINavigationController* navigationController = [[UINavigationController alloc]
initWithRootViewController:mainViewController];
navigationController.navigationBar.topItem.title = @"Sample"; navigationController.navigationBar.topItem.title = @"Sample";
navigationController.navigationBar.translucent = NO; navigationController.navigationBar.translucent = NO;
[_window setRootViewController: [[UINavigationController alloc] initWithRootViewController: mainViewController]]; [_window
setRootViewController:[[UINavigationController alloc]
initWithRootViewController:mainViewController]];
[_window makeKeyAndVisible]; [_window makeKeyAndVisible];
NSLog(@"Hello from Flipper in an Objc app!"); NSLog(@"Hello from Flipper in an Objc app!");

View File

@@ -7,6 +7,7 @@
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
@interface CommunicationDemoViewController : UIViewController<UITableViewDataSource> @interface CommunicationDemoViewController
: UIViewController<UITableViewDataSource>
@end @end

View File

@@ -8,7 +8,8 @@
#import "CommunicationDemoViewController.h" #import "CommunicationDemoViewController.h"
#import <FlipperKitExamplePlugin/FlipperKitExamplePlugin.h> #import <FlipperKitExamplePlugin/FlipperKitExamplePlugin.h>
@interface CommunicationDemoViewController()<FlipperKitExampleCommunicationResponderDelegate> @interface CommunicationDemoViewController ()<
FlipperKitExampleCommunicationResponderDelegate>
@property(strong, nonatomic) NSMutableArray<NSString*>* messagesToDisplay; @property(strong, nonatomic) NSMutableArray<NSString*>* messagesToDisplay;
@property(weak, nonatomic) IBOutlet UITextField* messageTextField; @property(weak, nonatomic) IBOutlet UITextField* messageTextField;
@property(weak, nonatomic) IBOutlet UITableView* tableView; @property(weak, nonatomic) IBOutlet UITableView* tableView;
@@ -27,17 +28,21 @@
- (IBAction)tappedSendMessage:(UIButton*)sender { - (IBAction)tappedSendMessage:(UIButton*)sender {
if (self.messageTextField.text.length > 0) { if (self.messageTextField.text.length > 0) {
[[FlipperKitExamplePlugin sharedInstance] sendMessage:self.messageTextField.text]; [[FlipperKitExamplePlugin sharedInstance]
sendMessage:self.messageTextField.text];
} }
} }
- (nonnull UITableViewCell *)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath { - (nonnull UITableViewCell*)tableView:(nonnull UITableView*)tableView
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"reusableCell"]; cellForRowAtIndexPath:(nonnull NSIndexPath*)indexPath {
UITableViewCell* cell =
[tableView dequeueReusableCellWithIdentifier:@"reusableCell"];
cell.textLabel.text = self.messagesToDisplay[indexPath.row]; cell.textLabel.text = self.messagesToDisplay[indexPath.row];
return cell; return cell;
} }
- (NSInteger)tableView:(nonnull UITableView *)tableView numberOfRowsInSection:(NSInteger)section { - (NSInteger)tableView:(nonnull UITableView*)tableView
numberOfRowsInSection:(NSInteger)section {
return self.messagesToDisplay.count; return self.messagesToDisplay.count;
} }

View File

@@ -7,11 +7,11 @@
#import "MainViewController.h" #import "MainViewController.h"
#import <FlipperKit/FlipperDiagnosticsViewController.h>
#import "CommunicationDemoViewController.h"
#import "NetworkViewController.h" #import "NetworkViewController.h"
#import "RootViewController.h" #import "RootViewController.h"
#import "UserDefaultsViewController.h" #import "UserDefaultsViewController.h"
#import "CommunicationDemoViewController.h"
#import <FlipperKit/FlipperDiagnosticsViewController.h>
@interface MainViewController () @interface MainViewController ()
@@ -24,34 +24,46 @@
// Do any additional setup after loading the view. // Do any additional setup after loading the view.
} }
- (IBAction)tappedDiagnosticScreen:(UIButton*)sender { - (IBAction)tappedDiagnosticScreen:(UIButton*)sender {
FlipperDiagnosticsViewController *controller = [[FlipperDiagnosticsViewController alloc] init]; FlipperDiagnosticsViewController* controller =
[[FlipperDiagnosticsViewController alloc] init];
[self.navigationController pushViewController:controller animated:true]; [self.navigationController pushViewController:controller animated:true];
} }
- (IBAction)tappedComponentKitLayout:(UIButton*)sender { - (IBAction)tappedComponentKitLayout:(UIButton*)sender {
RootViewController* rootViewController = [RootViewController new]; RootViewController* rootViewController = [RootViewController new];
[self.navigationController pushViewController:rootViewController animated:true]; [self.navigationController pushViewController:rootViewController
animated:true];
} }
- (IBAction)tappedNetworkInspector:(UIButton*)sender { - (IBAction)tappedNetworkInspector:(UIButton*)sender {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryBoard" bundle:nil]; UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"MainStoryBoard"
NetworkViewController *networkViewController = [storyboard instantiateViewControllerWithIdentifier:@"NetworkViewController"]; bundle:nil];
NetworkViewController* networkViewController = [storyboard
instantiateViewControllerWithIdentifier:@"NetworkViewController"];
[self.navigationController pushViewController:networkViewController animated:true]; [self.navigationController pushViewController:networkViewController
animated:true];
} }
- (IBAction)tappedUserDefaults:(id)sender { - (IBAction)tappedUserDefaults:(id)sender {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryBoard" bundle:nil]; UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"MainStoryBoard"
UserDefaultsViewController *userDefaultsViewController = [storyboard instantiateViewControllerWithIdentifier:@"UserDefaultsViewController"]; bundle:nil];
UserDefaultsViewController* userDefaultsViewController = [storyboard
instantiateViewControllerWithIdentifier:@"UserDefaultsViewController"];
[self.navigationController pushViewController:userDefaultsViewController animated:true]; [self.navigationController pushViewController:userDefaultsViewController
animated:true];
} }
- (IBAction)tappedCommunicationDemo:(UIButton*)sender { - (IBAction)tappedCommunicationDemo:(UIButton*)sender {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryBoard" bundle:nil]; UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"MainStoryBoard"
CommunicationDemoViewController *communicationDemoViewController = [storyboard instantiateViewControllerWithIdentifier:@"CommunicationDemoViewController"]; bundle:nil];
[self.navigationController pushViewController:communicationDemoViewController animated:true]; CommunicationDemoViewController* communicationDemoViewController =
[storyboard instantiateViewControllerWithIdentifier:
@"CommunicationDemoViewController"];
[self.navigationController pushViewController:communicationDemoViewController
animated:true];
} }
- (IBAction)tappedCauseCrash:(UIButton*)sender { - (IBAction)tappedCauseCrash:(UIButton*)sender {

View File

@@ -19,7 +19,15 @@
} }
- (IBAction)tappedGithubLitho:(UIButton*)sender { - (IBAction)tappedGithubLitho:(UIButton*)sender {
[[[NSURLSession sharedSession] dataTaskWithURL:[NSURL URLWithString:@"https://raw.githubusercontent.com/facebook/litho/master/docs/static/logo.png"] completionHandler:^(NSData *_Nullable data, NSURLResponse *_Nullable response, NSError *_Nullable error) { [[[NSURLSession sharedSession]
dataTaskWithURL:
[NSURL
URLWithString:
@"https://raw.githubusercontent.com/facebook/litho/master/docs/static/logo.png"]
completionHandler:^(
NSData* _Nullable data,
NSURLResponse* _Nullable response,
NSError* _Nullable error) {
if (error && !data) { if (error && !data) {
return; return;
} }
@@ -33,36 +41,56 @@
NSMutableURLRequest* urlRequest = [NSMutableURLRequest requestWithURL:url]; NSMutableURLRequest* urlRequest = [NSMutableURLRequest requestWithURL:url];
[urlRequest addValue:@"application/json" forHTTPHeaderField:@"Content-Type"]; [urlRequest addValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[urlRequest addValue:@"application/json" forHTTPHeaderField:@"Accept"]; [urlRequest addValue:@"application/json" forHTTPHeaderField:@"Accept"];
NSDictionary *mapData = [[NSDictionary alloc] initWithObjectsAndKeys: @"Flipper", @"app", NSDictionary* mapData =
@"Its awesome", @"remarks", [[NSDictionary alloc] initWithObjectsAndKeys:@"Flipper",
@"app",
@"Its awesome",
@"remarks",
nil]; nil];
NSError* error = nil; NSError* error = nil;
NSData *postData = [NSJSONSerialization dataWithJSONObject:mapData options:0 error:&error]; NSData* postData = [NSJSONSerialization dataWithJSONObject:mapData
options:0
error:&error];
[urlRequest setHTTPBody:postData]; [urlRequest setHTTPBody:postData];
[urlRequest setHTTPMethod:@"POST"]; [urlRequest setHTTPMethod:@"POST"];
__weak NetworkViewController* weakSelf = self; __weak NetworkViewController* weakSelf = self;
[[[NSURLSession sharedSession] dataTaskWithRequest:urlRequest completionHandler:^(NSData *_Nullable data, NSURLResponse *_Nullable response, NSError *_Nullable dataTaskError) { [[[NSURLSession sharedSession]
dataTaskWithRequest:urlRequest
completionHandler:^(
NSData* _Nullable data,
NSURLResponse* _Nullable response,
NSError* _Nullable dataTaskError) {
if (dataTaskError || !data) { if (dataTaskError || !data) {
[weakSelf showAlertWithMessage:@"Received error in POST API response"]; [weakSelf
showAlertWithMessage:@"Received error in POST API response"];
return; return;
} }
NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:0 error:&dataTaskError]; NSDictionary* dict =
[NSJSONSerialization JSONObjectWithData:data
options:0
error:&dataTaskError];
NSLog(@"MSG-POST: %@", dict[@"msg"]); NSLog(@"MSG-POST: %@", dict[@"msg"]);
[weakSelf showAlertWithMessage:@"Received response from POST API"]; [weakSelf showAlertWithMessage:@"Received response from POST API"];
}] resume]; }] resume];
} }
- (IBAction)tappedGetAPI:(UIButton*)sender { - (IBAction)tappedGetAPI:(UIButton*)sender {
__weak NetworkViewController* weakSelf = self; __weak NetworkViewController* weakSelf = self;
[[[NSURLSession sharedSession] dataTaskWithURL:[NSURL URLWithString:@"https://demo9512366.mockable.io/FlipperGet"] completionHandler:^(NSData *_Nullable data, NSURLResponse *_Nullable response, NSError *_Nullable error) { [[[NSURLSession sharedSession]
dataTaskWithURL:
[NSURL URLWithString:@"https://demo9512366.mockable.io/FlipperGet"]
completionHandler:^(
NSData* _Nullable data,
NSURLResponse* _Nullable response,
NSError* _Nullable error) {
if (error || !data) { if (error || !data) {
[weakSelf showAlertWithMessage:@"Received error in GET API response"]; [weakSelf showAlertWithMessage:@"Received error in GET API response"];
return; return;
} }
NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error]; NSDictionary* dict = [NSJSONSerialization JSONObjectWithData:data
options:0
error:&error];
NSLog(@"MSG-GET: %@", dict[@"msg"]); NSLog(@"MSG-GET: %@", dict[@"msg"]);
[weakSelf showAlertWithMessage:@"Received response from GET API"]; [weakSelf showAlertWithMessage:@"Received response from GET API"];
}] resume]; }] resume];
@@ -76,8 +104,14 @@
} }
- (UIAlertController*)alertControllerForMessage:(nonnull NSString*)msg { - (UIAlertController*)alertControllerForMessage:(nonnull NSString*)msg {
UIAlertController *controller = [UIAlertController alertControllerWithTitle:@"Flipper" message:msg preferredStyle:UIAlertControllerStyleAlert]; UIAlertController* controller =
UIAlertAction *action = [UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleDefault handler:nil]; [UIAlertController alertControllerWithTitle:@"Flipper"
message:msg
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* action =
[UIAlertAction actionWithTitle:@"Ok"
style:UIAlertActionStyleDefault
handler:nil];
[controller addAction:action]; [controller addAction:action];
return controller; return controller;
} }

View File

@@ -26,13 +26,13 @@
@implementation RootViewController @implementation RootViewController
- (instancetype)init - (instancetype)init {
{
if (self = [super init]) { if (self = [super init]) {
_rootCKHostingView = [[CKComponentHostingView alloc] _rootCKHostingView = [[CKComponentHostingView alloc]
initWithComponentProvider:[self class] initWithComponentProvider:[self class]
sizeRangeProvider: sizeRangeProvider:[CKComponentFlexibleSizeRangeProvider
[CKComponentFlexibleSizeRangeProvider providerWithFlexibility:CKComponentSizeRangeFlexibleHeight]]; providerWithFlexibility:
CKComponentSizeRangeFlexibleHeight]];
[self.view addSubview:_rootCKHostingView]; [self.view addSubview:_rootCKHostingView];
[self loadViewIfNeeded]; [self loadViewIfNeeded];
@@ -46,51 +46,42 @@
self.edgesForExtendedLayout = UIRectEdgeNone; self.edgesForExtendedLayout = UIRectEdgeNone;
} }
- (void)viewDidLayoutSubviews - (void)viewDidLayoutSubviews {
{
[super viewDidLayoutSubviews]; [super viewDidLayoutSubviews];
_rootCKHostingView.frame = self.view.bounds; _rootCKHostingView.frame = self.view.bounds;
} }
+ (CKComponent *)componentForModel:(id<NSObject>)model context:(id<NSObject>)context { + (CKComponent*)componentForModel:(id<NSObject>)model
context:(id<NSObject>)context {
return [CKBackgroundLayoutComponent return [CKBackgroundLayoutComponent
newWithComponent: newWithComponent:
[CKFlexboxComponent [CKFlexboxComponent newWithView:{}
newWithView:{
}
size:{} size:{}
style:{} style:{}
children:{ children:{
{ {[CKButtonComponent
[CKButtonComponent
newWithAction:nil newWithAction:nil
options:{ options:{
.titles = @"Purple", .titles = @"Purple",
.titleColors = UIColor.purpleColor, .titleColors =
} UIColor.purpleColor,
] }]},
}, {[CKButtonComponent
{
[CKButtonComponent
newWithAction:nil newWithAction:nil
options:{ options:{
.titles = @"Brown", .titles = @"Brown",
.titleColors = UIColor.brownColor, .titleColors =
} UIColor.brownColor,
] }]},
}, {[CKButtonComponent
{
[CKButtonComponent
newWithAction:nil newWithAction:nil
options:{ options:{
.titles = @"Cyan", .titles = @"Cyan",
.titleColors = UIColor.cyanColor, .titleColors =
} UIColor.cyanColor,
] }]},
},
}] }]
background: background:[CKImageComponent
[CKImageComponent
newWithImage:[UIImage imageNamed:@"sonarpattern"] newWithImage:[UIImage imageNamed:@"sonarpattern"]
attributes:{} attributes:{}
size:{}]]; size:{}]];

View File

@@ -23,7 +23,8 @@
} }
- (IBAction)tappedSave:(id)sender { - (IBAction)tappedSave:(id)sender {
[self.userDefaults setObject:self.valueTextField.text forKey:self.keyTextField.text]; [self.userDefaults setObject:self.valueTextField.text
forKey:self.keyTextField.text];
} }
@end @end

View File

@@ -11,6 +11,7 @@
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
@autoreleasepool { @autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); return UIApplicationMain(
argc, argv, nil, NSStringFromClass([AppDelegate class]));
} }
} }