Skip to content

Commit d26ef73

Browse files
authored
Merge pull request alibaba#2203 from boboning/ios-feature-navigator
* [ios] update navigator module, add open and close interface.
2 parents 4f65b4d + 58a3ffc commit d26ef73

File tree

2 files changed

+42
-17
lines changed

2 files changed

+42
-17
lines changed

ios/sdk/WeexSDK/Sources/Module/WXNavigatorModule.m

+16-12
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ @implementation WXNavigatorModule
1818

1919
@synthesize weexInstance;
2020

21+
WX_EXPORT_METHOD(@selector(open:success:failure:))
22+
WX_EXPORT_METHOD(@selector(close:success:failure:))
2123
WX_EXPORT_METHOD(@selector(push:callback:))
2224
WX_EXPORT_METHOD(@selector(pop:callback:))
23-
WX_EXPORT_METHOD(@selector(close:callback:))
2425
WX_EXPORT_METHOD(@selector(setNavBarBackgroundColor:callback:))
2526
WX_EXPORT_METHOD(@selector(setNavBarLeftItem:callback:))
2627
WX_EXPORT_METHOD(@selector(clearNavBarLeftItem:callback:))
@@ -40,33 +41,36 @@ @implementation WXNavigatorModule
4041

4142
#pragma mark Weex Application Interface
4243

43-
- (void)push:(NSDictionary *)param callback:(WXModuleCallback)callback
44+
- (void)open:(NSDictionary *)param success:(WXModuleCallback)success failure:(WXModuleCallback)failure
4445
{
4546
id<WXNavigationProtocol> navigator = [self navigator];
4647
UIViewController *container = self.weexInstance.viewController;
47-
[navigator pushViewControllerWithParam:param completion:^(NSString *code, NSDictionary *responseData) {
48-
if (callback && code) {
49-
callback(code);
50-
}
51-
} withContainer:container];
48+
[navigator open:param success:success failure:failure withContainer:container];
5249
}
53-
54-
- (void)pop:(NSDictionary *)param callback:(WXModuleCallback)callback
50+
51+
- (void)close:(NSDictionary *)param success:(WXModuleCallback)success failure:(WXModuleCallback)failure
5552
{
5653
id<WXNavigationProtocol> navigator = [self navigator];
5754
UIViewController *container = self.weexInstance.viewController;
58-
[navigator popViewControllerWithParam:param completion:^(NSString *code, NSDictionary *responseData) {
55+
[navigator close:param success:success failure:failure withContainer:container];
56+
}
57+
58+
- (void)push:(NSDictionary *)param callback:(WXModuleCallback)callback
59+
{
60+
id<WXNavigationProtocol> navigator = [self navigator];
61+
UIViewController *container = self.weexInstance.viewController;
62+
[navigator pushViewControllerWithParam:param completion:^(NSString *code, NSDictionary *responseData) {
5963
if (callback && code) {
6064
callback(code);
6165
}
6266
} withContainer:container];
6367
}
6468

65-
- (void)close:(NSDictionary *)param callback:(WXModuleCallback)callback
69+
- (void)pop:(NSDictionary *)param callback:(WXModuleCallback)callback
6670
{
6771
id<WXNavigationProtocol> navigator = [self navigator];
6872
UIViewController *container = self.weexInstance.viewController;
69-
[navigator popToRootViewControllerWithParam:param completion:^(NSString *code, NSDictionary *responseData) {
73+
[navigator popViewControllerWithParam:param completion:^(NSString *code, NSDictionary *responseData) {
7074
if (callback && code) {
7175
callback(code);
7276
}

ios/sdk/WeexSDK/Sources/Protocol/WXNavigationProtocol.h

+26-5
Original file line numberDiff line numberDiff line change
@@ -119,18 +119,39 @@ typedef void (^WXNavigationResultBlock)(NSString *code, NSDictionary * responseD
119119
completion:(WXNavigationResultBlock)block
120120
withContainer:(UIViewController *)container;
121121

122+
123+
@optional
124+
122125
/**
123-
* @abstract Pops all the view controllers on the stack except the root view controller.
126+
* @abstract open the resource at the specified URL which supports many common schemes, including the http, https, tel and mailto schemes.
124127
*
125128
* @param param The data which is passed to the implementation of the protocol.
126129
*
127-
* @param block A block called once the action is completed.
130+
* @param block A block called once the action is completed successfully.
131+
*
132+
* @param block A block called once the action failed to be completed.
128133
*
129134
* @param container The target controller.
130135
*
131136
*/
132-
- (void)popToRootViewControllerWithParam:(NSDictionary *)param
133-
completion:(WXNavigationResultBlock)block
134-
withContainer:(UIViewController *)container;
137+
- (void)open:(NSDictionary *)param success:(WXModuleCallback)success
138+
failure:(WXModuleCallback)failure
139+
withContainer:(UIViewController *)container;
135140

141+
142+
/**
143+
* @abstract close the current weex page
144+
*
145+
* @param param The data which is passed to the implementation of the protocol.
146+
*
147+
* @param block A block called once the action is completed successfully.
148+
*
149+
* @param block A block called once the action failed to be completed.
150+
*
151+
* @param container The target controller.
152+
*
153+
*/
154+
- (void)close:(NSDictionary *)param success:(WXModuleCallback)success
155+
failure:(WXModuleCallback)failure
156+
withContainer:(UIViewController *)container;
136157
@end

0 commit comments

Comments
 (0)