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

addJavaScriptHandler do not work well in Android Api <= 22 #123

Closed
DreamBuddy opened this issue Jun 28, 2019 · 2 comments
Closed

addJavaScriptHandler do not work well in Android Api <= 22 #123

DreamBuddy opened this issue Jun 28, 2019 · 2 comments

Comments

@DreamBuddy
Copy link

Because addJavaScriptHandler use the 'Promise', but Android Webview does not support until api level 23.

I think,When the webview didn't support it ,We can make our 'MyPromise' or try other ways

@DreamBuddy
Copy link
Author

DreamBuddy commented Jun 28, 2019

private static final String MyPromise = "class MyPromise{constructor(e){if(this.resolveQueue=[],this.rejectQueue=[],this.message=null,this._status='PENDING','function'!=typeof e)throw Error('MyPromise 必须传递一个解析函数');try{e(this._resolve.bind(this),this._reject.bind(this))}catch(e){this._reject(e)}}_resolve(e){return'PENDING'!==this._status?this:(this.message=e,this._status='RESOLVED',this.resolveQueue.forEach(e=>{this._excute(e)}),this)}_reject(e){return'PENDING'!==this._status?this:(this.message=e,this._status='REJECTED',this.rejectQueue.forEach(e=>{this._excute(e)}),this)}then(e,t){let s=this._status;return'RESOLVED'===s&&this._excute(e),'REJECTED'===s&&this._excute(t),'PENDING'===s&&(this.resolveQueue.push(e),this.rejectQueue.push(t)),this}_excute(e){if(this._callback=e||function(){},'undefined'!=typeof MutationObserver){this.targetNode=document.createElement('i'),this.targetNode.id='INITIAL';let e={attributes:!0};return new MutationObserver(e=>{for(let t of e)'attributes'===t.type&&this._callback(this.message)}).observe(this.targetNode,e),void(this.targetNode.id=this._status)}if(process)process.nextTick(e=>{this._callback(this.message)});else{if('undefined'!=typeof MessageChannel){let e=new MessageChannel,t=e.port1,s=e.port2;return t.postMessage({}),void s.onmessage(e=>{this._callback(this.message)})}setTimeout(e=>{this._callback(this.message)},0)}}}";

  public static final String flutterInAppBroserJSClass = MyPromise + "window." + name + ".callHandler = function() {"
      + "var _callHandlerID = setTimeout(function(){});" + "window." + name
      + "._callHandler(arguments[0], _callHandlerID, JSON.stringify(Array.prototype.slice.call(arguments, 1)));"
      + "var _MyPromise = typeof Promise !== 'undefined'?Promise:MyPromise;" + "return new _MyPromise(function(resolve, reject) {" + "  window."
      + name + "[_callHandlerID] = resolve;" + "});" + "}";

pichillilorenzo added a commit that referenced this issue Dec 9, 2019
…nd event #128, fix #123 javascript handler for Android API <= 22, renamed onTargetBlank to onCreateWindow event, deleted useOnTargetBlank option, added supportMultipleWindows android option, added getDefaultUserAgent static method, Updated default value for domStorageEnabled option to true
pichillilorenzo added a commit that referenced this issue Dec 9, 2019
…nd event #128, fix #123 javascript handler for Android API <= 22, renamed onTargetBlank to onCreateWindow event, deleted useOnTargetBlank option, added supportMultipleWindows android option, added getDefaultUserAgent static method, Updated default value for domStorageEnabled option to true
This was referenced Jul 6, 2020
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 12, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant