Skip to content
This repository has been archived by the owner on Jun 3, 2021. It is now read-only.

Commit

Permalink
[iOS] add callback on wxcomponent
Browse files Browse the repository at this point in the history
  • Loading branch information
jianhan-he committed May 8, 2019
1 parent 650cb5b commit 4e858e6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
13 changes: 13 additions & 0 deletions ios/sdk/WeexSDK/Sources/Model/WXComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ typedef enum : NSUInteger {
WXDisplayTypeBlock
} WXDisplayType;

typedef enum : NSUInteger {
WXComponentViewCreatedCallback
} WXComponentCallbackType;

/**
* @abstract the component callback , result can be string or dictionary.
* @discussion callback data to js, the id of callback function will be removed to save memory.
Expand Down Expand Up @@ -169,6 +173,15 @@ NS_ASSUME_NONNULL_BEGIN
*/
- (nullable CGSize (^)(CGSize constrainedSize))measureBlock;

/**
* The callback of the component
*
* When the callbackType is WXComponentViewCreatedCallback, the result type is UIView.
*
* @return A block that takes component, callbackType and a result.
**/
@property (nonatomic, copy) void (^componentCallback)(WXComponent *component, WXComponentCallbackType callbackType, id result);

/**
* @abstract Called on main thread when the component has just laid out.
*/
Expand Down
3 changes: 3 additions & 0 deletions ios/sdk/WeexSDK/Sources/View/WXComponent+ViewManagement.mm
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ - (void)viewWillLoad
- (void)viewDidLoad
{
WXAssertMainThread();
if (self.componentCallback) {
self.componentCallback(self, WXComponentViewCreatedCallback, _view);
}
}

- (void)viewWillUnload
Expand Down

0 comments on commit 4e858e6

Please sign in to comment.