-
-
Notifications
You must be signed in to change notification settings - Fork 643
Expand file tree
/
Copy pathRNSViewInteractionManager.mm
More file actions
64 lines (53 loc) · 1.68 KB
/
RNSViewInteractionManager.mm
File metadata and controls
64 lines (53 loc) · 1.68 KB
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
#import "RNSViewInteractionManager.h"
#import "RNSTabsScreenComponentView.h"
#import "RNSViewInteractionAware.h"
@implementation RNSViewInteractionManager {
__weak UIView *lastRootWithInteractionsDisabled;
}
- (instancetype)init
{
if (self = [super init]) {
lastRootWithInteractionsDisabled = nil;
_disabled = YES;
}
return self;
}
- (void)disableInteractionsForSubtreeWith:(UIView *)view
{
if (_disabled) {
return;
}
UIView *current = view;
while (current && ![current isKindOfClass:UIWindow.class] &&
![current respondsToSelector:@selector(rnscreens_disableInteractions)]) {
current = current.superview;
}
if (current) {
if (lastRootWithInteractionsDisabled && lastRootWithInteractionsDisabled != current) {
// When one view already has interactions disabled, and we request a different view,
// we need to restore the first one
[self enableInteractionsForLastSubtree];
}
if ([current respondsToSelector:@selector(rnscreens_disableInteractions)]) {
[static_cast<id<RNSViewInteractionAware>>(current) rnscreens_disableInteractions];
} else {
current.userInteractionEnabled = NO;
}
lastRootWithInteractionsDisabled = current;
}
}
- (void)enableInteractionsForLastSubtree
{
if (_disabled) {
return;
}
if (lastRootWithInteractionsDisabled) {
if ([lastRootWithInteractionsDisabled respondsToSelector:@selector(rnscreens_enableInteractions)]) {
[static_cast<id<RNSViewInteractionAware>>(lastRootWithInteractionsDisabled) rnscreens_enableInteractions];
} else {
lastRootWithInteractionsDisabled.userInteractionEnabled = YES;
}
lastRootWithInteractionsDisabled = nil;
}
}
@end