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

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

@class YHExplorerViewController;

@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;

@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 将要加载请求前的回调
 
 @param request 请求
 
 @since 1.0.7
 */
- (void)explorerWillLoadRequest:(NSMutableURLRequest * _Nonnull)request;

/**
 @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 (^ _Nonnull) (NSDictionary * _Nullable, BOOL))completion;

/**
 由于shouldStartLoadWithRequest这个代理方法不适合对外暴露,此代理将暴露webview拦截到的请求
 
 @param webView UIWebView
 @param request 网页请求
 @param navigationType 请求类型
 */
- (void)webView:(UIWebView *)webView didCatchRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType;

@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