Skip to content

Commit b275a39

Browse files
authored
fix(ios): build failure when using custom native marks (#102)
Build fails on importing `RNPeroformance.h` in Objective-C file, because `chrono` is a part of STL library which cannot be found in plain Objective-C files. The idea of fix is to prevent it to be included in a header. `RNPerformanceEntryWasAddedNotification` declaration and initialization were split to prevent build failure as well.
1 parent 09ace72 commit b275a39

File tree

4 files changed

+27
-16
lines changed

4 files changed

+27
-16
lines changed

packages/react-native-performance/ios/RNPerformance.h

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,4 @@
11
#import "RNPerformanceEntry.h"
2-
#include <chrono>
3-
4-
static int64_t RNPerformanceGetTimestamp()
5-
{
6-
// Copied from https://github.com/facebook/react-native/blob/main/React/CxxBridge/RCTJSIExecutorRuntimeInstaller.mm#L25
7-
auto time = std::chrono::steady_clock::now();
8-
auto duration = std::chrono::duration_cast<std::chrono::nanoseconds>(
9-
time.time_since_epoch())
10-
.count();
11-
12-
constexpr double NANOSECONDS_IN_MILLISECOND = 1000000.0;
13-
14-
return duration / NANOSECONDS_IN_MILLISECOND;
15-
}
16-
17-
NSString * _Nonnull const RNPerformanceEntryWasAddedNotification = @"RNPerformanceEntryWasAdded";
182

193
@interface RNPerformance: NSObject
204

packages/react-native-performance/ios/RNPerformance.mm

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#import "RNPerformance.h"
22
#import "RNPerformanceEntry.h"
3+
#import "RNPerformanceUtils.h"
4+
5+
NSString *const RNPerformanceEntryWasAddedNotification = @"RNPerformanceEntryWasAdded";
36

47
@implementation RNPerformance
58
{

packages/react-native-performance/ios/RNPerformanceManager.mm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#import <QuartzCore/QuartzCore.h>
55
#import <React/RCTRootView.h>
66
#import <React/RCTPerformanceLogger.h>
7+
#import "RNPerformanceUtils.h"
78

89
#ifdef RCT_NEW_ARCH_ENABLED
910
#import <RNPerformanceSpec/RNPerformanceSpec.h>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#ifndef RNPerformanceUtils_h
2+
#define RNPerformanceUtils_h
3+
4+
#import <React/RCTDefines.h>
5+
6+
RCT_EXTERN NSString * _Nonnull const RNPerformanceEntryWasAddedNotification;
7+
8+
#include <chrono>
9+
10+
static int64_t RNPerformanceGetTimestamp()
11+
{
12+
// Copied from https://github.com/facebook/react-native/blob/main/React/CxxBridge/RCTJSIExecutorRuntimeInstaller.mm#L25
13+
auto time = std::chrono::steady_clock::now();
14+
auto duration = std::chrono::duration_cast<std::chrono::nanoseconds>(
15+
time.time_since_epoch())
16+
.count();
17+
18+
constexpr double NANOSECONDS_IN_MILLISECOND = 1000000.0;
19+
20+
return duration / NANOSECONDS_IN_MILLISECOND;
21+
}
22+
23+
#endif /* RNPerformanceUtils_h */

0 commit comments

Comments
 (0)