|
29 | 29 | NSString * const ZFWKWebViewEventGoBackKey = @"ZFWKWebViewEventGoBackKey";
|
30 | 30 | NSString * const ZFWKWebViewEventGoForwardKey = @"ZFWKWebViewEventGoForwardKey";
|
31 | 31 |
|
| 32 | +NSString * const ZFWKWebViewEventViewWillAppear = @"ZFWKWebViewEventViewWillAppear"; |
| 33 | +NSString * const ZFWKWebViewEventViewWillDisappear = @"ZFWKWebViewEventViewWillDisappear"; |
| 34 | +NSString * const ZFWKWebViewEventViewDidDisappear = @"ZFWKWebViewEventViewDidDisappear"; |
| 35 | +NSString * const ZFWKWebViewEventViewDidLoad = @"ZFWKWebViewEventViewDidLoad"; |
| 36 | +NSString * const ZFWKWebViewEventViewWillLayoutSubviews = @"ZFWKWebViewEventViewWillLayoutSubviews"; |
| 37 | + |
32 | 38 | static inline BOOL isIPhoneXSeries() {
|
33 | 39 | BOOL iPhoneXSeries = NO;
|
34 | 40 | if (UIDevice.currentDevice.userInterfaceIdiom != UIUserInterfaceIdiomPhone) return iPhoneXSeries;
|
@@ -278,14 +284,26 @@ - (void)removeJS {
|
278 | 284 | }
|
279 | 285 | - (void)viewWillAppear:(BOOL)animated {
|
280 | 286 | [super viewWillAppear:animated];
|
| 287 | + |
| 288 | + zf_wkWebViewEventCallBack callback = self.config.callbacks[ZFWKWebViewEventViewWillAppear]; |
| 289 | + if (callback) callback(self, self.config, nil); |
| 290 | + |
281 | 291 | [self addJS];
|
282 | 292 | }
|
283 | 293 | - (void)viewWillDisappear:(BOOL)animated {
|
284 | 294 | [super viewWillDisappear:animated];
|
| 295 | + |
| 296 | + zf_wkWebViewEventCallBack callback = self.config.callbacks[ZFWKWebViewEventViewWillDisappear]; |
| 297 | + if (callback) callback(self, self.config, nil); |
| 298 | + |
285 | 299 | [self removeJS];
|
286 | 300 | }
|
287 | 301 | - (void)viewDidDisappear:(BOOL)animated {
|
288 | 302 | [super viewDidDisappear:animated];
|
| 303 | + |
| 304 | + zf_wkWebViewEventCallBack callback = self.config.callbacks[ZFWKWebViewEventViewDidDisappear]; |
| 305 | + if (callback) callback(self, self.config, nil); |
| 306 | + |
289 | 307 | }
|
290 | 308 | - (void)viewDidLoad {
|
291 | 309 | [super viewDidLoad];
|
@@ -380,6 +398,11 @@ - (void)viewDidLoad {
|
380 | 398 | self.loadFailedView.imageView.image = self.config.refreshButtonImage;
|
381 | 399 | [self.loadFailedView.hoverButton addTarget:self action:@selector(refresh) forControlEvents:UIControlEventTouchUpInside];
|
382 | 400 | [self.view addSubview:self.loadFailedView];
|
| 401 | + |
| 402 | + |
| 403 | + zf_wkWebViewEventCallBack callback = self.config.callbacks[ZFWKWebViewEventViewDidLoad]; |
| 404 | + if (callback) callback(self, self.config, nil); |
| 405 | + |
383 | 406 | }
|
384 | 407 |
|
385 | 408 | - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context {
|
@@ -486,6 +509,10 @@ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(N
|
486 | 509 |
|
487 | 510 | - (void)viewWillLayoutSubviews {
|
488 | 511 | [super viewWillLayoutSubviews];
|
| 512 | + |
| 513 | + zf_wkWebViewEventCallBack callback = self.config.callbacks[ZFWKWebViewEventViewWillLayoutSubviews]; |
| 514 | + if (callback) callback(self, self.config, nil); |
| 515 | + |
489 | 516 | float y = 0;
|
490 | 517 | float navHeight = 64;
|
491 | 518 | if (isIPhoneXSeries()) {
|
@@ -536,13 +563,21 @@ - (void)rightButtonClick:(UIButton *)button {
|
536 | 563 | if (callback) callback(self, self.config, button);
|
537 | 564 | }
|
538 | 565 |
|
| 566 | +- (void)reloadPreviousRequest { |
| 567 | + [self refresh]; |
| 568 | +} |
| 569 | + |
539 | 570 | - (void)refresh {
|
540 | 571 | self.titleLabel.text = [ZFWKWebVCConf localizedStringForKey:@"Loading..."];
|
541 | 572 | zf_wkWebViewEventCallBack callback = self.config.callbacks[ZFWKWebViewEventRefreshKey];
|
542 | 573 | if (callback) callback(self, self.config, nil);
|
543 | 574 | [self.webView stopLoading];
|
544 |
| - NSURLRequest *req = [[NSURLRequest alloc] initWithURL:self.previousURL cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:self.config.timeoutDuration]; |
545 |
| - [self.webView loadRequest:req]; |
| 575 | + if (self.previousURL) { |
| 576 | + NSURLRequest *req = [[NSURLRequest alloc] initWithURL:self.previousURL cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:self.config.timeoutDuration]; |
| 577 | + [self.webView loadRequest:req]; |
| 578 | + } else { |
| 579 | + [self.webView reload]; |
| 580 | + } |
546 | 581 | }
|
547 | 582 | - (void)goBack {
|
548 | 583 | if ([self.webView canGoBack]) [self.webView goBack];
|
|
0 commit comments