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,5 +7,5 @@
#import <UIKit/UIKit.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@interface AppDelegate : UIResponder<UIApplicationDelegate>
@end

View File

@@ -7,51 +7,61 @@
#import "AppDelegate.h"
#import <FlipperKit/FlipperClient.h>
#import <FlipperKitExamplePlugin/FlipperKitExamplePlugin.h>
#import <FlipperKitLayoutComponentKitSupport/FlipperKitLayoutComponentKitSupport.h>
#import <FlipperKitLayoutPlugin/FlipperKitLayoutPlugin.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 <FlipperKitUserDefaultsPlugin/FKUserDefaultsPlugin.h>
#import <SKIOSNetworkPlugin/SKIOSNetworkAdapter.h>
#import "MainViewController.h"
#import "RootViewController.h"
#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
@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]];
FlipperClient *client = [FlipperClient sharedClient];
FlipperClient* client = [FlipperClient sharedClient];
SKDescriptorMapper *layoutDescriptorMapper = [[SKDescriptorMapper alloc] initWithDefaults];
[FlipperKitLayoutComponentKitSupport setUpWithDescriptorMapper: layoutDescriptorMapper];
[client addPlugin: [[FlipperKitLayoutPlugin alloc] initWithRootNode: application
withDescriptorMapper: layoutDescriptorMapper]];
SKDescriptorMapper* layoutDescriptorMapper =
[[SKDescriptorMapper alloc] initWithDefaults];
[FlipperKitLayoutComponentKitSupport
setUpWithDescriptorMapper:layoutDescriptorMapper];
[client addPlugin:[[FlipperKitLayoutPlugin alloc]
initWithRootNode:application
withDescriptorMapper:layoutDescriptorMapper]];
[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:[FlipperKitReactPlugin new]];
[client start];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryBoard" bundle:nil];
MainViewController *mainViewController = [storyboard instantiateViewControllerWithIdentifier:@"MainViewController"];
UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"MainStoryBoard"
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.translucent = NO;
[_window setRootViewController: [[UINavigationController alloc] initWithRootViewController: mainViewController]];
[_window
setRootViewController:[[UINavigationController alloc]
initWithRootViewController:mainViewController]];
[_window makeKeyAndVisible];
NSLog(@"Hello from Flipper in an Objc app!");

View File

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

View File

