I have the following issue. I know that when using Objective-C to export a Manager method you can use the RCT_EXPORT_METHOD and you can get the UIView associated with the reactTag like so:
RCT_EXPORT_METHOD(scrollTo:(noull NSNumber *)reactTag
offsetX:(CGFloat)x
offsetY:(CGFloat)y
animated:(BOOL)animated)
{
[self.bridge.uiManager addUIBlock:
^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry){
UIView *view = viewRegistry[reactTag];
if ([view conformsToProtocol:@protocol(RCTScrollableProtocol)]) {
[(id<RCTScrollableProtocol>)view scrollToOffset:(CGPoint){x, y} animated:animated];
} else {
RCTLogError(@"tried to scrollTo: on non-RCTScrollableProtocol view %@ "
"with tag #%@", view, reactTag);
}
}];
}
I am trying to do the same with a React Native Component in Swift but am unable to get the equivalent for the above code in Swift.
MyComponent.h
#import "RCTView.h"
#import "RCTBridgeModule.h"
@interface MyComponent : RCTView
@property (nonatomic, assign) NSString *config;
@end
MyComponent.m
#import "RNBarChart.h"
#import "RCTBridge.h"
#import "RCTViewManager.h"
#import "RCTUIManager.h"
@interface RCT_EXTERN_MODULE(RNBarChartSwift, RCTViewManager)
RCT_EXPORT_VIEW_PROPERTY(config, NSString);
RCT_EXTERN_METHOD(setX:(noull NSNumber *)reactTag value:(CGFloat *)v);
@end
MyComponent.swift
@objc(MyComponent)
class MyComponent : UIView {
override init(frame: CGRect) {
super.init(frame: frame);
self.frame = frame;
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented");
}
... rest of the code
MyComponentManager.swift
import Foundation
@objc(MyComponentSwift)
class MyComponentManager : RCTViewManager {
override func view() -> UIView! {
retu MyComponent();
}
@objc func setVisibleXRangeMaximum(reactTag: CGFloat, value: CGFloat) {
// How to get UIView associated with reactTag here?
}
}
Bridging-Header.h
#import "RCTBridge.h"
#import "RCTViewManager.h"
#import "RCTUIManager.h"
#import "UIView+React.h"
