Native external interface

  • Register the SDK’s default Modules, handlers, and Components
  • Register custom Modules, handlers, and Components
  • Reset JSFramework

Handler (Adapter corresponding to Android) is introduced

  • WXImgLoaderDefaultImpl Image download handler. Weex will reveal the View and URL of the image to be set. Native terminal needs to implement this interface for image download. The WeexSDK kernel itself does not provide a default implementation for image downloading.

The interface is defined as follows:

  @protocol WXImgLoaderProtocol <WXModuleProtocol>
/** * @abstract Creates a image download handler with a given URL * * @param imageUrl The URL of the image to download *  * @param imageFrame The frame of the image you want to set * * @param options : The options to be used for this download * * @param completedBlock : A block called once the download is completed. * image : the image which has been download to local. * error : the error which has happened in download. * finished : a Boolean value indicating whether download action has finished. */
- (id<WXImageOperationProtocol>)downloadImageWithURL:(NSString *)url imageFrame:(CGRect)imageFrame userInfo:(NSDictionary *)options completed:(void(^) (UIImage *image,  NSError *error, BOOL finished))completedBlock;
@end
Copy the code

Native and JS communication

  • Custom notification events

Practice notifications for native custom parts and JS, such as passing pull-down events to js, which are methods in the Component base class that can be used directly

/** * @abstract Fire an event to the component and tell Javascript which value has been changed. * @param eventName The event name can be monitored in a tag component of the WEEX file. The name is onXXX * @param params data * @param domChanges Changed data **/
- (void)fireEvent:(NSString *)eventName params:(NSDictionary *)params domChanges:(NSDictionary *)domChanges

Copy the code
  • Event callback

It is mainly used for Module callback results to JS. The callback types are divided into the following two types:

1.WXModuleCallback For performance reasons, this callback can only call back the notification JS once, and is then released for more than one result

2. WXModuleKeepAliveCallback the callback can set whether or not to callback types for many times, many times the callback scenario such as continuing to monitor the change of position, and returned to the js.

@implementation WXEchoModule
@synthesize weexInstance; // Let the module get the current instance
WX_EXPORT_METHOD(@selector(echo:))
- (void)echo:(NSString *)param callback:(WXModuleKeepAliveCallback)callback
{
  callback(param,ture);// Set this to true, the callback function can be executed multiple times, and the loop test can be written.
}
Copy the code

Dynamically adapted container

WeexSDK provides the method setFrame(CGRect) in the WXSDKInstance class to change the size of the container.

For example: In the navigation bar from have to nothing process, need to change the weexView, you can call this method setting at this time

degrade

Weex will add some new features and functions in the development stage, but these new features and functions must be upgraded to the SDK to implement, how to deal with the application that is not upgraded? You can use the degrade function.

The degraded feature is a version or phone that doesn’t work with Weex. It can be replaced by Weex H5.

The Native terminal can handle the fault through the onFailed callback in interface WXSDKInstance. If the fault is degraded actively, the returned error domain is TemplateErrorType, and the Native terminal can jump to the corresponding H5 page. You can also use other methods to inform the user that the current environment does not support Weex.