You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@weex.apache.org by ac...@apache.org on 2017/06/15 06:29:31 UTC

[4/6] incubator-weex git commit: * [ios] fix set accessibility unexpected crash

* [ios] fix set accessibility unexpected crash


Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/1b10c6a4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/1b10c6a4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/1b10c6a4

Branch: refs/heads/0.14-dev
Commit: 1b10c6a4a6f3443b6b1919ba376997a1911cac5b
Parents: 03747a6
Author: acton393 <zh...@gmail.com>
Authored: Tue Jun 13 15:46:02 2017 +0800
Committer: acton393 <zh...@gmail.com>
Committed: Tue Jun 13 15:46:02 2017 +0800

----------------------------------------------------------------------
 .../Sources/Component/WXComponent_internal.h    |  1 +
 .../WeexSDK/Sources/Layout/WXComponent+Layout.m |  1 -
 ios/sdk/WeexSDK/Sources/Model/WXComponent.m     | 47 +++++++++++++++-----
 3 files changed, 36 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/1b10c6a4/ios/sdk/WeexSDK/Sources/Component/WXComponent_internal.h
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Component/WXComponent_internal.h b/ios/sdk/WeexSDK/Sources/Component/WXComponent_internal.h
index ce2e80a..7226ced 100644
--- a/ios/sdk/WeexSDK/Sources/Component/WXComponent_internal.h
+++ b/ios/sdk/WeexSDK/Sources/Component/WXComponent_internal.h
@@ -61,6 +61,7 @@
     UIAccessibilityTraits _role; //accessibility
     NSString * _ariaLabel; //accessibilityLabel
     BOOL _ariaHidden; // accessibilityElementsHidden
+    NSString * _testId;// just for auto-test
     
     /**
      *  PseudoClass

http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/1b10c6a4/ios/sdk/WeexSDK/Sources/Layout/WXComponent+Layout.m
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Layout/WXComponent+Layout.m b/ios/sdk/WeexSDK/Sources/Layout/WXComponent+Layout.m
index ce570ca..a6f1f0e 100644
--- a/ios/sdk/WeexSDK/Sources/Layout/WXComponent+Layout.m
+++ b/ios/sdk/WeexSDK/Sources/Layout/WXComponent+Layout.m
@@ -148,7 +148,6 @@
                 [strongSelf setGradientLayer];
             }
             [strongSelf setNeedsDisplay];
-            [strongSelf _configWXComponentA11yWithAttributes:nil];
         }];
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/1b10c6a4/ios/sdk/WeexSDK/Sources/Model/WXComponent.m
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Model/WXComponent.m b/ios/sdk/WeexSDK/Sources/Model/WXComponent.m
index 561baa5..2a0bbd9 100644
--- a/ios/sdk/WeexSDK/Sources/Model/WXComponent.m
+++ b/ios/sdk/WeexSDK/Sources/Model/WXComponent.m
@@ -90,6 +90,7 @@
         _isNeedJoinLayoutSystem = YES;
         _isLayoutDirty = YES;
         _isViewFrameSyncWithCalculated = YES;
+        _ariaHidden = NO;
         
         _async = NO;
         
@@ -104,6 +105,20 @@
             }
         }
         
+        if (attributes[@"role"]){
+            _role = [WXConvert WXUIAccessibilityTraits:attributes[@"role"]];
+        }
+        if (attributes[@"ariaHidden"]) {
+            _ariaHidden = [WXConvert BOOL:attributes[@"ariaHidden"]];
+        }
+        if (attributes[@"ariaLabel"]) {
+            _ariaLabel = [WXConvert NSString:attributes[@"ariaLabel"]];
+        }
+        
+        if (attributes[@"testId"]) {
+            _testId = [WXConvert NSString:attributes[@"testId"]];
+        }
+        
         [self _setupNavBarWithStyles:_styles attributes:_attributes];
         [self _initCSSNodeWithStyles:_styles];
         [self _initViewPropertyWithStyles:_styles];
@@ -234,7 +249,19 @@
         _view.wx_ref = self.ref;
         _layer.wx_component = self;
         
-        [self _configWXComponentA11yWithAttributes:_attributes];
+        if (_role) {
+            _view.accessibilityTraits |= _role;
+        }
+        
+        if (_testId) {
+            _view.accessibilityIdentifier = _testId;
+        }
+        
+        if (_ariaLabel) {
+            _view.accessibilityLabel = _ariaLabel;
+        }
+        
+        _view.accessibilityElementsHidden = _ariaHidden;
         
         [self _initEvents:self.events];
         [self _initPseudoEvents:_isListenPseudoTouch];
@@ -515,26 +542,22 @@
 - (void)_configWXComponentA11yWithAttributes:(NSDictionary *)attributes
 {
     WX_CHECK_COMPONENT_TYPE(self.componentType)
-    NSDictionary *attributesCpy = [attributes copy];
-    if (!attributesCpy) {
-        return;
-    }
     
-    if (attributesCpy[@"role"]){
+    if (attributes[@"role"]){
         _role = [WXConvert WXUIAccessibilityTraits:attributes[@"role"]];
         self.view.accessibilityTraits = _role;
     }
-    if (attributesCpy[@"ariaHidden"]) {
-        _ariaHidden = [WXConvert BOOL:attributesCpy[@"ariaHidden"]];
+    if (attributes[@"ariaHidden"]) {
+        _ariaHidden = [WXConvert BOOL:attributes[@"ariaHidden"]];
         self.view.accessibilityElementsHidden = _ariaHidden;
     }
-    if (attributesCpy[@"ariaLabel"]) {
-        _ariaLabel = [WXConvert NSString:attributesCpy[@"ariaLabel"]];
+    if (attributes[@"ariaLabel"]) {
+        _ariaLabel = [WXConvert NSString:attributes[@"ariaLabel"]];
         self.view.accessibilityValue = _ariaLabel;
     }
     
-    if (attributesCpy[@"testId"]) {
-        [self.view setAccessibilityIdentifier:[WXConvert NSString:attributesCpy[@"testId"]]];
+    if (attributes[@"testId"]) {
+        [self.view setAccessibilityIdentifier:[WXConvert NSString:attributes[@"testId"]]];
     }
 
 }