When creating a custom user interface component in Swift, how can I access reactTagto trigger the React Native event?
Using the following code to create a custom component in Swift with a button: When the button is clicked, using bridge.eventDispatcherto sendInputEventWithNameshould trigger an event in the React Native JavaScript code. This is done by passing the responseTag as part of the event dictionary. However, it is not clear to me how to access the responseTag property or even where it is available.
(Digging around a bit, it seems to be present on something called RCTShadowView, however, responseTag is always nilon my shadowView)
Swift
import UIKit
@objc(FooView)
class FooView: UIView {
@objc var bridge: RCTBridge!
required override init(frame: CGRect) {
super.init(frame: frame)
let button = UIButton(frame: CGRect(x: 10, y: 10, width: 244, height: 244))
button.addTarget(self, action: "buttonClicked:", forControlEvents: .TouchUpInside)
self.addSubview(button)
}
func buttonClicked(sender: AnyObject?) {
let event = [
"target": "",
]
self.bridge.eventDispatcher.sendInputEventWithName("topChange", body: event)
}
}
Goal c
#import "RCTBridgeModule.h"
#import "RCTViewManager.h"
#import "FooProj-Swift.h"
@interface RCTFooViewManager : RCTViewManager
@end
@implementation RCTFooViewManager
RCT_EXPORT_MODULE()
- (UIView *)view
{
FooView* fooView = [[FooView alloc] init];
fooView.bridge = self.bridge;
fooView.shadowView = self.shadowView;
return fooView;
}
@end