react-native-macos/RNTester/Swizzle_RCTFabricSurface.m

51 строка
1.4 KiB
Mathematica
Исходник Обычный вид История

/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#ifdef RN_FABRIC_ENABLED
#import <objc/runtime.h>
#import <React/RCTFabricSurface.h>
// FIXME: remove when resolved https://github.com/facebook/react-native/issues/23910
@implementation RCTFabricSurface (SwizzleMeTimbers)
+ (void)load {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
Class class = [self class];
SEL originalSelector = @selector((start));
SEL swizzledSelector = @selector(xxx_start);
Method originalMethod = class_getInstanceMethod(class, originalSelector);
Method swizzledMethod = class_getInstanceMethod(class, swizzledSelector);
BOOL didAddMethod =
class_addMethod(class,
originalSelector,
method_getImplementation(swizzledMethod),
method_getTypeEncoding(swizzledMethod));
if (didAddMethod) {
class_replaceMethod(class,
swizzledSelector,
method_getImplementation(originalMethod),
method_getTypeEncoding(originalMethod));
} else {
method_exchangeImplementations(originalMethod, swizzledMethod);
}
});
}
#pragma mark - Method Swizzling
- (void)xxx_start {
NSLog(@"RCTSurface start: %@", self);
}
@end
#endif