supervons / react-native-echarts-pro

A React-Native charts based on Apache ECharts, support various charts and map.
https://supervons.github.io/react-native-echarts-pro-docs/
MIT License
216 stars 32 forks source link

WKWebview注入js脚本(webview 置灰操作),Echarts图标不显示问题 #109

Closed MMing0310 closed 1 year ago

MMing0310 commented 1 year ago

iOS端使用WKWebview注入js脚本(webview 置灰操作,实现APP灰白模式)后,Echarts无法正常显示,以下是WKWebview注入js脚本的代码:

import "WKWebView+blackWhiteModel.h"

import <objc/runtime.h>

@implementation WKWebView (blackWhiteModel)

目前该库是否支持WKWebview注入js脚本,更改Echarts主题样式等问题?

supervons commented 1 year ago

1、提供六种基础样式,详见 themeName

2、思路上建议改变下,因为是基于react-native-webview进行注入,不应该在iOS端进行修改,应该通过其提供的API进行修改;此外,本库提供的props比如通过 extension 进行插件注入,也可实现:

image
MMing0310 commented 1 year ago

您好,react-native-webview是基于WKWebview实现的,那我使用原生runtime机制,拦截交换,在WKWebview初始化的时候,直接注入js代码,通过css改变h5的样式,应该是可以的吧?但是注入后,ECharts就失效不显示了,哪怕我什么都不注入,依然无法显示,这是为什么? (instancetype)gl_initWithFrame:(CGRect)frame configuration:(WKWebViewConfiguration )configuration { BOOL isOpenWhiteBlackModel = [[NSUserDefaults standardUserDefaults] boolForKey:@"kIsShowBlackWhiteModel"]; if (isOpenWhiteBlackModel) { // js脚本 // NSString jScript = @"var filter = '-webkit-filter:grayscale(100%);-moz-filter:grayscale(100%); -ms-filter:grayscale(100%); -o-filter:grayscale(100%) filter:grayscale(100%);';document.getElementsByTagName('html')[0].style.filter = 'grayscale(100%)';"; NSString jScript = @""; // 注入 WKUserScript wkUScript = [[WKUserScript alloc] initWithSource:jScript injectionTime:WKUserScriptInjectionTimeAtDocumentEnd forMainFrameOnly:YES];

WKUserContentController wkUController = [[WKUserContentController alloc] init]; [wkUController addUserScript:wkUScript]; // 配置对象 WKWebViewConfiguration wkWebConfig = [[WKWebViewConfiguration alloc] init]; wkWebConfig.userContentController = wkUController; configuration = wkWebConfig; WKWebView *webView = [self gl_initWithFrame:frame configuration:configuration]; return webView; }

return [self gl_initWithFrame:frame configuration:configuration]; }

supervons commented 1 year ago

方案已提供,可以试一下。

可能是和react-native-webviewJS 注入有冲突。