Skip to content

Commit 187b4a6

Browse files
committed
+ [ios] update sdk restart and loglevel
1 parent 6ca9672 commit 187b4a6

18 files changed

+155
-57
lines changed

ios/WXDevtool/inspector/PonyDebugger/PDDebugger.m

+2-1
Original file line numberDiff line numberDiff line change
@@ -573,13 +573,14 @@ -(void)_evaluateNative:(NSString *)data
573573
return;
574574
}
575575
//call native
576-
WXLogLog(@"Calling native... instancdId:%@, methods:%@, callbackId:%@", instanceId, [WXUtility JSONString:methods], callbackId);
576+
WXLogDebug(@"Calling native... instancdId:%@, methods:%@, callbackId:%@", instanceId, [WXUtility JSONString:methods], callbackId);
577577
_nativeCallBlock(instanceId, methods, callbackId);
578578
}
579579

580580
if ([method isEqualToString:@"reload"]) {
581581
dispatch_async(dispatch_get_main_queue(), ^{
582582
[WXSDKEngine restart];
583+
[[NSNotificationCenter defaultCenter] postNotificationName:@"RefreshInstance" object:nil];
583584
});
584585
}
585586
}

ios/playground/WeexDemo/Scanner/WXScannerVC.m

+7-2
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ - (void)viewDidLoad {
5050
_captureLayer = [AVCaptureVideoPreviewLayer layerWithSession:_session];
5151
_captureLayer.videoGravity=AVLayerVideoGravityResizeAspectFill;
5252
_captureLayer.frame=self.view.layer.bounds;
53+
5354
}
5455

5556
- (void)viewWillAppear:(BOOL)animated {
@@ -162,8 +163,11 @@ - (BOOL)remoteDebug:(NSURL *)url
162163

163164
[WXSDKEngine restart];
164165

165-
[WXSDKEngine registerComponent:@"select" withClass:NSClassFromString(@"WXSelectComponent")];
166-
[WXSDKEngine registerModule:@"event" withClass:NSClassFromString(@"WXEventModule")];
166+
if ([[[self.navigationController viewControllers] objectAtIndex:0] isKindOfClass:NSClassFromString(@"WXDemoViewController")]) {
167+
WXDemoViewController * vc = (WXDemoViewController*)[[self.navigationController viewControllers] objectAtIndex:0];
168+
[self.navigationController popToViewController:vc animated:NO];
169+
}
170+
[[NSNotificationCenter defaultCenter] postNotificationName:@"RefreshInstance" object:nil];
167171

168172
return YES;
169173
}
@@ -173,4 +177,5 @@ - (BOOL)remoteDebug:(NSURL *)url
173177
}
174178
#pragma clang diagnostic pop
175179

180+
176181
@end

ios/playground/WeexDemo/WXDemoViewController.m

+9-1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ - (void)viewDidLoad
4949

5050
_weexHeight = self.view.frame.size.height - 64;
5151

52+
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationRefreshInstance:) name:@"RefreshInstance" object:nil];
53+
5254
[self render];
5355
}
5456

@@ -77,6 +79,7 @@ - (void)didReceiveMemoryWarning {
7779
- (void)dealloc
7880
{
7981
[_instance destroyInstance];
82+
[[NSNotificationCenter defaultCenter] removeObserver:self];
8083
}
8184

8285
- (void)render
@@ -115,7 +118,7 @@ - (void)render
115118
};
116119

117120
_instance.updateFinish = ^(UIView *view) {
118-
WXLogVerbose(@"%@", @"Update Finish...");
121+
WXLogDebug(@"%@", @"Update Finish...");
119122
};
120123
if (!self.url) {
121124
WXLogError(@"error: render url is nil");
@@ -209,4 +212,9 @@ - (NSURL*)testURL:(NSString*)url
209212
return [NSURL URLWithString:url];
210213
}
211214

215+
#pragma mark - notification
216+
- (void)notificationRefreshInstance:(NSNotification *)notification {
217+
[self refreshWeex];
218+
}
219+
212220
@end

ios/sdk/WeexSDK/Sources/Bridge/WXBridgeContext.m

+2-2
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,9 @@ - (void)executeJsFramework:(NSString *)script
232232

