@@ -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,93 @@ - (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.attributedTitle = [[NSAttributedString alloc ]
145+ initWithString: @" Dismiss ✕"
146+ attributes: @{NSFontAttributeName : [UIFont systemFontOfSize: 12.0 weight: UIFontWeightRegular]}];
147+ buttonConfig.contentInsets = NSDirectionalEdgeInsetsMake (6 , 12 , 6 , 12 );
148+ buttonConfig.background .backgroundColor = darkerBackground;
149+ buttonConfig.background .cornerRadius = 10 ;
150+ buttonConfig.baseForegroundColor = color;
151+
152+ self->_dismissButton = [UIButton buttonWithConfiguration: buttonConfig primaryAction: nil ];
153+ self->_dismissButton .translatesAutoresizingMaskIntoConstraints = NO ;
154+ [self ->_dismissButton addTarget: self action: @selector (hide ) forControlEvents: UIControlEventTouchUpInside];
155+ }
156+
127157 self->_label = [[UILabel alloc ] init ];
128158 self->_label .translatesAutoresizingMaskIntoConstraints = NO ;
129159 self->_label .font = [UIFont monospacedDigitSystemFontOfSize: 12.0 weight: UIFontWeightRegular];
130160 self->_label .textAlignment = NSTextAlignmentCenter;
131161 self->_label .textColor = color;
132162 self->_label .text = message;
163+ self->_label .numberOfLines = 0 ;
133164
134165 [self ->_window.rootViewController.view addSubview: self ->_container];
166+ if (dismissButton) {
167+ [self ->_container addSubview: self ->_dismissButton];
168+ }
135169 [self ->_container addSubview: self ->_label];
136170
137171 CGFloat topSafeAreaHeight = mainWindow.safeAreaInsets .top ;
138- CGFloat height = topSafeAreaHeight + 25 ;
139- self->_window .frame = CGRectMake (0 , 0 , mainWindow.frame .size .width , height);
140-
141172 self->_window .hidden = NO ;
142173
143174 [self ->_window layoutIfNeeded ];
144175
145- [ NSLayoutConstraint activateConstraints : @[
176+ NSMutableArray *constraints = [ NSMutableArray arrayWithArray : @[
146177 // Container constraints
147178 [self ->_container.topAnchor constraintEqualToAnchor: self ->_window.rootViewController.view.topAnchor],
148179 [self ->_container.leadingAnchor constraintEqualToAnchor: self ->_window.rootViewController.view.leadingAnchor],
149180 [self ->_container.trailingAnchor constraintEqualToAnchor: self ->_window.rootViewController.view.trailingAnchor],
150- [self ->_container.heightAnchor constraintEqualToConstant: height],
151181
152182 // Label constraints
153- [self ->_label.centerXAnchor constraintEqualToAnchor: self ->_container.centerXAnchor],
183+ [self ->_label.topAnchor constraintEqualToAnchor: self ->_container.topAnchor constant: topSafeAreaHeight + 5 ],
184+ [self ->_label.leadingAnchor constraintEqualToAnchor: self ->_container.leadingAnchor constant: 10 ],
154185 [self ->_label.bottomAnchor constraintEqualToAnchor: self ->_container.bottomAnchor constant: -5 ],
155186 ]];
187+
188+ // Add button-specific constraints if button exists
189+ if (dismissButton) {
190+ [constraints addObjectsFromArray: @[
191+ [self ->_dismissButton.trailingAnchor constraintEqualToAnchor: self ->_container.trailingAnchor constant: -10 ],
192+ [self ->_dismissButton.centerYAnchor constraintEqualToAnchor: self ->_label.centerYAnchor],
193+ [self ->_dismissButton.heightAnchor constraintEqualToConstant: 22 ],
194+ [self ->_label.trailingAnchor constraintEqualToAnchor: self ->_dismissButton.leadingAnchor constant: -10 ],
195+ ]];
196+ } else {
197+ [constraints addObject: [self ->_label.trailingAnchor constraintEqualToAnchor: self ->_container.trailingAnchor
198+ constant: -10 ]];
199+ }
200+
201+ [NSLayoutConstraint activateConstraints: constraints];
156202 });
157203}
158204
159205RCT_EXPORT_METHOD (
160206 showMessage : (NSString *)message withColor : (NSNumber *__nonnull)color withBackgroundColor : (NSNumber *__nonnull)
161- backgroundColor)
207+ backgroundColor withDismissButton : ( NSNumber *)dismissButton )
162208{
163- [self showMessage: message color: [RCTConvert UIColor: color] backgroundColor: [RCTConvert UIColor: backgroundColor]];
209+ [self showMessage: message
210+ color: [RCTConvert UIColor: color]
211+ backgroundColor: [RCTConvert UIColor: backgroundColor]
212+ dismissButton: [dismissButton boolValue ]];
164213}
165-
166214RCT_EXPORT_METHOD (hide)
167215{
168216 if (!RCTDevLoadingViewGetEnabled ()) {
@@ -211,7 +259,7 @@ - (void)showProgressMessage:(NSString *)message
211259 backgroundColor = [UIColor colorWithHue: 0 saturation: 0 brightness: 0.98 alpha: 1 ];
212260 }
213261
214- [self showMessage: message color: color backgroundColor: backgroundColor];
262+ [self showMessage: message color: color backgroundColor: backgroundColor dismissButton: false ];
215263}
216264
217265- (void )showOfflineMessage
@@ -225,7 +273,7 @@ - (void)showOfflineMessage
225273 }
226274
227275 NSString *message = [NSString stringWithFormat: @" Connect to %@ to develop JavaScript." , RCT_PACKAGER_NAME];
228- [self showMessage: message color: color backgroundColor: backgroundColor];
276+ [self showMessage: message color: color backgroundColor: backgroundColor dismissButton: false ];
229277}
230278
231279- (BOOL )isDarkModeEnabled
@@ -284,10 +332,16 @@ + (NSString *)moduleName
284332+ (void )setEnabled : (BOOL )enabled
285333{
286334}
287- - (void )showMessage : (NSString *)message color : (UIColor *)color backgroundColor : (UIColor *)backgroundColor
335+ - (void )showMessage : (NSString *)message
336+ color : (UIColor *)color
337+ backgroundColor : (UIColor *)backgroundColor
338+ dismissButton : (BOOL )dismissButton
288339{
289340}
290- - (void )showMessage : (NSString *)message withColor : (NSNumber *)color withBackgroundColor : (NSNumber *)backgroundColor
341+ - (void )showMessage : (NSString *)message
342+ withColor : (NSNumber *)color
343+ withBackgroundColor : (NSNumber *)backgroundColor
344+ withDismissButton : (NSNumber *)dismissButton
291345{
292346}
293347- (void )showWithURL : (NSURL *)URL
0 commit comments