@@ -8,49 +8,54 @@
#import "CommunicationDemoViewController.h"
#import <FlipperKitExamplePlugin/FlipperKitExamplePlugin.h>
@interface CommunicationDemoViewController()<FlipperKitExampleCommunicationResponderDelegate>
@property (strong, nonatomic) NSMutableArray<NSString *> *messagesToDisplay;
@property (weak, nonatomic) IBOutlet UITextField *messageTextField;
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@interface CommunicationDemoViewController ()<
FlipperKitExampleCommunicationResponderDelegate>
@property(strong, nonatomic) NSMutableArray<NSString*>* messagesToDisplay;
@property(weak, nonatomic) IBOutlet UITextField* messageTextField;
@property(weak, nonatomic) IBOutlet UITableView* tableView;
@end
@implementation CommunicationDemoViewController
- (void)viewDidLoad {
[super viewDidLoad];
[FlipperKitExamplePlugin sharedInstance].delegate = self;
[super viewDidLoad];
[FlipperKitExamplePlugin sharedInstance].delegate = self;
}
- (IBAction)tappedTriggerNotification:(UIButton *)sender {
[[FlipperKitExamplePlugin sharedInstance] triggerNotification];
- (IBAction)tappedTriggerNotification:(UIButton*)sender {
[[FlipperKitExamplePlugin sharedInstance] triggerNotification];
}
- (IBAction)tappedSendMessage:(UIButton *)sender {
if (self.messageTextField.text.length > 0) {
[[FlipperKitExamplePlugin sharedInstance] sendMessage:self.messageTextField.text];
}
}
- (nonnull UITableViewCell *)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"reusableCell"];
cell.textLabel.text = self.messagesToDisplay[indexPath.row];
return cell;
}
- (NSInteger)tableView:(nonnull UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.messagesToDisplay.count;
}
- (void)messageReceived:(NSString *)msg {
if (msg) {
if (!self.messagesToDisplay) {
self.messagesToDisplay = @[].mutableCopy;
}
[self.messagesToDisplay addObject:msg];
dispatch_async(dispatch_get_main_queue(), ^{
[self.tableView reloadData];
});
- (IBAction)tappedSendMessage:(UIButton*)sender {
if (self.messageTextField.text.length > 0) {
[[FlipperKitExamplePlugin sharedInstance]
sendMessage:self.messageTextField.text];
}
}
- (nonnull UITableViewCell*)tableView:(nonnull UITableView*)tableView
cellForRowAtIndexPath:(nonnull NSIndexPath*)indexPath {
UITableViewCell* cell =
[tableView dequeueReusableCellWithIdentifier:@"reusableCell"];
cell.textLabel.text = self.messagesToDisplay[indexPath.row];
return cell;
}
- (NSInteger)tableView:(nonnull UITableView*)tableView
numberOfRowsInSection:(NSInteger)section {
return self.messagesToDisplay.count;
}
- (void)messageReceived:(NSString*)msg {
if (msg) {
if (!self.messagesToDisplay) {
self.messagesToDisplay = @[].mutableCopy;
}
[self.messagesToDisplay addObject:msg];
dispatch_async(dispatch_get_main_queue(), ^{
[self.tableView reloadData];
});
}
}
@end

View File

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

View File

@@ -18,66 +18,100 @@
self.navigationItem.title = @"Network";
}
- (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) {
if (error && !data) {
return;
}
NSLog(@"Got Image");
}] resume];
- (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) {
if (error && !data) {
return;
}
NSLog(@"Got Image");
}] resume];
}
- (IBAction)tappedPOSTAPI:(UIButton *)sender {
NSString *post = @"https://demo9512366.mockable.io/FlipperPost";
NSURL *url = [NSURL URLWithString:post];
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL: url];
- (IBAction)tappedPOSTAPI:(UIButton*)sender {
NSString* post = @"https://demo9512366.mockable.io/FlipperPost";
NSURL* url = [NSURL URLWithString:post];
NSMutableURLRequest* urlRequest = [NSMutableURLRequest requestWithURL:url];
[urlRequest addValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[urlRequest addValue:@"application/json" forHTTPHeaderField:@"Accept"];
NSDictionary *mapData = [[NSDictionary alloc] initWithObjectsAndKeys: @"Flipper", @"app",
@"Its awesome", @"remarks",
nil];
NSError *error = nil;
NSData *postData = [NSJSONSerialization dataWithJSONObject:mapData options:0 error:&error];
NSDictionary* mapData =
[[NSDictionary alloc] initWithObjectsAndKeys:@"Flipper",
@"app",
@"Its awesome",
@"remarks",
nil];
NSError* error = nil;
NSData* postData = [NSJSONSerialization dataWithJSONObject:mapData
options:0
error:&error];
[urlRequest setHTTPBody:postData];
[urlRequest setHTTPMethod:@"POST"];
__weak NetworkViewController *weakSelf = self;
[[[NSURLSession sharedSession] dataTaskWithRequest:urlRequest completionHandler:^(NSData *_Nullable data, NSURLResponse *_Nullable response, NSError *_Nullable dataTaskError) {
__weak NetworkViewController* weakSelf = self;
[[[NSURLSession sharedSession]
dataTaskWithRequest:urlRequest
completionHandler:^(
NSData* _Nullable data,
NSURLResponse* _Nullable response,
NSError* _Nullable dataTaskError) {
if (dataTaskError || !data) {
[weakSelf
showAlertWithMessage:@"Received error in POST API response"];
return;
}
NSDictionary* dict =
[NSJSONSerialization JSONObjectWithData:data
options:0
error:&dataTaskError];
NSLog(@"MSG-POST: %@", dict[@"msg"]);
if (dataTaskError || !data) {
[weakSelf showAlertWithMessage:@"Received error in POST API response"];
return;
}
NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:0 error:&dataTaskError];
NSLog(@"MSG-POST: %@", dict[@"msg"]);
[weakSelf showAlertWithMessage:@"Received response from POST API"];
}] resume];
[weakSelf showAlertWithMessage:@"Received response from POST API"];
}] resume];
}
- (IBAction)tappedGetAPI:(UIButton *)sender {
__weak NetworkViewController *weakSelf = self;
[[[NSURLSession sharedSession] dataTaskWithURL:[NSURL URLWithString:@"https://demo9512366.mockable.io/FlipperGet"] completionHandler:^(NSData *_Nullable data, NSURLResponse *_Nullable response, NSError *_Nullable error) {
if (error || !data) {
[weakSelf showAlertWithMessage:@"Received error in GET API response"];
return;
}
NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
NSLog(@"MSG-GET: %@", dict[@"msg"]);
[weakSelf showAlertWithMessage:@"Received response from GET API"];
}] resume];
- (IBAction)tappedGetAPI:(UIButton*)sender {
__weak NetworkViewController* weakSelf = self;
[[[NSURLSession sharedSession]
dataTaskWithURL:
[NSURL URLWithString:@"https://demo9512366.mockable.io/FlipperGet"]
completionHandler:^(
NSData* _Nullable data,
NSURLResponse* _Nullable response,
NSError* _Nullable error) {
if (error || !data) {
[weakSelf showAlertWithMessage:@"Received error in GET API response"];
return;
}
NSDictionary* dict = [NSJSONSerialization JSONObjectWithData:data
options:0
error:&error];
NSLog(@"MSG-GET: %@", dict[@"msg"]);
[weakSelf showAlertWithMessage:@"Received response from GET API"];
}] resume];
}
- (void)showAlertWithMessage:(nonnull NSString *)msg {
- (void)showAlertWithMessage:(nonnull NSString*)msg {
dispatch_async(dispatch_get_main_queue(), ^{
UIAlertController *alertController = [self alertControllerForMessage:msg];
UIAlertController* alertController = [self alertControllerForMessage:msg];
[self presentViewController:alertController animated:true completion:nil];
});
}
- (UIAlertController *)alertControllerForMessage:(nonnull NSString *)msg {
UIAlertController *controller = [UIAlertController alertControllerWithTitle:@"Flipper" message:msg preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *action = [UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleDefault handler:nil];
- (UIAlertController*)alertControllerForMessage:(nonnull NSString*)msg {
UIAlertController* controller =
[UIAlertController alertControllerWithTitle:@"Flipper"
message:msg
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* action =
[UIAlertAction actionWithTitle:@"Ok"
style:UIAlertActionStyleDefault
handler:nil];
[controller addAction:action];
return controller;
}

View File

@@ -20,19 +20,19 @@
@interface RootViewController ()
@property (strong, nonatomic) CKComponentHostingView *rootCKHostingView;
@property(strong, nonatomic) CKComponentHostingView* rootCKHostingView;
@end
@implementation RootViewController
- (instancetype)init
{
- (instancetype)init {
if (self = [super init]) {
_rootCKHostingView = [[CKComponentHostingView alloc]
initWithComponentProvider:[self class]
sizeRangeProvider:
[CKComponentFlexibleSizeRangeProvider providerWithFlexibility:CKComponentSizeRangeFlexibleHeight]];
initWithComponentProvider:[self class]
sizeRangeProvider:[CKComponentFlexibleSizeRangeProvider
providerWithFlexibility:
CKComponentSizeRangeFlexibleHeight]];
[self.view addSubview:_rootCKHostingView];
[self loadViewIfNeeded];
@@ -46,54 +46,45 @@
self.edgesForExtendedLayout = UIRectEdgeNone;
}
- (void)viewDidLayoutSubviews
{
- (void)viewDidLayoutSubviews {
[super viewDidLayoutSubviews];
_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
newWithComponent:
[CKFlexboxComponent
newWithView:{
}
size:{}
style:{}
children: {
{
[CKButtonComponent
newWithAction:nil
options:{
.titles = @"Purple",
.titleColors = UIColor.purpleColor,
}
]
},
{
[CKButtonComponent
newWithAction:nil
options:{
.titles = @"Brown",
.titleColors = UIColor.brownColor,
}
]
},
{
[CKButtonComponent
newWithAction:nil
options:{
.titles = @"Cyan",
.titleColors = UIColor.cyanColor,
}
]
},
}]
background:
[CKImageComponent
newWithImage:[UIImage imageNamed:@"sonarpattern"]
attributes:{}
size:{}]];
newWithComponent:
[CKFlexboxComponent newWithView:{}
size:{}
style:{}
children:{
{[CKButtonComponent
newWithAction:nil
options:{
.titles = @"Purple",
.titleColors =
UIColor.purpleColor,
}]},
{[CKButtonComponent
newWithAction:nil
options:{
.titles = @"Brown",
.titleColors =
UIColor.brownColor,
}]},
{[CKButtonComponent
newWithAction:nil
options:{
.titles = @"Cyan",
.titleColors =
UIColor.cyanColor,
}]},
}]
background:[CKImageComponent
newWithImage:[UIImage imageNamed:@"sonarpattern"]
attributes:{}
size:{}]];
}
@end

View File

@@ -8,22 +8,23 @@
#import "UserDefaultsViewController.h"
@interface UserDefaultsViewController ()
@property (weak, nonatomic) IBOutlet UITextField *valueTextField;
@property (weak, nonatomic) IBOutlet UITextField *keyTextField;
@property (nonatomic, strong) NSUserDefaults *userDefaults;
@property(weak, nonatomic) IBOutlet UITextField* valueTextField;
@property(weak, nonatomic) IBOutlet UITextField* keyTextField;
@property(nonatomic, strong) NSUserDefaults* userDefaults;
@end
@implementation UserDefaultsViewController
- (instancetype)initWithCoder:(NSCoder *)aDecoder {
if (self = [super initWithCoder:aDecoder]) {
_userDefaults = [[NSUserDefaults alloc] initWithSuiteName:nil];
}
return self;
- (instancetype)initWithCoder:(NSCoder*)aDecoder {
if (self = [super initWithCoder:aDecoder]) {
_userDefaults = [[NSUserDefaults alloc] initWithSuiteName:nil];
}
return self;
}
- (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

View File

@@ -9,8 +9,9 @@
#import "AppDelegate.h"
int main(int argc, char * argv[]) {
int main(int argc, char* argv[]) {
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
return UIApplicationMain(
argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}