@@ -32,6 +32,7 @@ @implementation RCTDevLoadingView {
3232 UIWindow *_window;
3333 UILabel *_label;
3434 UIView *_container;
35+ UIButton *_dismissButton;
3536 NSDate *_showDate;
3637 BOOL _hiding;
3738 dispatch_block_t _initialMessageBlock;
@@ -85,7 +86,10 @@ - (void)showInitialMessageDelayed:(void (^)())initialMessage
8586 dispatch_time (DISPATCH_TIME_NOW, 0.2 * NSEC_PER_SEC), dispatch_get_main_queue (), self->_initialMessageBlock );
8687}
8788
88- - (void )showMessage : (NSString *)message color : (UIColor *)color backgroundColor : (UIColor *)backgroundColor
89+ - (void )showMessage : (NSString *)message
90+ color : (UIColor *)color
91+ backgroundColor : (UIColor *)backgroundColor
92+ dismissButton : (BOOL )dismissButton
8993{
9094 if (!RCTDevLoadingViewGetEnabled () || _hiding) {
9195 return ;
@@ -120,49 +124,91 @@ - (void)showMessage:(NSString *)message color:(UIColor *)color backgroundColor:(
120124 self->_container = [[UIView alloc ] init ];
121125 self->_container .backgroundColor = backgroundColor;
122126 self->_container .translatesAutoresizingMaskIntoConstraints = NO ;
127+ self->_container .clipsToBounds = YES ;
123128 UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc ] initWithTarget: self action: @selector (hide )];
124129 [self ->_container addGestureRecognizer: tapGesture];
125130 self->_container .userInteractionEnabled = YES ;
126131
132+ if (dismissButton) {
133+ CGFloat hue = 0.0 ;
134+ CGFloat saturation = 0.0 ;
135+ CGFloat brightness = 0.0 ;
136+ CGFloat alpha = 0.0 ;
137+ [backgroundColor getHue: &hue saturation: &saturation brightness: &brightness alpha: &alpha];
138+ UIColor *darkerBackground = [UIColor colorWithHue: hue
139+ saturation: saturation
140+ brightness: brightness * 0.7
141+ alpha: 1.0 ];
142+
143+ UIButtonConfiguration *buttonConfig = [UIButtonConfiguration plainButtonConfiguration ];
144+ buttonConfig.title = @" Dismiss ✕" ;
145+ buttonConfig.contentInsets = NSDirectionalEdgeInsetsMake (2 , 6 , 2 , 6 );
146+ buttonConfig.background .backgroundColor = darkerBackground;
147+ buttonConfig.background .cornerRadius = 10 ;
148+ buttonConfig.baseForegroundColor = color;
149+
150+ self->_dismissButton = [UIButton buttonWithConfiguration: buttonConfig primaryAction: nil ];
151+ self->_dismissButton .translatesAutoresizingMaskIntoConstraints = NO ;
152+ [self ->_dismissButton addTarget: self action: @selector (hide ) forControlEvents: UIControlEventTouchUpInside];
153+ }
154+
127155 self->_label = [[UILabel alloc ] init ];
128156 self->_label .translatesAutoresizingMaskIntoConstraints = NO ;
129157 self->_label .font = [UIFont monospacedDigitSystemFontOfSize: 12.0 weight: UIFontWeightRegular];
130158 self->_label .textAlignment = NSTextAlignmentCenter;
131159 self->_label .textColor = color;
132160 self->_label .text = message;
161+ self->_label .numberOfLines = 0 ;
133162
134163 [self ->_window.rootViewController.view addSubview: self ->_container];
164+ if (dismissButton) {
165+ [self ->_container addSubview: self ->_dismissButton];
166+ }
135167 [self ->_container addSubview: self ->_label];
136168
137169 CGFloat topSafeAreaHeight = mainWindow.safeAreaInsets .top ;
138- CGFloat height = topSafeAreaHeight + 25 ;
139- self->_window .frame = CGRectMake (0 , 0 , mainWindow.frame .size .width , height);
140-
141170 self->_window .hidden = NO ;
142171
143172 [self ->_window layoutIfNeeded ];
144173
145- [ NSLayoutConstraint activateConstraints : @[
174+ NSMutableArray *constraints = [ NSMutableArray arrayWithArray : @[
146175 // Container constraints
147176 [self ->_container.topAnchor constraintEqualToAnchor: self ->_window.rootViewController.view.topAnchor],
148177 [self ->_container.leadingAnchor constraintEqualToAnchor: self ->_window.rootViewController.view.leadingAnchor],
149178 [self ->_container.trailingAnchor constraintEqualToAnchor: self ->_window.rootViewController.view.trailingAnchor],
150- [self ->_container.heightAnchor constraintEqualToConstant: height],
151179
152180 // Label constraints
153- [self ->_label.centerXAnchor constraintEqualToAnchor: self ->_container.centerXAnchor],
181+ [self ->_label.topAnchor constraintEqualToAnchor: self ->_container.topAnchor constant: topSafeAreaHeight + 5 ],
182+ [self ->_label.leadingAnchor constraintEqualToAnchor: self ->_container.leadingAnchor constant: 10 ],
154183 [self ->_label.bottomAnchor constraintEqualToAnchor: self ->_container.bottomAnchor constant: -5 ],
155184 ]];
185+
186+ // Add button-specific constraints if button exists
187+ if (dismissButton) {
188+ [constraints addObjectsFromArray: @[
189+ [self ->_dismissButton.trailingAnchor constraintEqualToAnchor: self ->_container.trailingAnchor constant: -10 ],
190+ [self ->_dismissButton.centerYAnchor constraintEqualToAnchor: self ->_label.centerYAnchor],
191+ [self ->_dismissButton.heightAnchor constraintEqualToConstant: 22 ],
192+ [self ->_label.trailingAnchor constraintEqualToAnchor: self ->_dismissButton.leadingAnchor constant: -10 ],
193+ ]];
194+ } else {
195+ [constraints addObject: [self ->_label.trailingAnchor constraintEqualToAnchor: self ->_container.trailingAnchor
196+ constant: -10 ]];
197+ }
198+
199+ [NSLayoutConstraint activateConstraints: constraints];
156200 });
157201}
158202
159203RCT_EXPORT_METHOD (
160204 showMessage : (NSString *)message withColor : (NSNumber *__nonnull)color withBackgroundColor : (NSNumber *__nonnull)
161- backgroundColor)
205+ backgroundColor withDismissButton : ( NSNumber *)dismissButton )
162206{
163- [self showMessage: message color: [RCTConvert UIColor: color] backgroundColor: [RCTConvert UIColor: backgroundColor]];
207+ [self showMessage: message
208+ color: [RCTConvert UIColor: color]
209+ backgroundColor: [RCTConvert UIColor: backgroundColor]
210+ dismissButton: [dismissButton boolValue ]];
164211}
165-
166212RCT_EXPORT_METHOD (hide)
167213{
168214 if (!RCTDevLoadingViewGetEnabled ()) {
@@ -211,7 +257,7 @@ - (void)showProgressMessage:(NSString *)message
211257 backgroundColor = [UIColor colorWithHue: 0 saturation: 0 brightness: 0.98 alpha: 1 ];
212258 }
213259
214- [self showMessage: message color: color backgroundColor: backgroundColor];
260+ [self showMessage: message color: color backgroundColor: backgroundColor dismissButton: false ];
215261}
216262
217263- (void )showOfflineMessage
@@ -225,7 +271,7 @@ - (void)showOfflineMessage
225271 }
226272
227273 NSString *message = [NSString stringWithFormat: @" Connect to %@ to develop JavaScript." , RCT_PACKAGER_NAME];
228- [self showMessage: message color: color backgroundColor: backgroundColor];
274+ [self showMessage: message color: color backgroundColor: backgroundColor dismissButton: false ];
229275}
230276
231277- (BOOL )isDarkModeEnabled
@@ -284,10 +330,16 @@ + (NSString *)moduleName
284330+ (void )setEnabled : (BOOL )enabled
285331{
286332}
287- - (void )showMessage : (NSString *)message color : (UIColor *)color backgroundColor : (UIColor *)backgroundColor
333+ - (void )showMessage : (NSString *)message
334+ color : (UIColor *)color
335+ backgroundColor : (UIColor *)backgroundColor
336+ dismissButton : (BOOL )dismissButton
288337{
289338}
290- - (void )showMessage : (NSString *)message withColor : (NSNumber *)color withBackgroundColor : (NSNumber *)backgroundColor
339+ - (void )showMessage : (NSString *)message
340+ withColor : (NSNumber *)color
341+ withBackgroundColor : (NSNumber *)backgroundColor
342+ withDismissButton : (NSNumber *)dismissButton
291343{
292344}
293345- (void )showWithURL : (NSURL *)URL
0 commit comments