forked from wix/react-native-navigation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRNNReactView.m
65 lines (51 loc) · 1.83 KB
/
RNNReactView.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#import "RNNReactView.h"
#import "RCTHelpers.h"
#import <React/RCTUIManager.h>
@implementation RNNReactView {
BOOL _isAppeared;
}
- (instancetype)initWithBridge:(RCTBridge *)bridge moduleName:(NSString *)moduleName initialProperties:(NSDictionary *)initialProperties eventEmitter:(RNNEventEmitter *)eventEmitter reactViewReadyBlock:(RNNReactViewReadyCompletionBlock)reactViewReadyBlock {
self = [super initWithBridge:bridge moduleName:moduleName initialProperties:initialProperties];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(contentDidAppear:) name:RCTContentDidAppearNotification object:nil];
_reactViewReadyBlock = reactViewReadyBlock;
_eventEmitter = eventEmitter;
return self;
}
- (void)layoutSubviews {
[super layoutSubviews];
#ifdef DEBUG
[RCTHelpers removeYellowBox:self];
#endif
}
- (void)contentDidAppear:(NSNotification *)notification {
RNNReactView* appearedView = notification.object;
if ([appearedView.appProperties[@"componentId"] isEqual:self.componentId]) {
[self reactViewReady];
}
}
- (void)reactViewReady {
if (_reactViewReadyBlock) {
_reactViewReadyBlock();
_reactViewReadyBlock = nil;
}
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)componentDidAppear {
if (!_isAppeared) {
[_eventEmitter sendComponentDidAppear:self.componentId componentName:self.moduleName componentType:self.componentType];
}
_isAppeared = YES;
}
- (void)componentDidDisappear {
if (_isAppeared) {
[_eventEmitter sendComponentDidDisappear:self.componentId componentName:self.moduleName componentType:self.componentType];
}
_isAppeared = NO;
}
- (NSString *)componentId {
return self.appProperties[@"componentId"];
}
- (NSString *)componentType {
return ComponentTypeScreen;
}
@end