Pārlūkot izejas kodu

remove yellow boxes on iOS

yogevbd 6 gadus atpakaļ
vecāks
revīzija
d4879c8cd6
3 mainītis faili ar 78 papildinājumiem un 0 dzēšanām
  1. 1
    0
      lib/ios/RCTHelpers.h
  2. 59
    0
      lib/ios/RCTHelpers.m
  3. 18
    0
      lib/ios/RNNReactRootView.m

+ 1
- 0
lib/ios/RCTHelpers.h Parādīt failu

@@ -5,4 +5,5 @@
5 5
 + (NSMutableDictionary *)textAttributesFromDictionary:(NSDictionary *)dictionary withPrefix:(NSString *)prefix;
6 6
 + (NSMutableDictionary *)textAttributesFromDictionary:(NSDictionary *)dictionary withPrefix:(NSString *)prefix baseFont:(UIFont *)font;
7 7
 + (NSString*)getTimestampString;
8
++ (BOOL)removeYellowBox:(RCTRootView *)reactRootView;
8 9
 @end

+ 59
- 0
lib/ios/RCTHelpers.m Parādīt failu

@@ -135,5 +135,64 @@
135 135
 	return [NSString stringWithFormat:@"%lld", milliseconds];
136 136
 }
137 137
 
138
++ (NSArray *)getAllSubviewsForView:(UIView *)view {
139
+	NSMutableArray *allSubviews = [NSMutableArray new];
140
+	for (UIView *subview in view.subviews)
141
+	{
142
+		[allSubviews addObject:subview];
143
+		[allSubviews addObjectsFromArray:[self getAllSubviewsForView:subview]];
144
+	}
145
+	return allSubviews;
146
+}
147
+
148
+/*
149
+ The YellowBox is added to each RCTRootView. Regardless if there are warnings or not, if there's a warning anywhere in the app - it is added
150
+ Since it is always appears on the top, it blocks interactions with other components.
151
+ It is most noticeable in RCCLightBox and RCCNotification where button (for example) are not clickable if placed at the bottom part of the view
152
+ */
153
+
154
++ (BOOL)removeYellowBox:(RCTRootView *)reactRootView {
155
+#ifndef DEBUG
156
+	return YES;
157
+#endif
158
+	
159
+	BOOL removed = NO;
160
+	
161
+	NSArray* subviews = [self getAllSubviewsForView:reactRootView];
162
+	for (UIView *view in subviews)
163
+	{
164
+		if ([view isKindOfClass:[RCTView class]])
165
+		{
166
+			CGFloat r, g, b, a;
167
+			[view.backgroundColor getRed:&r green:&g blue:&b alpha:&a];
168
+			
169
+			//identify the yellow view by its hard-coded color and height
170
+			if((lrint(r * 255) == 250) && (lrint(g * 255) == 186) && (lrint(b * 255) == 48) && (lrint(a * 100) == 95) && (view.frame.size.height == 46))
171
+			{
172
+				UIView *yelloboxParentView = view;
173
+				while (view.superview != nil)
174
+				{
175
+					yelloboxParentView = yelloboxParentView.superview;
176
+					if ([yelloboxParentView isKindOfClass:[RCTScrollView class]])
177
+					{
178
+						yelloboxParentView = yelloboxParentView.superview;
179
+						break;
180
+					}
181
+				}
182
+				
183
+				[yelloboxParentView removeFromSuperview];
184
+				removed = YES;
185
+				break;
186
+			}
187
+		}
188
+		
189
+		if (removed)
190
+		{
191
+			break;
192
+		}
193
+	}
194
+	
195
+	return removed;
196
+}
138 197
 
139 198
 @end

+ 18
- 0
lib/ios/RNNReactRootView.m Parādīt failu

@@ -1,7 +1,25 @@
1 1
 #import "RNNReactRootView.h"
2
+#import "RCTHelpers.h"
2 3
 
3 4
 @implementation RNNReactRootView
4 5
 
6
+- (instancetype)initWithBridge:(RCTBridge *)bridge moduleName:(NSString *)moduleName initialProperties:(NSDictionary *)initialProperties {
7
+	self = [super initWithBridge:bridge moduleName:moduleName initialProperties:initialProperties];
8
+	
9
+#ifdef DEBUG
10
+	[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(contentDidAppear:) name:RCTContentDidAppearNotification object:nil];
11
+#endif
12
+	
13
+	return self;
14
+}
15
+
16
+- (void)contentDidAppear:(NSNotification *)notification {
17
+	if ([((RNNReactRootView *)notification.object).moduleName isEqualToString:self.moduleName]) {
18
+		[RCTHelpers removeYellowBox:self];
19
+		[[NSNotificationCenter defaultCenter] removeObserver:self];
20
+	}
21
+}
22
+
5 23
 - (void)setRootViewDidChangeIntrinsicSize:(void (^)(CGSize))rootViewDidChangeIntrinsicSize {
6 24
 	_rootViewDidChangeIntrinsicSize = rootViewDidChangeIntrinsicSize;
7 25
 	self.delegate = self;