|
| 1 | +/* |
| 2 | + * Copyright (c) Meta Platforms, Inc. and affiliates. |
| 3 | + * |
| 4 | + * This source code is licensed under the MIT license found in the |
| 5 | + * LICENSE file in the root directory of this source tree. |
| 6 | + */ |
| 7 | + |
| 8 | +#import <UIKit/UIKit.h> |
| 9 | + |
| 10 | +NS_ASSUME_NONNULL_BEGIN |
| 11 | + |
| 12 | +/** |
| 13 | + * A floating capsule at the top of the screen, in a window of its own above the app, for messages shown during |
| 14 | + * development. It centers where a system alert would, keeps clear of the safe area and of a foldable's hinge, and |
| 15 | + * animates in and out. Banners stack: while several are visible, each sits below those with a lower stack level. |
| 16 | + * The dev loading banner is one; each instance hosts one capsule at a time, and subclasses shape theirs through the |
| 17 | + * hooks below. |
| 18 | + */ |
| 19 | +@interface RCTDevBanner : NSObject |
| 20 | + |
| 21 | +/** Whether the capsule is on screen or animating out. Main queue only. */ |
| 22 | +@property (nonatomic, readonly, getter=isVisible) BOOL visible; |
| 23 | + |
| 24 | +/** Shows the message, replacing any capsule already on screen. Callable from any thread. */ |
| 25 | +- (void)showMessage:(NSString *)message |
| 26 | + color:(UIColor *)color |
| 27 | + backgroundColor:(UIColor *)backgroundColor |
| 28 | + dismissButton:(BOOL)dismissButton; |
| 29 | + |
| 30 | +/** Replaces the text of the capsule on screen, for updates that arrive quickly such as progress. Main queue only. */ |
| 31 | +- (void)updateMessage:(NSString *)message; |
| 32 | + |
| 33 | +/** Animates the capsule out, after it has been on screen long enough to read. Callable from any thread. */ |
| 34 | +- (void)hide; |
| 35 | + |
| 36 | +@end |
| 37 | + |
| 38 | +/** |
| 39 | + * Hooks for subclasses, each with the loading banner's behavior by default. All run on the main queue. |
| 40 | + */ |
| 41 | +@interface RCTDevBanner (Subclassing) |
| 42 | + |
| 43 | +/** The level of the banner's window. */ |
| 44 | +- (UIWindowLevel)windowLevel; |
| 45 | + |
| 46 | +/** Whether the window dims the app beneath the capsule and swallows touches on it. */ |
| 47 | +- (BOOL)dimsBackground; |
| 48 | + |
| 49 | +/** Banners with a lower level stack above those with a higher one. */ |
| 50 | +- (NSUInteger)stackLevel; |
| 51 | + |
| 52 | +/** The capsule's minimum height. */ |
| 53 | +- (CGFloat)minimumHeight; |
| 54 | + |
| 55 | +/** The space between the capsule's edges and its label, or its leading accessory view where there is one. */ |
| 56 | +- (NSDirectionalEdgeInsets)labelInsets; |
| 57 | + |
| 58 | +/** A view shown before the label, such as an icon, sized by its own constraints; nil for none. Called once per capsule. |
| 59 | + */ |
| 60 | +- (nullable UIView *)makeLeadingAccessoryView; |
| 61 | + |
| 62 | +/** The label's text for a message. */ |
| 63 | +- (NSAttributedString *)attributedTextForMessage:(NSString *)message textColor:(UIColor *)textColor; |
| 64 | + |
| 65 | +/** The capsule's accessibility label, or nil to expose its subviews instead. */ |
| 66 | +- (nullable NSString *)accessibilityLabelForMessage:(NSString *)message; |
| 67 | + |
| 68 | +/** What a tap on the capsule does. */ |
| 69 | +- (void)didTapCapsule; |
| 70 | + |
| 71 | +@end |
| 72 | + |
| 73 | +NS_ASSUME_NONNULL_END |
0 commit comments