Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

无法注册单个Handler #11

Closed
AnAnKK opened this issue Sep 22, 2020 · 6 comments
Closed

无法注册单个Handler #11

AnAnKK opened this issue Sep 22, 2020 · 6 comments

Comments

@AnAnKK
Copy link

AnAnKK commented Sep 22, 2020

我想在Activity中单独添加个Handler,源码中初始化BridgeTiny的时候已经添加了所有的Handler, 想在Activity中单独添加该怎么做呢(weview和Activity在用一个页面的需求)

@AnAnKK AnAnKK changed the title 请教个问题 无法注册单个Handler Sep 23, 2020
@smallbuer
Copy link
Owner

我想在Activity中单独添加个Handler,源码中初始化BridgeTiny的时候已经添加了所有的Handler, 想在Activity中单独添加该怎么做呢(weview和Activity在用一个页面的需求)

是想每个webview只添加单独的Handle吗,目前实现的相当于APP用的所有的webview使用的handle都在初始化的时候设置好;

@AnAnKK
Copy link
Author

AnAnKK commented Sep 27, 2020

是的, 因为我这里有个需求, 是webview和avtivity是同一个页面的, 我想实现在同一个页面原生和js交互; 但是Handler的handler(Context context, String data, CallBackFunction function) 方法无法写到Activity中, 导致没法交互; 因此我想在webview中添加个抽象方法来动态添加Handle,但我不知道怎么写, 请大佬看看这个我该咋实现呢

@smallbuer
Copy link
Owner

是的, 因为我这里有个需求, 是webview和avtivity是同一个页面的, 我想实现在同一个页面原生和js交互; 但是Handler的handler(Context context, String data, CallBackFunction function) 方法无法写到Activity中, 导致没法交互; 因此我想在webview中添加个抽象方法来动态添加Handle,但我不知道怎么写, 请大佬看看这个我该咋实现呢

如果需要这种场景,也就是单独给UI中的webview添加JS桥,其实这种也是很容易满足的,直接扩展IWebview接口,添加两个方法,void addHandlerLocal(String handlerName,BridgeHandler bridgeHandler)和Map<String, BridgeHandler> getLocalMessageHandlers();接口,然后再各个webview中实现一个Map集合的维护,在回调的时候优先匹配webview中的桥,如果匹配到就直接return

@AnAnKK
Copy link
Author

AnAnKK commented Sep 29, 2020

好的 多谢大佬指导

@smallbuer
Copy link
Owner

好的 多谢大佬指导

下个版本加一个这种功能,需求还是挺不错的

@smallbuer
Copy link
Owner

已经添加1.0.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants