You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@weex.apache.org by GitBox <gi...@apache.org> on 2018/10/09 03:12:27 UTC

[GitHub] cxfeng1 closed pull request #1621: Fix instance double render

cxfeng1 closed pull request #1621: Fix instance double render
URL: https://github.com/apache/incubator-weex/pull/1621
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/ios/sdk/WeexSDK/Sources/Component/WXEditComponent.mm b/ios/sdk/WeexSDK/Sources/Component/WXEditComponent.mm
index d93b19c75b..0df57d8d0f 100644
--- a/ios/sdk/WeexSDK/Sources/Component/WXEditComponent.mm
+++ b/ios/sdk/WeexSDK/Sources/Component/WXEditComponent.mm
@@ -904,8 +904,9 @@ - (void)keyboardWasShown:(NSNotification*)notification
     if(![self.view isFirstResponder]) {
         return;
     }
+    
+    CGRect end = [[[notification userInfo] objectForKey:@"UIKeyboardFrameEndUserInfoKey"] CGRectValue];
     if (!_disableMoveViewUp) {
-        CGRect end = [[[notification userInfo] objectForKey:@"UIKeyboardFrameEndUserInfoKey"] CGRectValue];
         _keyboardSize = end.size;
         UIView * rootView = self.weexInstance.rootView;
         CGRect screenRect = [[UIScreen mainScreen] bounds];
@@ -922,7 +923,7 @@ - (void)keyboardWasShown:(NSNotification*)notification
     }
     
     if (_keyboardEvent) {
-        [self fireEvent:@"keyboard" params:@{ @"isShow": @YES }];
+        [self fireEvent:@"keyboard" params:@{ @"isShow": @YES, @"keyboardSize": @{@"width": @(end.size.width), @"height": @(end.size.height)} }];
     }
     
     _keyboardHidden = NO;
diff --git a/ios/sdk/WeexSDK/Sources/Engine/WXSDKError.h b/ios/sdk/WeexSDK/Sources/Engine/WXSDKError.h
index 2834d76061..52a9f20710 100644
--- a/ios/sdk/WeexSDK/Sources/Engine/WXSDKError.h
+++ b/ios/sdk/WeexSDK/Sources/Engine/WXSDKError.h
@@ -54,6 +54,7 @@ typedef NS_ENUM(int, WXSDKErrCode)
     WX_ERR_RENDER_ADDEVENT = -2106,
     WX_ERR_RENDER_REMOVEEVENT = -2107,
     WX_ERR_RENDER_SCROLLTOELEMENT = -2110,
+    WX_ERR_RENDER_TWICE = -2111,
     WX_ERR_RENDER_END = -2199,
     
     WX_ERR_DOWNLOAD_START = -2201,
diff --git a/ios/sdk/WeexSDK/Sources/Engine/WXSDKError.m b/ios/sdk/WeexSDK/Sources/Engine/WXSDKError.m
index ef205fe87d..36aaa98288 100644
--- a/ios/sdk/WeexSDK/Sources/Engine/WXSDKError.m
+++ b/ios/sdk/WeexSDK/Sources/Engine/WXSDKError.m
@@ -73,6 +73,7 @@ +(NSDictionary *) getMap
                 @(WX_ERR_RENDER_ADDEVENT):@{ERROR_TYPE:@(WX_NATIVE_ERROR),ERROR_GROUP:@(WX_NATIVE)},
                 @(WX_ERR_RENDER_REMOVEEVENT):@{ERROR_TYPE:@(WX_NATIVE_ERROR),ERROR_GROUP:@(WX_NATIVE)},
                 @(WX_ERR_RENDER_SCROLLTOELEMENT):@{ERROR_TYPE:@(WX_NATIVE_ERROR),ERROR_GROUP:@(WX_NATIVE)},
+                @(WX_ERR_RENDER_TWICE):@{ERROR_TYPE:@(WX_NATIVE_ERROR),ERROR_GROUP:@(WX_NATIVE)},
                 @(WX_ERR_RENDER_END):@{ERROR_TYPE:@(WX_NATIVE_ERROR),ERROR_GROUP:@(WX_NATIVE)},
                 
                 @(WX_ERR_DOWNLOAD_START):@{ERROR_TYPE:@(WX_NATIVE_ERROR),ERROR_GROUP:@(WX_NATIVE)},
diff --git a/ios/sdk/WeexSDK/Sources/Manager/WXComponentManager.mm b/ios/sdk/WeexSDK/Sources/Manager/WXComponentManager.mm
index 7ad5c45c6f..e22dc38d76 100644
--- a/ios/sdk/WeexSDK/Sources/Manager/WXComponentManager.mm
+++ b/ios/sdk/WeexSDK/Sources/Manager/WXComponentManager.mm
@@ -220,6 +220,7 @@ - (void)createBody:(NSString*)ref
     WXAssertParam(ref);
     WXAssertParam(type);
     WXAssertParam(renderObject);
+    WXAssert(_rootComponent == nil, @"Create body is invoked twice.");
     
     _rootComponent = [self _buildComponent:ref type:type supercomponent:nil styles:styles attributes:attributes events:events renderObject:renderObject];
     
diff --git a/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.h b/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.h
index 165e0f82be..52dee073a7 100644
--- a/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.h
+++ b/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.h
@@ -76,7 +76,15 @@ extern NSString *const bundleUrlOptionKey;
  **/
 @property (nonatomic, assign) BOOL needPrerender;
 
-@property (nonatomic , strong) NSDictionary* containerInfo;
+/**
+ * Custom info.
+ **/
+@property (nonatomic, strong) NSDictionary* containerInfo;
+
+/**
+ * Whether this instance is rendered or not. Please MUST not render an instance twice.
+ **/
+@property (nonatomic, assign, readonly) BOOL isRendered;
 
 /**
  * The state of current instance.
diff --git a/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m b/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m
index 4afbb13fa5..7c16166bcf 100644
--- a/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m
+++ b/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m
@@ -100,13 +100,14 @@ - (instancetype)init
     self = [super init];
     if(self){
         NSInteger instanceId = 0;
-        @synchronized(self){
+        @synchronized(bundleUrlOptionKey) {
             static NSInteger __instance = 0;
             instanceId = __instance % (1024*1024);
             __instance++;
         }
         _instanceId = [NSString stringWithFormat:@"%ld", (long)instanceId];
         
+        // TODO self is retained here.
         [WXSDKManager storeInstance:self forID:_instanceId];
         
         _bizType = @"";
@@ -283,6 +284,11 @@ - (void)_renderWithOpcode:(NSData *)contents
         WXLogError(@"Fail to find instanceļ¼");
         return;
     }
+    
+    if (_isRendered) {
+        [WXExceptionUtils commitCriticalExceptionRT:self.instanceId errCode:[NSString stringWithFormat:@"%d", WX_ERR_RENDER_TWICE] function:@"_renderWithOpcode:" exception:[NSString stringWithFormat:@"instance is rendered twice"] extParams:nil];
+        return;
+    }
 
     //some case , with out render (url)
     [self.apmInstance startRecord:self.instanceId];
@@ -340,10 +346,10 @@ - (void)_renderWithOpcode:(NSData *)contents
 
     [WXTracingManager startTracingWithInstanceId:self.instanceId ref:nil className:nil name:WXTExecJS phase:WXTracingBegin functionName:@"renderWithOpcode" options:@{@"threadName":WXTMainThread}];
     [[WXSDKManager bridgeMgr] createInstance:self.instanceId contents:contents options:dictionary data:_jsData];
-
     [WXTracingManager startTracingWithInstanceId:self.instanceId ref:nil className:nil name:WXTExecJS phase:WXTracingEnd functionName:@"renderWithOpcode" options:@{@"threadName":WXTMainThread}];
 
    // WX_MONITOR_PERF_SET(WXPTBundleSize, [data length], self);
+    _isRendered = YES;
 }
 
 - (void)_renderWithMainBundleString:(NSString *)mainBundleString
@@ -352,6 +358,11 @@ - (void)_renderWithMainBundleString:(NSString *)mainBundleString
         WXLogError(@"Fail to find instanceļ¼");
         return;
     }
+    
+    if (_isRendered) {
+        [WXExceptionUtils commitCriticalExceptionRT:self.instanceId errCode:[NSString stringWithFormat:@"%d", WX_ERR_RENDER_TWICE] function:@"_renderWithMainBundleString:" exception:[NSString stringWithFormat:@"instance is rendered twice"] extParams:nil];
+        return;
+    }
 
     //some case , with out render (url)
     [self _checkPageName];
@@ -428,6 +439,8 @@ - (void)_renderWithMainBundleString:(NSString *)mainBundleString
     [WXTracingManager startTracingWithInstanceId:self.instanceId ref:nil className:nil name:WXTExecJS phase:WXTracingEnd functionName:@"renderWithMainBundleString" options:@{@"threadName":WXTMainThread}];
     
     WX_MONITOR_PERF_SET(WXPTBundleSize, [mainBundleString lengthOfBytesUsingEncoding:NSUTF8StringEncoding], self);
+    
+    _isRendered = YES;
 }
 
 - (BOOL)_handleConfigCenter
@@ -682,6 +695,8 @@ - (void)destroyInstance
     if (url.length > 0) {
         [WXPrerenderManager addGlobalTask:url callback:nil];
     }
+    
+    _isRendered = NO;
 }
 
 - (void)forceGarbageCollection


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services