iOS:DoricViewController add loadingView and errorView
This commit is contained in:
parent
7c83581c1e
commit
5a68f10cb5
@ -157,7 +157,7 @@ public class DoricPanelFragment extends Fragment implements IDoricNavigator {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadJSBundle() {
|
private void loadJSBundle() {
|
||||||
Bundle argument = getArguments();
|
Bundle argument = getArguments();
|
||||||
if (argument == null) {
|
if (argument == null) {
|
||||||
if (getActivity() != null && getActivity().getIntent() != null) {
|
if (getActivity() != null && getActivity().getIntent() != null) {
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
#import "DoricAsyncResult.h"
|
#import "DoricAsyncResult.h"
|
||||||
#import "DoricRegistry.h"
|
#import "DoricRegistry.h"
|
||||||
|
|
||||||
typedef NS_ENUM(NSInteger, QueueMode) {
|
typedef NS_ENUM(NSInteger, DoricQueueMode) {
|
||||||
JS = 0,
|
JS = 0,
|
||||||
UI,
|
UI,
|
||||||
INDEPENDENT
|
INDEPENDENT
|
||||||
|
@ -22,10 +22,15 @@
|
|||||||
#import "DoricNavBarDelegate.h"
|
#import "DoricNavBarDelegate.h"
|
||||||
#import "DoricPanel.h"
|
#import "DoricPanel.h"
|
||||||
|
|
||||||
|
extern NSString *const DORIC_MASK_RETRY;
|
||||||
|
|
||||||
|
|
||||||
@interface DoricViewController : UIViewController <DoricNavigatorDelegate, DoricNavBarDelegate>
|
@interface DoricViewController : UIViewController <DoricNavigatorDelegate, DoricNavBarDelegate>
|
||||||
@property(nonatomic, strong) DoricPanel *doricPanel;
|
@property(nonatomic, strong) DoricPanel *doricPanel;
|
||||||
@property(nonatomic) BOOL statusBarHidden;
|
@property(nonatomic) BOOL statusBarHidden;
|
||||||
@property(nonatomic) int statusBarMode;
|
@property(nonatomic) int statusBarMode;
|
||||||
|
@property(nonatomic, strong) UIView *loadingView;
|
||||||
|
@property(nonatomic, strong) UIView *errorView;
|
||||||
|
|
||||||
- (instancetype)initWithScheme:(NSString *)scheme alias:(NSString *)alias extra:(NSString *)extra;
|
- (instancetype)initWithScheme:(NSString *)scheme alias:(NSString *)alias extra:(NSString *)extra;
|
||||||
@end
|
@end
|
||||||
|
@ -18,40 +18,69 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#import "DoricViewController.h"
|
#import "DoricViewController.h"
|
||||||
#import "DoricAsyncResult.h"
|
|
||||||
#import "DoricJSLoaderManager.h"
|
#import "DoricJSLoaderManager.h"
|
||||||
#import "UIView+Doric.h"
|
#import "UIView+Doric.h"
|
||||||
#import "DoricExtensions.h"
|
#import "DoricExtensions.h"
|
||||||
#import "DoricUtil.h"
|
#import "DoricUtil.h"
|
||||||
|
|
||||||
|
NSString *const DORIC_MASK_RETRY = @"doric_mask_retry";
|
||||||
|
|
||||||
@interface DoricViewController ()
|
@interface DoricViewController ()
|
||||||
@property(nonatomic) BOOL navBarHidden;
|
@property(nonatomic) BOOL navBarHidden;
|
||||||
@property(nonatomic, strong) UIImage *navBarImage;
|
@property(nonatomic, strong) UIImage *navBarImage;
|
||||||
|
@property(nonatomic, strong) UIView *maskView;
|
||||||
|
@property(nonatomic, copy) NSString *scheme;
|
||||||
|
@property(nonatomic, copy) NSString *alias;
|
||||||
|
@property(nonatomic, copy) NSString *extra;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation DoricViewController
|
@implementation DoricViewController
|
||||||
- (instancetype)initWithScheme:(NSString *)scheme alias:(NSString *)alias extra:(NSString *)extra {
|
- (instancetype)initWithScheme:(NSString *)scheme alias:(NSString *)alias extra:(NSString *)extra {
|
||||||
if (self = [super init]) {
|
if (self = [super init]) {
|
||||||
self.edgesForExtendedLayout = UIRectEdgeNone;
|
self.edgesForExtendedLayout = UIRectEdgeNone;
|
||||||
DoricAsyncResult <NSString *> *result = [DoricJSLoaderManager.instance request:scheme];
|
_scheme = scheme;
|
||||||
result.resultCallback = ^(NSString *result) {
|
_alias = alias;
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
_extra = extra;
|
||||||
DoricPanel *panel = [DoricPanel new];
|
_doricPanel = [DoricPanel new];
|
||||||
[panel.view also:^(UIView *it) {
|
}
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)viewDidLoad {
|
||||||
|
[super viewDidLoad];
|
||||||
|
self.doricPanel = [[DoricPanel new] also:^(DoricPanel *it) {
|
||||||
|
[it.view also:^(UIView *it) {
|
||||||
it.backgroundColor = [UIColor whiteColor];
|
it.backgroundColor = [UIColor whiteColor];
|
||||||
it.width = self.view.width;
|
it.width = self.view.width;
|
||||||
it.height = self.view.height;
|
it.height = self.view.height;
|
||||||
}];
|
}];
|
||||||
[self.view addSubview:panel.view];
|
[self.view addSubview:it.view];
|
||||||
[self addChildViewController:panel];
|
[self addChildViewController:it];
|
||||||
[panel config:result alias:alias extra:extra];
|
}];
|
||||||
panel.doricContext.navigator = self;
|
self.maskView = [[UIView new] also:^(UIView *it) {
|
||||||
panel.doricContext.navBar = self;
|
it.backgroundColor = [UIColor whiteColor];
|
||||||
self.doricPanel = panel;
|
it.width = self.view.width;
|
||||||
});
|
it.height = self.view.height;
|
||||||
};
|
[self.view addSubview:it];
|
||||||
|
if (self.loadingView) {
|
||||||
|
[it addSubview:self.loadingView];
|
||||||
}
|
}
|
||||||
return self;
|
if (self.errorView) {
|
||||||
|
[it addSubview:self.errorView];
|
||||||
|
}
|
||||||
|
UIView *retryView = [it viewWithTagString:DORIC_MASK_RETRY];
|
||||||
|
if (retryView) {
|
||||||
|
UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc]
|
||||||
|
initWithTarget:self
|
||||||
|
action:@selector(retry:)];
|
||||||
|
[retryView addGestureRecognizer:recognizer];
|
||||||
|
}
|
||||||
|
}];
|
||||||
|
[self loadJSBundle];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)retry:(UIView *)view {
|
||||||
|
[self loadJSBundle];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)viewWillAppear:(BOOL)animated {
|
- (void)viewWillAppear:(BOOL)animated {
|
||||||
@ -127,4 +156,43 @@ - (BOOL)prefersStatusBarHidden {
|
|||||||
return self.statusBarHidden;
|
return self.statusBarHidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)showLoading {
|
||||||
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
|
self.maskView.hidden = NO;
|
||||||
|
self.loadingView.hidden = NO;
|
||||||
|
self.errorView.hidden = YES;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)showError {
|
||||||
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
|
self.maskView.hidden = NO;
|
||||||
|
self.loadingView.hidden = YES;
|
||||||
|
self.errorView.hidden = NO;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)hideMask {
|
||||||
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
|
self.maskView.hidden = YES;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)loadJSBundle {
|
||||||
|
[self showLoading];
|
||||||
|
DoricAsyncResult <NSString *> *result = [DoricJSLoaderManager.instance request:self.scheme];
|
||||||
|
result.resultCallback = ^(NSString *result) {
|
||||||
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
|
[self hideMask];
|
||||||
|
[self.doricPanel config:result alias:self.alias extra:self.extra];
|
||||||
|
self.doricPanel.doricContext.navigator = self;
|
||||||
|
self.doricPanel.doricContext.navBar = self;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
result.exceptionCallback = ^(NSException *e) {
|
||||||
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
|
[self showError];
|
||||||
|
});
|
||||||
|
};
|
||||||
|
}
|
||||||
@end
|
@end
|
||||||
|
Reference in New Issue
Block a user