@@ -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;
@@ -86,6 +87,14 @@ - (void)showInitialMessageDelayed:(void (^)())initialMessage
8687}
8788
8889- (void )showMessage : (NSString *)message color : (UIColor *)color backgroundColor : (UIColor *)backgroundColor
90+ {
91+ [self showMessageV2: message color: color backgroundColor: backgroundColor dismissButton: NO ];
92+ }
93+
94+ - (void )showMessageV2 : (NSString *)message
95+ color : (UIColor *)color
96+ backgroundColor : (UIColor *)backgroundColor
97+ dismissButton : (BOOL )dismissButton
8998{
9099 if (!RCTDevLoadingViewGetEnabled () || _hiding) {
91100 return ;
@@ -120,39 +129,81 @@ - (void)showMessage:(NSString *)message color:(UIColor *)color backgroundColor:(
120129 self->_container = [[UIView alloc ] init ];
121130 self->_container .backgroundColor = backgroundColor;
122131 self->_container .translatesAutoresizingMaskIntoConstraints = NO ;
132+ self->_container .clipsToBounds = YES ;
123133 UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc ] initWithTarget: self action: @selector (hide )];
124134 [self ->_container addGestureRecognizer: tapGesture];
125135 self->_container .userInteractionEnabled = YES ;
126136
137+ if (dismissButton) {
138+ CGFloat hue = 0.0 ;
139+ CGFloat saturation = 0.0 ;
140+ CGFloat brightness = 0.0 ;
141+ CGFloat alpha = 0.0 ;
142+ [backgroundColor getHue: &hue saturation: &saturation brightness: &brightness alpha: &alpha];
143+ UIColor *darkerBackground = [UIColor colorWithHue: hue
144+ saturation: saturation
145+ brightness: brightness * 0.7
146+ alpha: 1.0 ];
147+
148+ UIButtonConfiguration *buttonConfig = [UIButtonConfiguration plainButtonConfiguration ];
149+ buttonConfig.attributedTitle = [[NSAttributedString alloc ]
150+ initWithString: @" Dismiss ✕"
151+ attributes: @{NSFontAttributeName : [UIFont systemFontOfSize: 12.0 weight: UIFontWeightRegular]}];
152+ buttonConfig.contentInsets = NSDirectionalEdgeInsetsMake (6 , 12 , 6 , 12 );
153+ buttonConfig.background .backgroundColor = darkerBackground;
154+ buttonConfig.background .cornerRadius = 10 ;
155+ buttonConfig.baseForegroundColor = color;
156+
157+ self->_dismissButton = [UIButton buttonWithConfiguration: buttonConfig primaryAction: nil ];
158+ self->_dismissButton .translatesAutoresizingMaskIntoConstraints = NO ;
159+ [self ->_dismissButton addTarget: self action: @selector (hide ) forControlEvents: UIControlEventTouchUpInside];
160+ }
161+
127162 self->_label = [[UILabel alloc ] init ];
128163 self->_label .translatesAutoresizingMaskIntoConstraints = NO ;
129164 self->_label .font = [UIFont monospacedDigitSystemFontOfSize: 12.0 weight: UIFontWeightRegular];
130165 self->_label .textAlignment = NSTextAlignmentCenter;
131166 self->_label .textColor = color;
132167 self->_label .text = message;
168+ self->_label .numberOfLines = 0 ;
133169
134170 [self ->_window.rootViewController.view addSubview: self ->_container];
171+ if (dismissButton) {
172+ [self ->_container addSubview: self ->_dismissButton];
173+ }
135174 [self ->_container addSubview: self ->_label];
136175
137176 CGFloat topSafeAreaHeight = mainWindow.safeAreaInsets .top ;
138- CGFloat height = topSafeAreaHeight + 25 ;
139- self->_window .frame = CGRectMake (0 , 0 , mainWindow.frame .size .width , height);
140-
141177 self->_window .hidden = NO ;
142178
143179 [self ->_window layoutIfNeeded ];
144180
145- [ NSLayoutConstraint activateConstraints : @[
181+ NSMutableArray *constraints = [ NSMutableArray arrayWithArray : @[
146182 // Container constraints
147183 [self ->_container.topAnchor constraintEqualToAnchor: self ->_window.rootViewController.view.topAnchor],
148184 [self ->_container.leadingAnchor constraintEqualToAnchor: self ->_window.rootViewController.view.leadingAnchor],
149185 [self ->_container.trailingAnchor constraintEqualToAnchor: self ->_window.rootViewController.view.trailingAnchor],
150- [self ->_container.heightAnchor constraintEqualToConstant: height],
151186
152187 // Label constraints
153- [self ->_label.centerXAnchor constraintEqualToAnchor: self ->_container.centerXAnchor],
188+ [self ->_label.topAnchor constraintEqualToAnchor: self ->_container.topAnchor constant: topSafeAreaHeight + 5 ],
189+ [self ->_label.leadingAnchor constraintEqualToAnchor: self ->_container.leadingAnchor constant: 10 ],
154190 [self ->_label.bottomAnchor constraintEqualToAnchor: self ->_container.bottomAnchor constant: -5 ],
155191 ]];
192+
193+ // Add button-specific constraints if button exists
194+ if (dismissButton) {
195+ [constraints addObjectsFromArray: @[
196+ [self ->_dismissButton.trailingAnchor constraintEqualToAnchor: self ->_container.trailingAnchor constant: -10 ],
197+ [self ->_dismissButton.centerYAnchor constraintEqualToAnchor: self ->_label.centerYAnchor],
198+ [self ->_dismissButton.heightAnchor constraintEqualToConstant: 22 ],
199+ [self ->_label.trailingAnchor constraintEqualToAnchor: self ->_dismissButton.leadingAnchor constant: -10 ],
200+ ]];
201+ } else {
202+ [constraints addObject: [self ->_label.trailingAnchor constraintEqualToAnchor: self ->_container.trailingAnchor
203+ constant: -10 ]];
204+ }
205+
206+ [NSLayoutConstraint activateConstraints: constraints];
156207 });
157208}
158209
@@ -162,7 +213,15 @@ - (void)showMessage:(NSString *)message color:(UIColor *)color backgroundColor:(
162213{
163214 [self showMessage: message color: [RCTConvert UIColor: color] backgroundColor: [RCTConvert UIColor: backgroundColor]];
164215}
165-
216+ RCT_EXPORT_METHOD (
217+ showMessageV2 : (NSString *)message withColor : (NSNumber *__nonnull)
218+ color withBackgroundColor : (NSNumber *__nonnull)backgroundColor withDismissButton : (NSNumber *)dismissButton)
219+ {
220+ [self showMessageV2: message
221+ color: [RCTConvert UIColor: color]
222+ backgroundColor: [RCTConvert UIColor: backgroundColor]
223+ dismissButton: [dismissButton boolValue ]];
224+ }
166225RCT_EXPORT_METHOD (hide)
167226{
168227 if (!RCTDevLoadingViewGetEnabled ()) {
@@ -211,7 +270,7 @@ - (void)showProgressMessage:(NSString *)message
211270 backgroundColor = [UIColor colorWithHue: 0 saturation: 0 brightness: 0.98 alpha: 1 ];
212271 }
213272
214- [self showMessage : message color: color backgroundColor: backgroundColor];
273+ [self showMessageV2 : message color: color backgroundColor: backgroundColor dismissButton: false ];
215274}
216275
217276- (void )showOfflineMessage
@@ -225,7 +284,7 @@ - (void)showOfflineMessage
225284 }
226285
227286 NSString *message = [NSString stringWithFormat: @" Connect to %@ to develop JavaScript." , RCT_PACKAGER_NAME];
228- [self showMessage : message color: color backgroundColor: backgroundColor];
287+ [self showMessageV2 : message color: color backgroundColor: backgroundColor dismissButton: false ];
229288}
230289
231290- (BOOL )isDarkModeEnabled
@@ -290,6 +349,18 @@ - (void)showMessage:(NSString *)message color:(UIColor *)color backgroundColor:(
290349- (void )showMessage : (NSString *)message withColor : (NSNumber *)color withBackgroundColor : (NSNumber *)backgroundColor
291350{
292351}
352+ - (void )showMessageV2 : (NSString *)message
353+ color : (UIColor *)color
354+ backgroundColor : (UIColor *)backgroundColor
355+ dismissButton : (BOOL )dismissButton
356+ {
357+ }
358+ - (void )showMessageV2 : (NSString *)message
359+ withColor : (NSNumber *)color
360+ withBackgroundColor : (NSNumber *)backgroundColor
361+ withDismissButton : (NSNumber *)dismissButton
362+ {
363+ }
293364- (void )showWithURL : (NSURL *)URL
294365{
295366}
0 commit comments