You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

79 lines
3.3 KiB

  1. //
  2. // FLEXAlert.h
  3. // FLEX
  4. //
  5. // Created by Tanner Bennett on 8/20/19.
  6. // Copyright © 2019 Flipboard. All rights reserved.
  7. //
  8. #import <UIKit/UIKit.h>
  9. @class FLEXAlert, FLEXAlertAction;
  10. typedef void (^FLEXAlertReveal)(void);
  11. typedef void (^FLEXAlertBuilder)(FLEXAlert *make);
  12. typedef FLEXAlert *(^FLEXAlertStringProperty)(NSString *);
  13. typedef FLEXAlert *(^FLEXAlertStringArg)(NSString *);
  14. typedef FLEXAlert *(^FLEXAlertTextField)(void(^configurationHandler)(UITextField *textField));
  15. typedef FLEXAlertAction *(^FLEXAlertAddAction)(NSString *title);
  16. typedef FLEXAlertAction *(^FLEXAlertActionStringProperty)(NSString *);
  17. typedef FLEXAlertAction *(^FLEXAlertActionProperty)(void);
  18. typedef FLEXAlertAction *(^FLEXAlertActionBOOLProperty)(BOOL);
  19. typedef FLEXAlertAction *(^FLEXAlertActionHandler)(void(^handler)(NSArray<NSString *> *strings));
  20. @interface FLEXAlert : NSObject
  21. /// Shows a simple alert with one button which says "Dismiss"
  22. + (void)showAlert:(NSString *)title message:(NSString *)message from:(UIViewController *)viewController;
  23. /// Construct and display an alert
  24. + (void)makeAlert:(FLEXAlertBuilder)block showFrom:(UIViewController *)viewController;
  25. /// Construct and display an action sheet-style alert
  26. + (void)makeSheet:(FLEXAlertBuilder)block showFrom:(UIViewController *)viewController;
  27. /// Construct an alert
  28. + (UIAlertController *)makeAlert:(FLEXAlertBuilder)block;
  29. /// Construct an action sheet-style alert
  30. + (UIAlertController *)makeSheet:(FLEXAlertBuilder)block;
  31. /// Set the alert's title.
  32. ///
  33. /// Call in succession to append strings to the title.
  34. @property (nonatomic, readonly) FLEXAlertStringProperty title;
  35. /// Set the alert's message.
  36. ///
  37. /// Call in succession to append strings to the message.
  38. @property (nonatomic, readonly) FLEXAlertStringProperty message;
  39. /// Add a button with a given title with the default style and no action.
  40. @property (nonatomic, readonly) FLEXAlertAddAction button;
  41. /// Add a text field with the given (optional) placeholder text.
  42. @property (nonatomic, readonly) FLEXAlertStringArg textField;
  43. /// Add and configure the given text field.
  44. ///
  45. /// Use this if you need to more than set the placeholder, such as
  46. /// supply a delegate, make it secure entry, or change other attributes.
  47. @property (nonatomic, readonly) FLEXAlertTextField configuredTextField;
  48. @end
  49. @interface FLEXAlertAction : NSObject
  50. /// Set the action's title.
  51. ///
  52. /// Call in succession to append strings to the title.
  53. @property (nonatomic, readonly) FLEXAlertActionStringProperty title;
  54. /// Make the action destructive. It appears with red text.
  55. @property (nonatomic, readonly) FLEXAlertActionProperty destructiveStyle;
  56. /// Make the action cancel-style. It appears with a bolder font.
  57. @property (nonatomic, readonly) FLEXAlertActionProperty cancelStyle;
  58. /// Enable or disable the action. Enabled by default.
  59. @property (nonatomic, readonly) FLEXAlertActionBOOLProperty enabled;
  60. /// Give the button an action. The action takes an array of text field strings.
  61. @property (nonatomic, readonly) FLEXAlertActionHandler handler;
  62. /// Access the underlying UIAlertAction, should you need to change it while
  63. /// the encompassing alert is being displayed. For example, you may want to
  64. /// enable or disable a button based on the input of some text fields in the alert.
  65. /// Do not call this more than once per instance.
  66. @property (nonatomic, readonly) UIAlertAction *action;
  67. @end