Skip to content

Commit

Permalink
Make RCTPerfMonitor TurboModule-compatible
Browse files Browse the repository at this point in the history
Summary:
See title.

Changelog:
[iOS][Added] - Make RCTPerfMonitor TurboModule-compatible

Reviewed By: shergin

Differential Revision: D18145947

fbshipit-source-id: df2f0d60a4924f094cc4ec311b6bf570fb9fb7e1
  • Loading branch information
RSNara authored and facebook-github-bot committed Nov 1, 2019
1 parent 7233ae4 commit 809d010
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 22 deletions.
3 changes: 3 additions & 0 deletions React/CoreModules/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ rn_apple_library(
) + react_module_plugin_providers(
name = "AppState",
native_class_func = "RCTAppStateCls",
) + react_module_plugin_providers(
name = "PerfMonitor",
native_class_func = "RCTPerfMonitorCls",
),
plugins_header = "FBCoreModulesPlugins.h",
preprocessor_flags = OBJC_ARC_PREPROCESSOR_FLAGS + get_debug_preprocessor_flags() + rn_extra_build_flags() + [
Expand Down
1 change: 1 addition & 0 deletions React/CoreModules/CoreModulesPlugins.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Class RCTTimingCls(void) __attribute__((used));
Class RCTStatusBarManagerCls(void) __attribute__((used));
Class RCTKeyboardObserverCls(void) __attribute__((used));
Class RCTAppStateCls(void) __attribute__((used));
Class RCTPerfMonitorCls(void) __attribute__((used));

#ifdef __cplusplus
}
Expand Down
1 change: 1 addition & 0 deletions React/CoreModules/CoreModulesPlugins.mm
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Class RCTCoreModulesClassProvider(const char *name) {
{"StatusBarManager", RCTStatusBarManagerCls},
{"KeyboardObserver", RCTKeyboardObserverCls},
{"AppState", RCTAppStateCls},
{"PerfMonitor", RCTPerfMonitorCls},
};

auto p = sCoreModuleClassMap.find(name);
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#import "RCTFPSGraph.h"

#import "RCTAssert.h"
#import <React/RCTAssert.h>

#if RCT_DEV

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,31 @@
* LICENSE file in the root directory of this source tree.
*/

#import "RCTDefines.h"
#import <React/RCTDefines.h>

#import "CoreModulesPlugins.h"

#if RCT_DEV

#import <dlfcn.h>

#import <mach/mach.h>

#import "RCTBridge.h"
#import "RCTDevSettings.h"
#import "RCTFPSGraph.h"
#import "RCTInvalidating.h"
#import "RCTJavaScriptExecutor.h"
#import "RCTPerformanceLogger.h"
#import "RCTRootView.h"
#import "RCTUIManager.h"
#import "RCTBridge+Private.h"
#import "RCTUtils.h"

#if __has_include("RCTDevMenu.h")
#import "RCTDevMenu.h"
#import <React/RCTDevSettings.h>

#import <React/RCTBridge.h>
#import <React/RCTFPSGraph.h>
#import <React/RCTInvalidating.h>
#import <React/RCTJavaScriptExecutor.h>
#import <React/RCTPerformanceLogger.h>
#import <React/RCTRootView.h>
#import <React/RCTUIManager.h>
#import <React/RCTBridge+Private.h>
#import <React/RCTUtils.h>
#import <ReactCommon/RCTTurboModule.h>

#if __has_include(<React/RCTDevMenu.h>)
#import <React/RCTDevMenu.h>
#endif

static NSString *const RCTPerfMonitorCellIdentifier = @"RCTPerfMonitorCellIdentifier";
Expand All @@ -46,7 +50,7 @@ static BOOL RCTJSCSetOption(const char *option)
*
* JSC::Options::setOptions - JavaScriptCore/runtime/Options.h
*/
setOption = dlsym(RTLD_DEFAULT, "_ZN3JSC7Options9setOptionEPKc");
setOption = reinterpret_cast<RCTJSCSetOptionType>(dlsym(RTLD_DEFAULT, "_ZN3JSC7Options9setOptionEPKc"));

if (RCT_DEBUG && setOption == NULL) {
RCTLogWarn(@"The symbol used to enable JSC runtime options is not available in this iOS version");
Expand All @@ -68,13 +72,13 @@ static vm_size_t RCTGetResidentMemorySize(void)
kern_return_t kernelReturn = task_info(mach_task_self(), TASK_VM_INFO, (task_info_t) &vmInfo, &count);
if(kernelReturn == KERN_SUCCESS) {
memoryUsageInByte = (vm_size_t) vmInfo.phys_footprint;
}
}
return memoryUsageInByte;
}

@interface RCTPerfMonitor : NSObject <RCTBridgeModule, RCTInvalidating, UITableViewDataSource, UITableViewDelegate>
@interface RCTPerfMonitor : NSObject <RCTBridgeModule, RCTTurboModule, RCTInvalidating, UITableViewDataSource, UITableViewDelegate>

#if __has_include("RCTDevMenu.h")
#if __has_include(<React/RCTDevMenu.h>)
@property (nonatomic, strong, readonly) RCTDevMenuItem *devMenuItem;
#endif
@property (nonatomic, strong, readonly) UIPanGestureRecognizer *gestureRecognizer;
Expand All @@ -91,7 +95,7 @@ @interface RCTPerfMonitor : NSObject <RCTBridgeModule, RCTInvalidating, UITableV
@end

@implementation RCTPerfMonitor {
#if __has_include("RCTDevMenu.h")
#if __has_include(<React/RCTDevMenu.h>)
RCTDevMenuItem *_devMenuItem;
#endif
UIPanGestureRecognizer *_gestureRecognizer;
Expand Down Expand Up @@ -140,7 +144,7 @@ - (void)setBridge:(RCTBridge *)bridge
{
_bridge = bridge;

#if __has_include("RCTDevMenu.h")
#if __has_include(<React/RCTDevMenu.h>)
[_bridge.devMenu addItem:self.devMenuItem];
#endif
}
Expand All @@ -150,7 +154,7 @@ - (void)invalidate
[self hide];
}

#if __has_include("RCTDevMenu.h")
#if __has_include(<React/RCTDevMenu.h>)
- (RCTDevMenuItem *)devMenuItem
{
if (!_devMenuItem) {
Expand Down Expand Up @@ -576,3 +580,11 @@ - (CGFloat)tableView:(__unused UITableView *)tableView
@end

#endif

Class RCTPerfMonitorCls(void) {
#if RCT_DEV
return RCTPerfMonitor.class;
#else
return nil;
#endif
}

0 comments on commit 809d010

Please sign in to comment.