File tree Expand file tree Collapse file tree 2 files changed +10
-4
lines changed
easybridge/src/main/assets Expand file tree Collapse file tree 2 files changed +10
-4
lines changed Original file line number Diff line number Diff line change 1111 document . addEventListener ( 'WebViewJavascriptBridgeReady' ,
1212 function ( ) {
1313 toast ( 'inject finished' ) ;
14- window [ ' easyBridge' ] . resultBack = function ( parameters , callback ) {
14+ window . easyBridge . registerHandler ( ' resultBack' , function ( parameters , callback ) {
1515 if ( typeof callback == 'function' ) {
1616 callback ( parameters ) ;
1717 }
18- } ;
18+ } ) ;
1919 } , false ) ;
2020
2121 function toast ( params = 'toast data' ) {
22- window [ ' easyBridge' ] . callHandler ( 'toast' , 'toast with:' + params + 'at ' + new Date ( ) . toLocaleString ( ) ) ;
22+ window . easyBridge . callHandler ( 'toast' , 'toast with:' + params + 'at ' + new Date ( ) . toLocaleString ( ) ) ;
2323 }
2424 </ script >
2525</ head >
Original file line number Diff line number Diff line change 3131 parameters = args || { } ;
3232 parameters = JSON . stringify ( parameters ) ;
3333 }
34- //the name '_easybridge' is an java object that mapping to a javascript onject ,using addJavaInterface in Java code
34+ //the name '_easybridge' is an java object that mapping to a javascript object ,using addJavaInterface in Java code
3535 if ( window . _easybridge ) {
3636 setTimeout ( function ( ) {
3737 //the function enqueue is the pubic method from Java Code,using to call Java logic
4242 }
4343 }
4444
45+ //the function for JavaScript to register handler that Java Code Can Executed
46+ function registerHandler ( handlerName , handler ) {
47+ window [ bridgeName ] [ handlerName ] = handler ;
48+ }
49+
4550 //the function for Java Code to invoked JavaScript function
4651 function _executeScript ( handlerName , parameters , callbackId ) {
4752 if ( ! handlerName ) {
104109 //init the bridge object
105110 window [ bridgeName ] = {
106111 callHandler : callHandler ,
112+ registerHandler : registerHandler ,
107113 _executeScript : _executeScript ,
108114 _dispatchResult : _dispatchResult ,
109115
You can’t perform that action at this time.
0 commit comments