iOS: Update diagnostic screen on state update
Summary: Update the diagnostic screen whenever the sonar state changes. Reviewed By: priteshrnandgaonkar Differential Revision: D9218765 fbshipit-source-id: 654a35e309cb43df18bc8c8a645d469eddc1031d
This commit is contained in:
committed by
Facebook Github Bot
parent
21888157df
commit
d8e5e31c9a
@@ -7,11 +7,13 @@
|
||||
*/
|
||||
#ifdef FB_SONARKIT_ENABLED
|
||||
|
||||
#include "FlipperStateUpdateListener.h"
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
@interface FlipperDiagnosticsViewController : UIViewController
|
||||
@interface FlipperDiagnosticsViewController : UIViewController <FlipperStateUpdateListener>
|
||||
@property(strong, nonatomic) UIScrollView *scrollView;
|
||||
@property(strong, nonatomic) UILabel *stateLabel;
|
||||
- (void)onUpdate;
|
||||
@end
|
||||
|
||||
#endif
|
||||
|
||||
@@ -12,8 +12,9 @@
|
||||
text.text = @"Flipper Diagnostics";
|
||||
[self.view addSubview:text];
|
||||
|
||||
self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 50, self.view.frame.size.width, self.view.frame.size.height - 50)];
|
||||
self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 50, self.view.frame.size.width, self.view.frame.size.height - 100)];
|
||||
self.stateLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 1000)];
|
||||
|
||||
self.stateLabel.numberOfLines = 0;
|
||||
self.stateLabel.text = [[SonarClient sharedClient] getState];
|
||||
[self.scrollView addSubview:self.stateLabel];
|
||||
@@ -22,8 +23,23 @@
|
||||
}
|
||||
|
||||
- (void)onUpdate {
|
||||
self.stateLabel.text = [[SonarClient sharedClient] getState];
|
||||
self.scrollView.contentSize = self.stateLabel.frame.size;
|
||||
FlipperDiagnosticsViewController __weak *weakSelf = self;
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
FlipperDiagnosticsViewController *strongSelf = weakSelf;
|
||||
if (!strongSelf) {
|
||||
return;
|
||||
}
|
||||
NSString *state = [[SonarClient sharedClient] getState];
|
||||
strongSelf.stateLabel.text = state;
|
||||
[strongSelf.stateLabel sizeToFit];
|
||||
strongSelf.scrollView.contentSize = strongSelf.stateLabel.frame.size;
|
||||
});
|
||||
}
|
||||
|
||||
- (void)viewWillAppear:(BOOL)animated {
|
||||
[super viewWillAppear:animated];
|
||||
id<FlipperStateUpdateListener> weakSelf = self;
|
||||
[[SonarClient sharedClient] subscribeForUpdates:weakSelf];
|
||||
}
|
||||
|
||||
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
|
||||
|
||||
14
iOS/SonarKit/FlipperStateUpdateListener.h
Normal file
14
iOS/SonarKit/FlipperStateUpdateListener.h
Normal file
@@ -0,0 +1,14 @@
|
||||
/*
|
||||
* Copyright (c) 2018-present, Facebook, Inc.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the LICENSE
|
||||
* file in the root directory of this source tree.
|
||||
*
|
||||
*/
|
||||
#ifdef FB_SONARKIT_ENABLED
|
||||
|
||||
@protocol FlipperStateUpdateListener
|
||||
- (void)onUpdate;
|
||||
@end
|
||||
|
||||
#endif
|
||||
19
iOS/SonarKit/SKStateUpdateCPPWrapper.h
Normal file
19
iOS/SonarKit/SKStateUpdateCPPWrapper.h
Normal file
@@ -0,0 +1,19 @@
|
||||
#ifdef FB_SONARKIT_ENABLED
|
||||
|
||||
#include <Sonar/SonarStateUpdateListener.h>
|
||||
#import "FlipperStateUpdateListener.h"
|
||||
|
||||
/*
|
||||
* This class exists to bridge the gap between Objective C and C++.
|
||||
* A SKStateUpdateCPPWrapper instance allows for wrapping an Objective-C object
|
||||
* and passing it to the pure C++ SonarClient, so it can be triggered when updates occur.
|
||||
*/
|
||||
class SKStateUpdateCPPWrapper : public SonarStateUpdateListener {
|
||||
public:
|
||||
SKStateUpdateCPPWrapper(id<FlipperStateUpdateListener> delegate_);
|
||||
void onUpdate();
|
||||
private:
|
||||
__weak id<FlipperStateUpdateListener> delegate_;
|
||||
};
|
||||
|
||||
#endif
|
||||
16
iOS/SonarKit/SKStateUpdateCPPWrapper.mm
Normal file
16
iOS/SonarKit/SKStateUpdateCPPWrapper.mm
Normal file
@@ -0,0 +1,16 @@
|
||||
#ifdef FB_SONARKIT_ENABLED
|
||||
|
||||
#include "SKStateUpdateCPPWrapper.h"
|
||||
|
||||
SKStateUpdateCPPWrapper::SKStateUpdateCPPWrapper(id<FlipperStateUpdateListener> controller) {
|
||||
delegate_ = controller;
|
||||
}
|
||||
|
||||
void SKStateUpdateCPPWrapper::onUpdate() {
|
||||
if (!delegate_) {
|
||||
return;
|
||||
}
|
||||
[delegate_ onUpdate];
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -8,6 +8,7 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import "SonarPlugin.h"
|
||||
#import "FlipperStateUpdateListener.h"
|
||||
|
||||
/**
|
||||
Represents a connection between the Sonar desktop och client side. Manages the lifecycle of attached
|
||||
@@ -50,6 +51,11 @@ Get the current state of the sonar client
|
||||
*/
|
||||
- (NSString *)getState;
|
||||
|
||||
/**
|
||||
Subscribe a ViewController to state update change notifications
|
||||
*/
|
||||
- (void)subscribeForUpdates:(id<FlipperStateUpdateListener>)controller;
|
||||
|
||||
// initializers are disabled. You must use `+[SonarClient sharedClient]` instance.
|
||||
- (instancetype)init NS_UNAVAILABLE;
|
||||
+ (instancetype)new NS_UNAVAILABLE;
|
||||
|
||||
@@ -13,6 +13,8 @@
|
||||
#include <folly/io/async/EventBase.h>
|
||||
#include <folly/io/async/ScopedEventBaseThread.h>
|
||||
#import <UIKit/UIKit.h>
|
||||
#include "SKStateUpdateCPPWrapper.h"
|
||||
#import "FlipperDiagnosticsViewController.h"
|
||||
|
||||
#if !TARGET_OS_SIMULATOR
|
||||
//#import "SKPortForwardingServer.h"
|
||||
@@ -125,6 +127,11 @@ using WrapperPlugin = facebook::sonar::SonarCppWrapperPlugin;
|
||||
return @(_cppClient->getState().c_str());
|
||||
}
|
||||
|
||||
- (void)subscribeForUpdates:(id<FlipperStateUpdateListener>)controller {
|
||||
auto stateListener = std::make_shared<SKStateUpdateCPPWrapper>(controller);
|
||||
_cppClient->setStateListener(stateListener);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user