FLEXAlert.h 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. //
  2. // FLEXAlert.h
  3. // FLEX
  4. //
  5. // Created by Tanner Bennett on 8/20/19.
  6. // Copyright © 2020 FLEX Team. 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
  27. showFrom:(UIViewController *)viewController
  28. source:(id)viewOrBarItem;
  29. /// Construct an alert
  30. + (UIAlertController *)makeAlert:(FLEXAlertBuilder)block;
  31. /// Construct an action sheet-style alert
  32. + (UIAlertController *)makeSheet:(FLEXAlertBuilder)block;
  33. /// Set the alert's title.
  34. ///
  35. /// Call in succession to append strings to the title.
  36. @property (nonatomic, readonly) FLEXAlertStringProperty title;
  37. /// Set the alert's message.
  38. ///
  39. /// Call in succession to append strings to the message.
  40. @property (nonatomic, readonly) FLEXAlertStringProperty message;
  41. /// Add a button with a given title with the default style and no action.
  42. @property (nonatomic, readonly) FLEXAlertAddAction button;
  43. /// Add a text field with the given (optional) placeholder text.
  44. @property (nonatomic, readonly) FLEXAlertStringArg textField;
  45. /// Add and configure the given text field.
  46. ///
  47. /// Use this if you need to more than set the placeholder, such as
  48. /// supply a delegate, make it secure entry, or change other attributes.
  49. @property (nonatomic, readonly) FLEXAlertTextField configuredTextField;
  50. @end
  51. @interface FLEXAlertAction : NSObject
  52. /// Set the action's title.
  53. ///
  54. /// Call in succession to append strings to the title.
  55. @property (nonatomic, readonly) FLEXAlertActionStringProperty title;
  56. /// Make the action destructive. It appears with red text.
  57. @property (nonatomic, readonly) FLEXAlertActionProperty destructiveStyle;
  58. /// Make the action cancel-style. It appears with a bolder font.
  59. @property (nonatomic, readonly) FLEXAlertActionProperty cancelStyle;
  60. /// Enable or disable the action. Enabled by default.
  61. @property (nonatomic, readonly) FLEXAlertActionBOOLProperty enabled;
  62. /// Give the button an action. The action takes an array of text field strings.
  63. @property (nonatomic, readonly) FLEXAlertActionHandler handler;
  64. /// Access the underlying UIAlertAction, should you need to change it while
  65. /// the encompassing alert is being displayed. For example, you may want to
  66. /// enable or disable a button based on the input of some text fields in the alert.
  67. /// Do not call this more than once per instance.
  68. @property (nonatomic, readonly) UIAlertAction *action;
  69. @end