233233
__weak __typeof__(self) weakSelf = self;
234234
[WXBridgeContext _timeSince:^() {
235-
WXLogLog(@"JSFramework starts executing...");
235+
WXLogDebug(@"JSFramework starts executing...");
236236
[self.jsBridge executeJSFramework:script];
237-
WXLogLog(@"JSFramework ends executing...");
237+
WXLogDebug(@"JSFramework ends executing...");
238238
if ([self.jsBridge exception]) {
239239
[WXSDKError monitorAlarm:NO errorCode:WX_ERR_LOAD_JSLIB msg:@"JSFramework executes error !"];
240240
}

ios/sdk/WeexSDK/Sources/Bridge/WXDebugLoggerBridge.m

+2-2
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ -(void)_evaluateNative:(NSString *)data
9797
return;
9898
}
9999
//call native
100-
WXLogLog(@"Calling native... instancdId:%@, methods:%@, callbackId:%@", instanceId, [WXUtility JSONString:methods], callbackId);
100+
WXLogDebug(@"Calling native... instancdId:%@, methods:%@, callbackId:%@", instanceId, [WXUtility JSONString:methods], callbackId);
101101
_nativeCallBlock(instanceId, methods, callbackId);
102102
} else if ([method isEqualToString:@"setLogLevel"]) {
103103
NSString *levelString = [args firstObject];
@@ -116,7 +116,7 @@ - (void)callJSMethod:(NSString *)method args:(NSArray *)args
116116
{
117117
if (![method isEqualToString:@"__logger"]) {
118118
// prevent recursion
119-
WXLogLog(@"Calling JS... method:%@, args:%@", method, [WXUtility JSONString:args]);
119+
WXLogDebug(@"Calling JS... method:%@, args:%@", method, [WXUtility JSONString:args]);
120120
}
121121

122122
NSMutableDictionary *dict = [NSMutableDictionary dictionary];

ios/sdk/WeexSDK/Sources/Bridge/WXJSCoreBridge.m

+3-3
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ - (instancetype)init
6363
if (idx == args.count - 1) {
6464
NSNumber *flag = levelMap[[jsVal toString]];
6565
if (flag) {
66-
WXLOG([flag unsignedIntegerValue], @"%@", string);
66+
WX_LOG([flag unsignedIntegerValue], @"%@", string);
6767
} else {
6868
[string appendFormat:@"%@ ", jsVal];
6969
WXLogInfo(@"%@", string);
@@ -94,7 +94,7 @@ - (void)executeJSFramework:(NSString *)frameworkScript
9494

9595
- (void)callJSMethod:(NSString *)method args:(NSArray *)args
9696
{
97-
WXLogLog(@"Calling JS... method:%@, args:%@", method, args);
97+
WXLogDebug(@"Calling JS... method:%@, args:%@", method, args);
9898
[[_jsContext globalObject] invokeMethod:method withArguments:args];
9999
}
100100

@@ -104,7 +104,7 @@ - (void)registerCallNative:(WXJSCallNative)callNative
104104
NSString *instanceId = [instance toString];
105105
NSArray *tasksArray = [tasks toArray];
106106
NSString *callbackId = [callback toString];
107-
WXLogLog(@"Calling native... instance:%@, tasks:%@, callback:%@", instanceId, tasksArray, callbackId);
107+
WXLogDebug(@"Calling native... instance:%@, tasks:%@, callback:%@", instanceId, tasksArray, callbackId);
108108
callNative(instanceId, tasksArray, callbackId);
109109
};
110110

ios/sdk/WeexSDK/Sources/Component/WXAComponent.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ - (void)openURL
4848
withContainer:)]) {
4949
__weak typeof(self) weexSelf = self;
5050
[navigationHandler pushViewControllerWithParam:@{@"url":_href} completion:^(NSString *code, NSDictionary *responseData) {
51-
WXLogLog(@"Push success -> %@", weexSelf.href);
51+
WXLogDebug(@"Push success -> %@", weexSelf.href);
5252
} withContainer:self.weexInstance.viewController];
5353
} else {
5454
WXLogError(@"Event handler of class %@ does not respond to pushViewControllerWithParam", NSStringFromClass([navigationHandler class]));

ios/sdk/WeexSDK/Sources/Component/WXImageComponent.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ - (void)updateImage
164164
if (weakSelf.imageSrc) {
165165
NSString *imageSrc = weakSelf.imageSrc;
166166
NSDictionary *userInfo = @{@"imageQuality":@(weakSelf.imageQuality), @"imageSharp":@(weakSelf.imageSharp)};
167-
WXLogLog(@"Updating image, component:%@, image source:%@, userInfo:%@", self.ref, imageSrc, userInfo);
167+
WXLogDebug(@"Updating image, component:%@, image source:%@, userInfo:%@", self.ref, imageSrc, userInfo);
168168
weakSelf.imageOperation = [[weakSelf imageLoader] downloadImageWithURL:imageSrc imageFrame:weakSelf.calculatedFrame userInfo:userInfo completed:^(UIImage *image, NSError *error, BOOL finished) {
169169
dispatch_async(dispatch_get_main_queue(), ^{
170170
__strong typeof(self) strongSelf = weakSelf;

ios/sdk/WeexSDK/Sources/Component/WXListComponent.m

+4-4
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ - (void)cellDidRemove:(WXCellComponent *)cell
147147
[_cellComponents removeObject:cell];
148148
[_completedCells removeObject:cell];
149149

150-
WXLogLog(@"Delete cell:%@ at row:%ld", cell.ref, (long)indexPath.row);
150+
WXLogDebug(@"Delete cell:%@ at row:%ld", cell.ref, (long)indexPath.row);
151151
[UIView performWithoutAnimation:^{
152152
[_tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationNone];
153153
}];
@@ -178,7 +178,7 @@ - (void)cellDidLayout:(WXCellComponent *)cell
178178
if (![_completedCells containsObject:cell]) {
179179
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:row inSection:0];
180180
[_completedCells addObject:cell];
181-
WXLogLog(@"Insert cell:%@ at row:%ld", cell.ref, (long)indexPath.row);
181+
WXLogDebug(@"Insert cell:%@ at row:%ld", cell.ref, (long)indexPath.row);
182182
[UIView performWithoutAnimation:^{
183183
[_tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationNone];
184184
}];
@@ -288,7 +288,7 @@ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger
288288

289289
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
290290
{
291-
WXLogLog(@"Getting cell at row:%ld", (long)indexPath.row);
291+
WXLogDebug(@"Getting cell at row:%ld", (long)indexPath.row);
292292
static NSString *reuseIdentifier = @"WXTableViewCell";
293293

294294
UITableViewCell *cellView = [_tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
@@ -320,7 +320,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
320320

321321
[cellView.contentView addSubview:cell.view];
322322

323-
WXLogLog(@"Created cell:%@ view:%@ cellView:%@ at row:%ld", cell.ref, cell.view, cellView, (long)indexPath.row);
323+
WXLogDebug(@"Created cell:%@ view:%@ cellView:%@ at row:%ld", cell.ref, cell.view, cellView, (long)indexPath.row);
324324
return cellView;
325325
}
326326

ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.m

+47-2
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ + (void)registerComponent:(NSString *)name withClass:(Class)clazz withProperties
8989

9090
WXAssert(name && clazz, @"Fail to register the component, please check if the parameters are correct !");
9191

92-
[WXComponentFactory registerComponent:name withClass:clazz];
92+
[WXComponentFactory registerComponent:name withClass:clazz withPros:properties];
9393

9494
if (properties) {
9595
NSMutableDictionary *props = [properties mutableCopy];
@@ -175,9 +175,24 @@ + (NSString*)SDKEngineVersion
175175

176176
+ (void)restart
177177
{
178+
NSDictionary *components = [WXComponentFactory componentConfigs];
179+
NSDictionary *modules = [WXModuleFactory moduleConfigs];
180+
NSDictionary *handlers = [WXHandlerFactory handlerConfs];
178181
[WXSDKManager unload];
179182
[WXComponentFactory unregisterAllComponents];
180-
[self initSDKEnviroment];
183+
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"main" ofType:@"js"];
184+
NSString *script = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];
185+
if (!script || script.length <= 0) {
186+
[WXSDKError monitorAlarm:NO errorCode:WX_ERR_LOAD_JSLIB msg:@"framework loading is failure!"];
187+
return;
188+
}
189+
190+
[self _originalRegisterComponents:components];
191+
[self _originalRegisterModules:modules];
192+
[self _originalRegisterHandlers:handlers];
193+
194+
[[WXSDKManager bridgeMgr] executeJsFramework:script];
195+
[WXUtility addStatTrack:[WXAppConfiguration appName]];
181196
}
182197

183198
+ (void)connectDebugServer:(NSString*)URL
@@ -191,4 +206,34 @@ + (void)connectDevToolServer:(NSString *)URL
191206

192207
}
193208

209+
+ (void)_originalRegisterComponents:(NSDictionary *)components {
210+
void (^componentBlock)(id, id, BOOL *) = ^(id mKey, id mObj, BOOL * mStop) {
211+
212+
NSString *name = mObj[@"name"];
213+
NSString *componentClass = mObj[@"clazz"];
214+
NSDictionary *pros = nil;
215+
if (mObj[@"pros"]) {
216+
pros = mObj[@""];
217+
}
218+
[self registerComponent:name withClass:NSClassFromString(componentClass) withProperties:pros];
219+
};
220+
[components enumerateKeysAndObjectsUsingBlock:componentBlock];
221+
222+
}
223+
224+
+ (void)_originalRegisterModules:(NSDictionary *)modules {
225+
void (^moduleBlock)(id, id, BOOL *) = ^(id mKey, id mObj, BOOL * mStop) {
226+
227+
[self registerModule:mKey withClass:NSClassFromString(mObj)];
228+
};
229+
[modules enumerateKeysAndObjectsUsingBlock:moduleBlock];
230+
}
231+
232+
+ (void)_originalRegisterHandlers:(NSDictionary *)handlers {
233+
void (^handlerBlock)(id, id, BOOL *) = ^(id mKey, id mObj, BOOL * mStop) {
234+
[self registerHandler:mObj withProtocol:NSProtocolFromString(mKey)];
235+
};
236+
[handlers enumerateKeysAndObjectsUsingBlock:handlerBlock];
237+
}
238+
194239
@end

ios/sdk/WeexSDK/Sources/Manager/WXComponentFactory.h

+7-1
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515
*
1616
* @param name The component name to register;
1717
* @param clazz The WXComponent subclass to register
18+
* @param pros The component properties to register
1819
*/
19-
+ (void)registerComponent:(NSString *)name withClass:(Class)clazz;
20+
+ (void)registerComponent:(NSString *)name withClass:(Class)clazz withPros:(NSDictionary *)pros;
2021

2122
/**
2223
* @abstract Register a list of components
@@ -36,5 +37,10 @@
3637
*/
3738
+ (Class)classWithComponentName:(NSString *)name;
3839

40+
/**
41+
* @abstract Returns the registered components.
42+
*/
43+
+ (NSDictionary *)componentConfigs;
44+
3945

4046
@end

ios/sdk/WeexSDK/Sources/Manager/WXComponentFactory.m

+29-7
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,20 @@ @interface WXComponentConfig : NSObject
1414

1515
@property (nonatomic, strong) NSString *name;
1616
@property (nonatomic, strong) NSString *clazz;
17+
@property (nonatomic, strong) NSDictionary *properties;
1718

18-
- (instancetype)initWithName:(NSString *)name class:(NSString *)clazz;
19+
- (instancetype)initWithName:(NSString *)name class:(NSString *)clazz pros:(NSDictionary *)pros;
1920

2021
@end
2122

2223
@implementation WXComponentConfig
2324

24-
- (instancetype)initWithName:(NSString *)name class:(NSString *)clazz
25+
- (instancetype)initWithName:(NSString *)name class:(NSString *)clazz pros:(NSDictionary *)pros
2526
{
2627
if (self = [super init]) {
2728
_name = name;
2829
_clazz = clazz;
30+
_properties = pros;
2931
}
3032

3133
return self;
@@ -66,9 +68,9 @@ + (Class)classWithComponentName:(NSString *)name
6668
return [[self sharedInstance] classWithComponentName:name];
6769
}
6870

69-
+ (void)registerComponent:(NSString *)name withClass:(Class)clazz
71+
+ (void)registerComponent:(NSString *)name withClass:(Class)clazz withPros:(NSDictionary *)pros
7072
{
71-
[[self sharedInstance] registerComponent:name withClass:clazz];
73+
[[self sharedInstance] registerComponent:name withClass:clazz withPros:pros];
7274
}
7375

7476
+ (void)registerComponents:(NSArray *)components
@@ -81,8 +83,28 @@ + (void)unregisterAllComponents
8183
[[self sharedInstance] unregisterAllComponents];
8284
}
8385

86+
+ (NSDictionary *)componentConfigs {
87+
return [[self sharedInstance] getComponentConfigs];
88+
}
89+
8490
#pragma mark Private
8591

92+
- (NSDictionary *)getComponentConfigs {
93+
NSMutableDictionary *componentDic = [[NSMutableDictionary alloc] init];
94+
void (^componentBlock)(id, id, BOOL *) = ^(id mKey, id mObj, BOOL * mStop) {
95+
WXComponentConfig *componentConfig = (WXComponentConfig *)mObj;
96+
NSMutableDictionary *configDic = [[NSMutableDictionary alloc] init];
97+
[configDic setObject:componentConfig.name forKey:@"name"];
98+
[configDic setObject:componentConfig.clazz forKey:@"clazz"];
99+
if (componentConfig.properties) {
100+
[configDic setObject:componentConfig.properties forKey:@"pros"];
101+
}
102+
[componentDic setObject:configDic forKey:componentConfig.name];
103+
};
104+
[_componentConfigs enumerateKeysAndObjectsUsingBlock:componentBlock];
105+
return componentDic;
106+
}
107+
86108
- (Class)classWithComponentName:(NSString *)name
87109
{
88110
WXAssert(name, @"Can not find class for a nil component name");
@@ -104,7 +126,7 @@ - (Class)classWithComponentName:(NSString *)name
104126
return NSClassFromString(config.clazz);
105127
}
106128

107-
- (void)registerComponent:(NSString *)name withClass:(Class)clazz
129+
- (void)registerComponent:(NSString *)name withClass:(Class)clazz withPros:(NSDictionary *)pros
108130
{
109131
WXAssert(name && clazz, @"name or clazz must not be nil for registering component.");
110132

@@ -117,7 +139,7 @@ - (void)registerComponent:(NSString *)name withClass:(Class)clazz
117139
config.name, config.class, name, clazz);
118140
}
119141

120-
config = [[WXComponentConfig alloc] initWithName:name class:NSStringFromClass(clazz)];
142+
config = [[WXComponentConfig alloc] initWithName:name class:NSStringFromClass(clazz) pros:pros];
121143
[_componentConfigs setValue:config forKey:name];
122144
[_configLock unlock];
123145
}
@@ -133,7 +155,7 @@ - (void)registerComponents:(NSArray *)components
133155
NSString *clazz = dict[@"class"];
134156
WXAssert(name && clazz, @"name or clazz must not be nil for registering components.");
135157

136-
WXComponentConfig *config = [[WXComponentConfig alloc] initWithName:name class:clazz];
158+
WXComponentConfig *config = [[WXComponentConfig alloc] initWithName:name class:clazz pros:nil];
137159
if(config){
138160
[_componentConfigs setValue:config forKey:name];
139161
}

ios/sdk/WeexSDK/Sources/Manager/WXHandlerFactory.h

+5
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,9 @@
2626
**/
2727
+ (id)handlerForProtocol:(Protocol *)protocol;
2828

29+
/**
30+
* @abstract Returns the registered handlers.
31+
*/
32+
+ (NSDictionary *)handlerConfs;
33+
2934
@end

ios/sdk/WeexSDK/Sources/Manager/WXHandlerFactory.m

+4
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,8 @@ + (id)handlerForProtocol:(Protocol *)protocol
4646
return handler;
4747
}
4848

49+
+ (NSDictionary *)handlerConfs {
50+
return [WXHandlerFactory sharedInstance].handlers;
51+
}
52+
4953
@end

0 commit comments

Comments
 (0)