-
Notifications
You must be signed in to change notification settings - Fork 24.8k
Closed
Labels
StaleThere has been a lack of activity on this issue and it may be closed soon.There has been a lack of activity on this issue and it may be closed soon.
Description
Is this a bug report?
Not confirm.
Have you read the Contributing Guidelines?
Yes, I have follow all sept of this document of how to use RCTEventEmitter to send event from Native to JS.but still meet this error.
Environment
react-native -v
: 0.45.1node -v
: 8.1.2npm -v
: 5.30
Then, specify:
- Target Platform: iOS
- Development Operating System:macOS
- Build tools:iOS 10
Steps to Reproduce
- Create a helper class that can emit event from iOS native to JS according to the document.
- invoke sendEventWithName method any where in the code we need to emit event.
Expected Behavior
JS will receive the event and catch the data.
Actual Behavior
[tid:com.facebook.react.ShadowQueue] Exception 'bridge is not set.
This is probably because you've explicitly synthesized the bridge in RCTCameraEvent,
even though it's inherited from RCTEventEmitter.'
was thrown while invoking capture on target CameraManager with params (
{
audio = 0;
barCodeTypes = (
);
description = "";
mirrorImage = 0;
mode = 1;
playSoundOnCapture = 1;
preferredTimeScale = 30;
quality = 0;
target = 1;
title = "";
totalSeconds = 10;
type = 1;
},
3892,
3893
)
Reproducible Demo
EventHelper.h
#import <React/RCTBridgeModule.h>
#import <React/RCTEventEmitter.h>
@interface RCTCameraEvent : RCTEventEmitter<RCTBridgeModule>
@end
EventHelper.m
#import "RCTCameraEvent.h"
@implementation RCTCameraEvent
RCT_EXPORT_MODULE();
- (NSArray<NSString *> *)supportedEvents
{
return @[@"CustomEvent"];
}
- (void)sendEvent2JS
{
[self sendEventWithName:@"CustomEvent" body:@{@"name": @"111"}];
}
@end
invoke send event method in code
RCTCameraEvent * cameraEvent = [[RCTCameraEvent alloc]init];
[cameraEvent sendEvent2JS];
All I want to do is create a helper class so that I can invoke the send event method anywhere I need.
I have look into many issues (#8714) and search related answer on Google and stackoverflow but still can not found a perfect solution using RCTEventEmitter. there are lots of developers like me meet this problem and react native haven't provide us a standard code demo or completely document.
brunolemos, mairi17 and ccorcosjeremy-jm
Metadata
Metadata
Assignees
Labels
StaleThere has been a lack of activity on this issue and it may be closed soon.There has been a lack of activity on this issue and it may be closed soon.