WXBridgeProtocol.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing,
  13. * software distributed under the License is distributed on an
  14. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. * KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations
  17. * under the License.
  18. */
  19. #import <JavaScriptCore/JavaScriptCore.h>
  20. typedef NSInteger(^WXJSCallNative)(NSString *instance, NSArray *tasks, NSString *callback);
  21. typedef NSInteger(^WXJSCallAddElement)(NSString *instanceId, NSString *parentRef, NSDictionary *elementData, NSInteger index);
  22. typedef NSInteger(^WXJSCallCreateBody)(NSString *instanceId, NSDictionary *bodyData);
  23. typedef NSInteger(^WXJSCallRemoveElement)(NSString *instanceId,NSString *ref);
  24. typedef NSInteger(^WXJSCallMoveElement)(NSString *instanceId,NSString *ref,NSString *parentRef,NSInteger index);
  25. typedef NSInteger(^WXJSCallUpdateAttrs)(NSString *instanceId,NSString *ref,NSDictionary *attrsData);
  26. typedef NSInteger(^WXJSCallUpdateStyle)(NSString *instanceId,NSString *ref,NSDictionary *stylesData);
  27. typedef NSInteger(^WXJSCallAddEvent)(NSString *instanceId,NSString *ref,NSString *event);
  28. typedef NSInteger(^WXJSCallRemoveEvent)(NSString *instanceId,NSString *ref,NSString *event);
  29. typedef NSInteger(^WXJSCallCreateFinish)(NSString *instanceId);
  30. typedef NSInteger(^WXJSCallRefreshFinish)(NSString *instanceId);
  31. typedef NSInteger(^WXJSCallUpdateFinish)(NSString *instanceId);
  32. typedef NSInvocation *(^WXJSCallNativeModule)(NSString *instanceId, NSString *moduleName, NSString *methodName, NSArray *args, NSDictionary *options);
  33. typedef void (^WXJSCallNativeComponent)(NSString *instanceId, NSString *componentRef, NSString *methodName, NSArray *args, NSDictionary *options);
  34. @protocol WXBridgeProtocol <NSObject>
  35. @property (nonatomic, readonly) JSValue* exception;
  36. /**
  37. * Executes the js framework code in javascript engine
  38. * You can do some setup in this method
  39. */
  40. - (void)executeJSFramework:(NSString *)frameworkScript;
  41. /**
  42. * Executes the js code in javascript engine
  43. * You can do some setup in this method
  44. */
  45. - (void)executeJavascript:(NSString *)script;
  46. /**
  47. * Executes global js method with specific arguments
  48. */
  49. - (JSValue *)callJSMethod:(NSString *)method args:(NSArray*)args;
  50. /**
  51. * Reset js engine environment, called when any environment variable is changed.
  52. */
  53. - (void)resetEnvironment;
  54. @optional
  55. /**
  56. * Remove instance's timer.
  57. */
  58. -(void)removeTimers:(NSString *)instance;
  59. /**
  60. * Called when garbage collection is wanted by sdk.
  61. */
  62. - (void)garbageCollect;
  63. @required
  64. /**
  65. * Register callback when call native tasks occur
  66. */
  67. - (void)registerCallNative:(WXJSCallNative)callNative;
  68. /**
  69. * Register callback when addElement tasks occur
  70. */
  71. - (void)registerCallAddElement:(WXJSCallAddElement)callAddElement;
  72. /**
  73. * Register callback when createBody tasks occur
  74. */
  75. - (void)registerCallCreateBody:(WXJSCallCreateBody)callCreateBody;
  76. /**
  77. * Register callback when removeElement tasks occur
  78. */
  79. - (void)registerCallRemoveElement:(WXJSCallRemoveElement)callRemoveElement;
  80. /**
  81. * Register callback when removeElement tasks occur
  82. */
  83. - (void)registerCallMoveElement:(WXJSCallMoveElement)callMoveElement;
  84. /**
  85. * Register callback when updateAttrs tasks occur
  86. */
  87. - (void)registerCallUpdateAttrs:(WXJSCallUpdateAttrs)callUpdateAttrs;
  88. /**
  89. * Register callback when updateStyle tasks occur
  90. */
  91. - (void)registerCallUpdateStyle:(WXJSCallUpdateStyle)callUpdateStyle;
  92. /**
  93. * Register callback when addEvent tasks occur
  94. */
  95. - (void)registerCallAddEvent:(WXJSCallAddEvent)callAddEvent;
  96. /**
  97. * Register callback when removeEvent tasks occur
  98. */
  99. - (void)registerCallRemoveEvent:(WXJSCallRemoveEvent)callRemoveEvent;
  100. /**
  101. * Register callback when createFinish tasks occur
  102. */
  103. - (void)registerCallCreateFinish:(WXJSCallCreateFinish)callCreateFinish;
  104. /**
  105. * Register callback for global js function `callNativeModule`
  106. */
  107. - (void)registerCallNativeModule:(WXJSCallNativeModule)callNativeModuleBlock;
  108. /**
  109. * Register callback for global js function `callNativeComponent`
  110. */
  111. - (void)registerCallNativeComponent:(WXJSCallNativeComponent)callNativeComponentBlock;
  112. @optional
  113. /**
  114. * Register callback when refreshFinish tasks occur
  115. */
  116. - (void)registerCallRefreshFinish:(WXJSCallRefreshFinish)callRefreshFinish;
  117. /**
  118. * Register callback when updateFinish tasks occur
  119. */
  120. - (void)registerCallUpdateFinish:(WXJSCallUpdateFinish)callUpdateFinish;
  121. /*
  122. * Executes the specified JavaScript code, treating the specified URL as its source location.
  123. * Evaluating a script runs any top-level code and adds function or object definitions to the brige’s global object.
  124. * The sourceURL parameter is informative only; debuggers may use this URL when reporting exceptions.
  125. @param script The JavaScript source code to evaluate.
  126. @param sourceURL A URL to be considered as the script’s origin.
  127. @return ReturnsThe last value generated by the script. Note that a script can result in the JavaScript value undefined.
  128. */
  129. - (JSValue *)executeJavascript:(NSString *)script withSourceURL:(NSURL*)sourceURL;
  130. @property (nonatomic, strong) NSString* weexInstanceId;
  131. /**
  132. set JavaScriptContext
  133. */
  134. - (void)setJSContext:(JSContext*)context;
  135. /*
  136. * javaScript runtime context
  137. */
  138. - (JSContext*)javaScriptContext;
  139. @end