All Products
Search
Document Center

Refresh component

Last Updated: May 25, 2021

AURefreshView is a pull-down refresh view with an ant icon. At present, two colors are supported, as shown in the sample image.

Sample image

Add components

To enable AURefreshView, add the Common UI component and the Lottie component first.

  1. In the Podfile file, enter mPaaS_pod "mPaaS_CommonUI" and mPaaS_pod "mPaaS_Lottie" to add the dependencies on the Common UI component and the Lottie components.
  2. Run pod install to complete adding the components.

Interface description

 
  1. typedef NS_ENUM(NSUInteger, AURefreshViewState) {
  2. AURefreshViewStateNomal = 0, // Restore the list to the initial position.
  3. AURefreshViewStateBeginPulling = 1, // A user starts to pull the bar down.
  4. AURefreshViewStateLoading = 2, // Trigger RPC loading. The contentInset list is delivered in the default position.
  5. AURefreshViewStateFinishedLoading = 3, // RPC loaded. The contentInset list is about to be restored to the original position.
  6. AURefreshViewStateBeginResetting = 4, // The contentInset list starts to restore to the default inset.
  7. };
  8. typedef NS_ENUM(NSUInteger, AURefreshViewType) {
  9. AURefreshViewDefault, // The refresh style on the page.
  10. AURefreshViewTypeFeature1 // Apply it to the title bar, such as the homepage or the fortune tab with a background.
  11. };
  12. @protocol AURefreshViewDelegate;
  13. /**
  14. Set the animation view of mPaaS during pull-down refresh.
  15. */
  16. @interface AURefreshView : UIView
  17. @property (nonatomic, readonly) AURefreshViewState state;
  18. @property (nonatomic, weak) id <AURefreshViewDelegate> delegate;
  19. /**
  20. Set the style of the Lottie component during pull-down refresh.
  21. */
  22. @property (nonatomic, strong) UIView /*LOTAnimationView */ *lottieAnimationView;
  23. /* Specify the parent view where pull-down refresh is performed. The initial default height of pull-down refresh is the height of scrollView. By default, refreshView is to add the parent scrollView.
  24. * The default initial frame is (0, 0 - scrollView.height, scrollView.width, scrollView.height)). */
  25. - (instancetype)initWithSuperView:(UIScrollView *)scrollView
  26. type:(AURefreshViewType)type
  27. bizType:(NSString *)bizType;
  28. // Set a text that is displayed during pull-down refresh.
  29. - (void)setupLabelText:(NSString *)text;
  30. // Call the following methods in "delegate" of UIScrollView:
  31. - (void)auRefreshScrollViewWillBeginDragging:(UIScrollView *)scrollView;
  32. - (void)auRefreshScrollViewDidScroll:(UIScrollView *)scrollView;
  33. - (void)auRefreshScrollViewDidEndDragging:(UIScrollView *)scrollView;
  34. // To end the animation and hide the list, call the following method:
  35. - (void)auRefreshScrollViewDidFinishedLoading:(UIScrollView *)scrollView;
  36. // The client needs to scroll the page to the initial position and then call the automatic pull-down refresh function. Otherwise, a scrolling error will occur.
  37. - (void)autoPullRefreshScrollView:(UIScrollView *)scrollView;
  38. //
  39. - (void)pauseAnimation;
  40. // Expand the page.
  41. - (void)resumeAnimation;
  42. @end
  43. @protocol AURefreshViewDelegate <NSObject>
  44. @optional
  45. // This protocol is triggered when the bar is dropped down to the default position, which is the height of (Lottie)View.
  46. - (void)auRefreshViewDidTriggerloading:(AURefreshView *)view;
  47. // Complete the reset action after a pull-down refresh.
  48. - (void)auRefreshViewDidDidFinishAnimation:(AURefreshView *)view;
  49. @end

Sample code

This section provides the sample code of standard style and custom style refresh view.

Standard style

The following shows the sample code for a standard style refresh view.

 
  1. _refreshView = [[AURefreshView alloc] initWithSuperView:self.tableView type:AURefreshViewDefault bizType:@"demo"];
  2. [_refreshView setupLabelText:@"Refreshing"];
  3. [self.tableView addSubview:_refreshView];
  4. - (void)viewDidAppear:(BOOL)animated
  5. {
  6. [super viewDidAppear:animated];
  7. [_refreshView resumeAnimation];
  8. }
  9. - (void)viewDidDisappear:(BOOL)animated
  10. {
  11. [super viewDidDisappear:animated];
  12. [_refreshView pauseAnimation];
  13. }
  14. - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
  15. {
  16. [_refreshView auRefreshScrollViewWillBeginDragging:scrollView];
  17. }
  18. - (void)scrollViewDidScroll:(UIScrollView *)scrollView
  19. {
  20. [_refreshView auRefreshScrollViewDidScroll:scrollView];
  21. }
  22. - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
  23. {
  24. [_refreshView auRefreshScrollViewDidEndDragging:scrollView];
  25. }

Custom style

To customize styles, you must use the Lottie component and rewrite the Category of AUThemeManager.

The following sample code is for your reference:

 
  1. + (NSString *)au_defaultTheme_refresh_lottie_path{
  2. NSString *path = [[NSBundle mainBundle] pathForResource:@"ani" ofType:@"json"];
  3. return path;
  4. }