|
10 | 10 | #import <cassert>
|
11 | 11 |
|
12 | 12 | #import <React/RCTBridge+Private.h>
|
| 13 | +#import <React/RCTPerformanceLogger.h> |
13 | 14 | #import <React/RCTBridgeModule.h>
|
14 | 15 | #import <React/RCTCxxModule.h>
|
15 | 16 | #import <React/RCTLog.h>
|
@@ -67,19 +68,45 @@ - (instancetype)initWithRuntime:(jsi::Runtime *)runtime
|
67 | 68 |
|
68 | 69 | __strong __typeof(self) strongSelf = weakSelf;
|
69 | 70 |
|
| 71 | + auto moduleName = name.c_str(); |
| 72 | + auto moduleWasNotInitialized = ![strongSelf moduleIsInitialized:moduleName]; |
| 73 | + if (moduleWasNotInitialized) { |
| 74 | + [strongSelf->_bridge.performanceLogger markStartForTag:RCTPLTurboModuleSetup]; |
| 75 | + } |
| 76 | + |
70 | 77 | /**
|
71 | 78 | * By default, all TurboModules are long-lived.
|
72 | 79 | * Additionally, if a TurboModule with the name `name` isn't found, then we
|
73 | 80 | * trigger an assertion failure.
|
74 | 81 | */
|
75 |
| - return [strongSelf provideTurboModule: name.c_str()]; |
| 82 | + auto turboModule = [strongSelf provideTurboModule:moduleName]; |
| 83 | + |
| 84 | + if (moduleWasNotInitialized && [strongSelf moduleIsInitialized:moduleName]) { |
| 85 | + [strongSelf->_bridge.performanceLogger markStopForTag:RCTPLTurboModuleSetup]; |
| 86 | + [strongSelf notifyAboutTurboModuleSetup:moduleName]; |
| 87 | + } |
| 88 | + |
| 89 | + return turboModule; |
76 | 90 | };
|
77 | 91 |
|
78 | 92 | _binding = std::make_shared<react::TurboModuleBinding>(moduleProvider);
|
79 | 93 | }
|
80 | 94 | return self;
|
81 | 95 | }
|
82 | 96 |
|
| 97 | +- (void)notifyAboutTurboModuleSetup:(const char*)name { |
| 98 | + NSString *moduleName = [[NSString alloc] initWithUTF8String:name]; |
| 99 | + if (moduleName) { |
| 100 | + int64_t setupTime = [self->_bridge.performanceLogger durationForTag:RCTPLTurboModuleSetup]; |
| 101 | + [[NSNotificationCenter defaultCenter] postNotificationName:RCTDidSetupModuleNotification |
| 102 | + object:nil |
| 103 | + userInfo:@{ |
| 104 | + RCTDidSetupModuleNotificationModuleNameKey: moduleName, |
| 105 | + RCTDidSetupModuleNotificationSetupTimeKey: @(setupTime) |
| 106 | + }]; |
| 107 | + } |
| 108 | +} |
| 109 | + |
83 | 110 | /**
|
84 | 111 | * Given a name for a TurboModule, return a C++ object which is the instance
|
85 | 112 | * of that TurboModule C++ class. This class wraps the TurboModule's ObjC instance.
|
|
0 commit comments