YHExplorerWebViewDelegate.h 4.38 KB
//
//  YHExplorerWebViewDelegate.h
//  ALWlibwebp
//
//  Created by 孟顺 on 2019/3/5.
//

#import <Foundation/Foundation.h>
#import "Cordova.h"

@class YHExplorerViewController;
@protocol YHLinkParserDelegate;

@protocol YHExplorerWebViewDelegate <NSObject>

@optional

- (void)yhExplorer_webViewDidStartLoad:(nonnull YHExplorerViewController *)explorer;

- (void)yhExplorer_webViewDidFinishLoad:(nonnull YHExplorerViewController *)explorer;

- (void)yhExplorer_webView:(nonnull YHExplorerViewController *)explorer didFailLoadWithError:(nullable NSError *)error;

- (BOOL)yhExplorer_webView:(nonnull YHExplorerViewController *)explorer shouldStartLoadWithRequest:(nullable NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType;

- (void)yhExplorer_webViewWebContentProcessDidTerminate:(id)webView;
@end

#pragma mark - Protocol:YHExplorerDelegate
@protocol YHExplorerDelegate <YHExplorerWebViewDelegate>
@optional

/**
 *  获取页面的title
 *
 *  @param title 页面的title
 */
- (void)pageTitleUpdated:(NSString * _Nullable)title;
/**
 *  webView探测到含有指定参数的回调
 *
 *  @param params 参数
 */
- (void)explorerDidDetectParameters:(NSDictionary * _Nonnull)params __attribute__((deprecated("Use `- explorer:didDetectParameters:` instead.")));

/**
 @brief 获取页面的title
 
 @param explorer explorer对象
 @param params   参数
 
 @since 1.1.0
 */
- (void)explorer:(YHExplorerViewController * _Nonnull)explorer didDetectParameters:(NSDictionary * _Nonnull)params;

/**
 @brief 将要加载请求前的回调  iOS系统>=11&&使用的wkwebview 则不会回调 此时使用wkwebviewDecidePolicyForNavigationActionWithUrl:
 
 @param request 请求
 
 @since 6.8.9
 */
- (void)explorerWillLoadRequest:(NSMutableURLRequest * _Nonnull)request;

/**
 当wkwebview加载 一个url 会询问客户端是否应该加载时的 回调, 当且仅当iOS11及其以上的版本才可以使用
 */
- (void)wkwebviewDecidePolicyForNavigationActionWithUrl:(NSURL *)url API_AVAILABLE(ios(11.0));

/**
 @brief 补充userAgent
 
 @return 需要添加的UserAgent
 
 @since 1.1.0
 */
- (NSString * _Nullable)extraUserAgent;

/**
 @brief 点击图片事件
 注:需要开启 `YHExplorerView`属性`enablePictureTapGesture`
 
 @param explorer explorer对象
 @param params   图片的一些信息
 
 @since 1.1.3
 */
- (void)explorer:(YHExplorerViewController * _Nonnull)explorer didClickPicture:(NSDictionary * _Nonnull)pictureInfo;

#pragma mark Native
/**
 @brief H5端触发Native事件
 
 @param params 事件参数
 
 @param completion 处理完后的回调(务必回调!!!)
 
 @since 1.1.0
 */
- (void)didGetMessageFromWeb:(NSDictionary * _Nonnull)params completion:(void (^) (id _Nullable, BOOL))completion;

@required
@end

@protocol YHExplorerWebViewActionProtocol <NSObject>

@optional
- (nullable UIScrollView *)scrollView;
- (nullable NSURL *)requestURL;

- (BOOL)isLoading;
- (BOOL)canGoBack;
- (BOOL)canGoForward;

- (nullable id)goBack;
- (nullable id)goForward;
- (nullable id)reload;
- (nullable id)reloadFromOrigin;
- (void)stopLoading;

@property (nonatomic) BOOL scalesPageToFit;

- (void)evaluateJavaScript:(nonnull NSString *)javaScriptString completionHandler:(void (^ __nullable)(__nullable id, NSError * __nullable error))completionHandler;
- (nullable NSString *)stringByEvaluatingJavaScriptFromString:(nonnull NSString *)javaScriptString;

- (void)yh_setScrollEnabled:(BOOL)enabled;

@end

#pragma mark - Protocol:YHExplorer

@protocol YHExplorer <YHExplorerWebViewActionProtocol>
/**
 *  加载url
 *
 *  @param url 地址
 */
- (void)loadWebUrl:(NSString * _Nonnull)url;
/**
 *  加载URL
 *
 *  @param URL
 */
- (void)loadURL:(NSURL * _Nonnull)URL;
/**
 *  加载html内容
 *
 *  @param html 网页内容
 */
- (void)loadHTMLString:(NSString * _Nonnull)html;
/**
 *  加载html内容
 *
 *  @param html 网页内容
 *  @param baseURL URL
 */
- (void)loadHTMLString:(NSString * _Nonnull)html baseURL:(NSURL * __nullable)baseURL;

/**
 *  设置进度条的颜色
 *
 *  @param color 颜色
 */
- (void)setProgressBarColor:(UIColor * _Nonnull)color;
@optional
/**
 *  注册一个链接解析器
 *
 *  @param parser 链接解析器
 */
- (void)registerLinkParser:(id <YHLinkParserDelegate> _Nonnull)parser;

/**
 *  禁用链接解析
 *
 *  @param parser 链接解析器
 */
- (void)unRegisterLinkParser:(id <YHLinkParserDelegate> _Nonnull)parser;

/**
 *  移除滚动条
 */
- (void)removeProgress;
@end