10
10
#import < QuartzCore/QuartzCore.h>
11
11
12
12
#import < FBReactNativeSpec/FBReactNativeSpec.h>
13
+ #import < React/RCTAppearance.h>
13
14
#import < React/RCTBridge.h>
14
15
#import < React/RCTConvert.h>
15
16
#import < React/RCTDefines.h>
@@ -190,27 +191,61 @@ - (void)showMessage:(NSString *)message color:(UIColor *)color backgroundColor:(
190
191
});
191
192
}
192
193
194
+ - (void )showProgressMessage : (NSString *)message
195
+ {
196
+ if (self->_window != nil ) {
197
+ // This is an optimization. Since the progress can come in quickly,
198
+ // we want to do the minimum amount of work to update the UI,
199
+ // which is to only update the label text.
200
+ self->_label .text = message;
201
+ return ;
202
+ }
203
+
204
+ UIColor *color = [UIColor whiteColor ];
205
+ UIColor *backgroundColor = [UIColor colorWithHue: 105 saturation: 0 brightness: .25 alpha: 1 ];
206
+
207
+ if ([self isDarkModeEnabled ]) {
208
+ color = [UIColor colorWithHue: 208 saturation: 0.03 brightness: .14 alpha: 1 ];
209
+ backgroundColor = [UIColor colorWithHue: 0 saturation: 0 brightness: 0.98 alpha: 1 ];
210
+ }
211
+
212
+ [self showMessage: message color: color backgroundColor: backgroundColor];
213
+ }
214
+
215
+ - (void )showOfflineMessage
216
+ {
217
+ UIColor *color = [UIColor whiteColor ];
218
+ UIColor *backgroundColor = [UIColor blackColor ];
219
+
220
+ if ([self isDarkModeEnabled ]) {
221
+ color = [UIColor blackColor ];
222
+ backgroundColor = [UIColor whiteColor ];
223
+ }
224
+
225
+ NSString *message = [NSString stringWithFormat: @" Connect to %@ to develop JavaScript." , RCT_PACKAGER_NAME];
226
+ [self showMessage: message color: color backgroundColor: backgroundColor];
227
+ }
228
+
229
+ - (BOOL )isDarkModeEnabled
230
+ {
231
+ // We pass nil here to match the behavior of the native module.
232
+ // If we were to pass a view, then it's possible that this native
233
+ // banner would have a different color than the JavaScript banner
234
+ // (which always passes nil). This would result in an inconsistent UI.
235
+ return [RCTColorSchemePreference (nil ) isEqualToString: @" dark" ];
236
+ }
193
237
- (void )showWithURL : (NSURL *)URL
194
238
{
195
- UIColor *color;
196
- UIColor *backgroundColor;
197
- NSString *message;
198
239
if (URL.fileURL ) {
199
240
// If dev mode is not enabled, we don't want to show this kind of notification.
200
241
#if !RCT_DEV
201
242
return ;
202
243
#endif
203
- color = [UIColor whiteColor ];
204
- backgroundColor = [UIColor blackColor ];
205
- message = [NSString stringWithFormat: @" Connect to %@ to develop JavaScript." , RCT_PACKAGER_NAME];
206
- [self showMessage: message color: color backgroundColor: backgroundColor];
244
+ [self showOfflineMessage ];
207
245
} else {
208
- color = [UIColor whiteColor ];
209
- backgroundColor = [UIColor colorWithHue: 105 saturation: 0 brightness: .25 alpha: 1 ];
210
- message = [NSString stringWithFormat: @" Loading from %@ \u2026 " , RCT_PACKAGER_NAME];
211
-
212
246
[self showInitialMessageDelayed: ^{
213
- [self showMessage: message color: color backgroundColor: backgroundColor];
247
+ NSString *message = [NSString stringWithFormat: @" Loading from %@ \u2026 " , RCT_PACKAGER_NAME];
248
+ [self showProgressMessage: message];
214
249
}];
215
250
}
216
251
}
@@ -225,18 +260,7 @@ - (void)updateProgress:(RCTLoadingProgress *)progress
225
260
[self clearInitialMessageDelay ];
226
261
227
262
dispatch_async (dispatch_get_main_queue (), ^{
228
- if (self->_window == nil ) {
229
- // If we didn't show the initial message, then there's no banner window.
230
- // We need to create it here so that the progress is actually displayed.
231
- UIColor *color = [UIColor whiteColor ];
232
- UIColor *backgroundColor = [UIColor colorWithHue: 105 saturation: 0 brightness: .25 alpha: 1 ];
233
- [self showMessage: [progress description ] color: color backgroundColor: backgroundColor];
234
- } else {
235
- // This is an optimization. Since the progress can come in quickly,
236
- // we want to do the minimum amount of work to update the UI,
237
- // which is to only update the label text.
238
- self->_label .text = [progress description ];
239
- }
263
+ [self showProgressMessage: [progress description ]];
240
264
});
241
265
}
242
266
0 commit comments