From 1eb7426c1f469363a44ea7e0e7425eed32b6743f Mon Sep 17 00:00:00 2001 From: zhouleonlei Date: Mon, 10 May 2021 20:33:53 +0800 Subject: [PATCH] [NUI] Fix Svace issues --- src/Tizen.NUI.Components/Controls/Loading.cs | 2 +- .../Controls/RecyclerView/CollectionView.cs | 23 ++++++++++++++-------- .../RecyclerView/Item/RecyclerViewItem.Internal.cs | 3 +-- .../Controls/RecyclerView/Item/RecyclerViewItem.cs | 3 +-- .../Controls/RecyclerView/Layouter/GridLayouter.cs | 2 +- .../RecyclerView/Layouter/LinearLayouter.cs | 2 +- .../src/internal/EXaml/Action/AddEventAction.cs | 6 +++--- .../EXaml/Action/AddToResourceDictionary.cs | 5 ++--- .../internal/EXaml/Action/CallAddMethodAction.cs | 6 +++--- .../EXaml/Action/SetBindalbePropertyAction.cs | 4 ++-- .../src/internal/EXaml/Action/SetBindingAction.cs | 6 +++--- .../EXaml/Action/SetDynamicResourceAction.cs | 6 ++---- .../src/internal/EXaml/Action/SetPropertyAction.cs | 4 ++-- .../src/internal/EXaml/Block/GatherTypesBlock.cs | 8 +++++--- .../EXaml/Operation/AddToResourceDictionary.cs | 2 +- .../EXaml/Operation/GatherBindableProperties.cs | 5 ++++- .../EXaml/Operation/GatherConvertedValue.cs | 2 +- .../internal/EXaml/Operation/SetDynamicResource.cs | 2 +- .../src/internal/Layouting/LayoutController.cs | 4 ++++ .../src/public/BaseComponents/Style/ViewStyle.cs | 2 +- src/Tizen.NUI/src/public/Layouting/FlexLayout.cs | 2 +- 21 files changed, 55 insertions(+), 44 deletions(-) diff --git a/src/Tizen.NUI.Components/Controls/Loading.cs b/src/Tizen.NUI.Components/Controls/Loading.cs index f982359..1d01a18 100755 --- a/src/Tizen.NUI.Components/Controls/Loading.cs +++ b/src/Tizen.NUI.Components/Controls/Loading.cs @@ -134,7 +134,7 @@ namespace Tizen.NUI.Components /// 6 public string[] ImageArray { - get => (GetValue(ImageListProperty) as List).ToArray(); + get => (GetValue(ImageListProperty) as List)?.ToArray() ?? null; set => SetValue(ImageListProperty, value == null ? new List() : new List((string[])value)); } diff --git a/src/Tizen.NUI.Components/Controls/RecyclerView/CollectionView.cs b/src/Tizen.NUI.Components/Controls/RecyclerView/CollectionView.cs index e2d7ef6..9ea3075 100755 --- a/src/Tizen.NUI.Components/Controls/RecyclerView/CollectionView.cs +++ b/src/Tizen.NUI.Components/Controls/RecyclerView/CollectionView.cs @@ -833,10 +833,14 @@ namespace Tizen.NUI.Components groupHeader.isGroupFooter = false; ContentContainer.Add(groupHeader); } - groupHeader.ParentItemsView = this; - groupHeader.Index = index; - groupHeader.ParentGroup = context; - groupHeader.BindingContext = context; + + if (groupHeader != null) + { + groupHeader.ParentItemsView = this; + groupHeader.Index = index; + groupHeader.ParentGroup = context; + groupHeader.BindingContext = context; + } //group selection? item = groupHeader; } @@ -854,11 +858,14 @@ namespace Tizen.NUI.Components groupFooter.isGroupFooter = true; ContentContainer.Add(groupFooter); } - groupFooter.ParentItemsView = this; - groupFooter.Index = index; - groupFooter.ParentGroup = context; - groupFooter.BindingContext = context; + if (groupFooter != null) + { + groupFooter.ParentItemsView = this; + groupFooter.Index = index; + groupFooter.ParentGroup = context; + groupFooter.BindingContext = context; + } //group selection? item = groupFooter; } diff --git a/src/Tizen.NUI.Components/Controls/RecyclerView/Item/RecyclerViewItem.Internal.cs b/src/Tizen.NUI.Components/Controls/RecyclerView/Item/RecyclerViewItem.Internal.cs index d442144..23a1b5f 100755 --- a/src/Tizen.NUI.Components/Controls/RecyclerView/Item/RecyclerViewItem.Internal.cs +++ b/src/Tizen.NUI.Components/Controls/RecyclerView/Item/RecyclerViewItem.Internal.cs @@ -132,9 +132,8 @@ namespace Tizen.NUI.Components if (IsSelectable) { - if (ParentItemsView as CollectionView) + if (ParentItemsView is CollectionView colView) { - CollectionView colView = ParentItemsView as CollectionView; switch (colView.SelectionMode) { case ItemSelectionMode.Single: diff --git a/src/Tizen.NUI.Components/Controls/RecyclerView/Item/RecyclerViewItem.cs b/src/Tizen.NUI.Components/Controls/RecyclerView/Item/RecyclerViewItem.cs index f728cd2..ce8d840 100755 --- a/src/Tizen.NUI.Components/Controls/RecyclerView/Item/RecyclerViewItem.cs +++ b/src/Tizen.NUI.Components/Controls/RecyclerView/Item/RecyclerViewItem.cs @@ -215,9 +215,8 @@ namespace Tizen.NUI.Components if (IsSelectable) { // Extension : Extension?.SetTouchInfo(touch); - if (ParentItemsView as CollectionView) + if (ParentItemsView is CollectionView colView) { - CollectionView colView = ParentItemsView as CollectionView; switch (colView.SelectionMode) { case ItemSelectionMode.Single: diff --git a/src/Tizen.NUI.Components/Controls/RecyclerView/Layouter/GridLayouter.cs b/src/Tizen.NUI.Components/Controls/RecyclerView/Layouter/GridLayouter.cs index 9fd9e49..7821d7a 100755 --- a/src/Tizen.NUI.Components/Controls/RecyclerView/Layouter/GridLayouter.cs +++ b/src/Tizen.NUI.Components/Controls/RecyclerView/Layouter/GridLayouter.cs @@ -1230,7 +1230,7 @@ namespace Tizen.NUI.Components if (targetSibling > -1 && targetSibling < Container.Children.Count) { RecyclerViewItem candidate = Container.Children[targetSibling] as RecyclerViewItem; - if (candidate.Index >= 0 && candidate.Index < colView.InternalItemSource.Count) + if (candidate != null && candidate.Index >= 0 && candidate.Index < colView.InternalItemSource.Count) { nextFocusedView = candidate; } diff --git a/src/Tizen.NUI.Components/Controls/RecyclerView/Layouter/LinearLayouter.cs b/src/Tizen.NUI.Components/Controls/RecyclerView/Layouter/LinearLayouter.cs index 6a15035..1c5bd10 100755 --- a/src/Tizen.NUI.Components/Controls/RecyclerView/Layouter/LinearLayouter.cs +++ b/src/Tizen.NUI.Components/Controls/RecyclerView/Layouter/LinearLayouter.cs @@ -1325,7 +1325,7 @@ namespace Tizen.NUI.Components if (targetSibling > -1 && targetSibling < Container.Children.Count) { RecyclerViewItem candidate = Container.Children[targetSibling] as RecyclerViewItem; - if (candidate.Index >= 0 && candidate.Index < colView.InternalItemSource.Count) + if (candidate != null && candidate.Index >= 0 && candidate.Index < colView.InternalItemSource.Count) { nextFocusedView = candidate; } diff --git a/src/Tizen.NUI/src/internal/EXaml/Action/AddEventAction.cs b/src/Tizen.NUI/src/internal/EXaml/Action/AddEventAction.cs index 60fb053..abdbc22 100755 --- a/src/Tizen.NUI/src/internal/EXaml/Action/AddEventAction.cs +++ b/src/Tizen.NUI/src/internal/EXaml/Action/AddEventAction.cs @@ -64,10 +64,10 @@ namespace Tizen.NUI.EXaml public void OnActive() { - if (null != childOp) + if (null != childOp && childOp.ValueList.Count > 3 && (childOp.ValueList[0] is Instance instance) && (childOp.ValueList[1] is Instance element)) { - int instanceIndex = (childOp.ValueList[0] as Instance).Index; - int elementIndex = (childOp.ValueList[1] as Instance).Index; + int instanceIndex = instance.Index; + int elementIndex = element.Index; int propertyIndex = (int)childOp.ValueList[2]; int value = (int)childOp.ValueList[3]; globalDataList.Operations.Add(new AddEvent(globalDataList, instanceIndex, elementIndex, propertyIndex, value)); diff --git a/src/Tizen.NUI/src/internal/EXaml/Action/AddToResourceDictionary.cs b/src/Tizen.NUI/src/internal/EXaml/Action/AddToResourceDictionary.cs index 76874e0..2667d03 100755 --- a/src/Tizen.NUI/src/internal/EXaml/Action/AddToResourceDictionary.cs +++ b/src/Tizen.NUI/src/internal/EXaml/Action/AddToResourceDictionary.cs @@ -64,10 +64,9 @@ namespace Tizen.NUI.EXaml public void OnActive() { - if (null != childOp) + if (null != childOp && childOp.ValueList.Count > 2 && (childOp.ValueList[0] is Instance instance) && (childOp.ValueList[1] is string key)) { - int instanceIndex = (childOp.ValueList[0] as Instance).Index; - string key = childOp.ValueList[1] as string; + int instanceIndex = instance.Index; var value = childOp.ValueList[2]; globalDataList.Operations.Add(new AddToResourceDictionary(globalDataList, instanceIndex, key, value)); } diff --git a/src/Tizen.NUI/src/internal/EXaml/Action/CallAddMethodAction.cs b/src/Tizen.NUI/src/internal/EXaml/Action/CallAddMethodAction.cs index 701c12f..fc69b14 100755 --- a/src/Tizen.NUI/src/internal/EXaml/Action/CallAddMethodAction.cs +++ b/src/Tizen.NUI/src/internal/EXaml/Action/CallAddMethodAction.cs @@ -64,10 +64,10 @@ namespace Tizen.NUI.EXaml public void OnActive() { - if (null != childOp) + if (null != childOp && childOp.ValueList.Count > 2 && (childOp.ValueList[0] is Instance instance) && (childOp.ValueList[1] is Instance child)) { - int parentIndex = (childOp.ValueList[0] as Instance).Index; - int childIndex = (childOp.ValueList[1] as Instance).Index; + int parentIndex = instance.Index; + int childIndex = child.Index; int methodIndex = (int)childOp.ValueList[2]; globalDataList.Operations.Add(new CallAddMethod(globalDataList, parentIndex, childIndex, methodIndex)); diff --git a/src/Tizen.NUI/src/internal/EXaml/Action/SetBindalbePropertyAction.cs b/src/Tizen.NUI/src/internal/EXaml/Action/SetBindalbePropertyAction.cs index c48cba5..773570a 100755 --- a/src/Tizen.NUI/src/internal/EXaml/Action/SetBindalbePropertyAction.cs +++ b/src/Tizen.NUI/src/internal/EXaml/Action/SetBindalbePropertyAction.cs @@ -64,9 +64,9 @@ namespace Tizen.NUI.EXaml public void OnActive() { - if (null != childOp) + if (null != childOp && childOp.ValueList.Count > 2 && (childOp.ValueList[0] is Instance instance)) { - int instanceIndex = (childOp.ValueList[0] as Instance).Index; + int instanceIndex = instance.Index; int bindalbePropertyIndex = (int)childOp.ValueList[1]; var value = childOp.ValueList[2]; globalDataList.Operations.Add(new SetBindalbeProperty(globalDataList, instanceIndex, bindalbePropertyIndex, value)); diff --git a/src/Tizen.NUI/src/internal/EXaml/Action/SetBindingAction.cs b/src/Tizen.NUI/src/internal/EXaml/Action/SetBindingAction.cs index 5036aaf..08d42ca 100755 --- a/src/Tizen.NUI/src/internal/EXaml/Action/SetBindingAction.cs +++ b/src/Tizen.NUI/src/internal/EXaml/Action/SetBindingAction.cs @@ -64,11 +64,11 @@ namespace Tizen.NUI.EXaml public void OnActive() { - if (null != childOp) + if (null != childOp && childOp.ValueList.Count > 2 && (childOp.ValueList[0] is Instance instance) && (childOp.ValueList[2] is Instance value)) { - int instanceIndex = (childOp.ValueList[0] as Instance).Index; + int instanceIndex = instance.Index; var propertyIndex = (int)childOp.ValueList[1]; - int valueIndex = (childOp.ValueList[2] as Instance).Index; + int valueIndex = value.Index; globalDataList.Operations.Add(new SetBinding(globalDataList, instanceIndex, propertyIndex, valueIndex)); } diff --git a/src/Tizen.NUI/src/internal/EXaml/Action/SetDynamicResourceAction.cs b/src/Tizen.NUI/src/internal/EXaml/Action/SetDynamicResourceAction.cs index 6cffcc5..c17e805 100755 --- a/src/Tizen.NUI/src/internal/EXaml/Action/SetDynamicResourceAction.cs +++ b/src/Tizen.NUI/src/internal/EXaml/Action/SetDynamicResourceAction.cs @@ -61,12 +61,10 @@ namespace Tizen.NUI.EXaml public void OnActive() { - if (null != childOp) + if (null != childOp && childOp.ValueList.Count > 2 && (childOp.ValueList[0] is Instance instance) && (childOp.ValueList[2] is string key)) { - int instanceIndex = (childOp.ValueList[0] as Instance).Index; + int instanceIndex = instance.Index; int propertyIndex = (int)childOp.ValueList[1]; - string key = childOp.ValueList[2] as string; - globalDataList.Operations.Add(new SetDynamicResource(globalDataList, instanceIndex, propertyIndex, key)); } } diff --git a/src/Tizen.NUI/src/internal/EXaml/Action/SetPropertyAction.cs b/src/Tizen.NUI/src/internal/EXaml/Action/SetPropertyAction.cs index 2dc2c06..837741b 100755 --- a/src/Tizen.NUI/src/internal/EXaml/Action/SetPropertyAction.cs +++ b/src/Tizen.NUI/src/internal/EXaml/Action/SetPropertyAction.cs @@ -64,9 +64,9 @@ namespace Tizen.NUI.EXaml public void OnActive() { - if (null != childOp) + if (null != childOp && childOp.ValueList.Count > 2 && (childOp.ValueList[0] is Instance instance)) { - int instanceIndex = (childOp.ValueList[0] as Instance).Index; + int instanceIndex = instance.Index; int propertyIndex = (int)childOp.ValueList[1]; var value = childOp.ValueList[2]; globalDataList.Operations.Add(new SetProperty(globalDataList, instanceIndex, propertyIndex, value)); diff --git a/src/Tizen.NUI/src/internal/EXaml/Block/GatherTypesBlock.cs b/src/Tizen.NUI/src/internal/EXaml/Block/GatherTypesBlock.cs index 2f4a280..0fe0255 100755 --- a/src/Tizen.NUI/src/internal/EXaml/Block/GatherTypesBlock.cs +++ b/src/Tizen.NUI/src/internal/EXaml/Block/GatherTypesBlock.cs @@ -75,11 +75,13 @@ namespace Tizen.NUI.EXaml { List genericTypeIndexs = new List(); var genericTypeIndexList = valueList[1] as List; - foreach (var index in genericTypeIndexList) + if (genericTypeIndexList != null) { - genericTypeIndexs.Add((int)index); + foreach (var index in genericTypeIndexList) + { + genericTypeIndexs.Add((int)index); + } } - return new GatherType(globalDataList, assemblyIndex, typeName, genericTypeIndexs); } else diff --git a/src/Tizen.NUI/src/internal/EXaml/Operation/AddToResourceDictionary.cs b/src/Tizen.NUI/src/internal/EXaml/Operation/AddToResourceDictionary.cs index e2187ab..5262820 100755 --- a/src/Tizen.NUI/src/internal/EXaml/Operation/AddToResourceDictionary.cs +++ b/src/Tizen.NUI/src/internal/EXaml/Operation/AddToResourceDictionary.cs @@ -41,7 +41,7 @@ namespace Tizen.NUI.EXaml var instance = globalDataList.GatheredInstances[instanceIndex] as ResourceDictionary; var realValue = (value is Instance) ? globalDataList.GatheredInstances[(value as Instance).Index] : value; - instance.Add(key, realValue); + instance?.Add(key, realValue); } private int instanceIndex; diff --git a/src/Tizen.NUI/src/internal/EXaml/Operation/GatherBindableProperties.cs b/src/Tizen.NUI/src/internal/EXaml/Operation/GatherBindableProperties.cs index f077d7e..720f085 100755 --- a/src/Tizen.NUI/src/internal/EXaml/Operation/GatherBindableProperties.cs +++ b/src/Tizen.NUI/src/internal/EXaml/Operation/GatherBindableProperties.cs @@ -44,7 +44,10 @@ namespace Tizen.NUI.EXaml field = type.GetField(fi => fi.Name == propertyName && fi.IsStatic && !fi.IsPublic); } - globalDataList.GatheredBindableProperties.Add(field.GetValue(null) as BindableProperty); + if (null != field && field.GetValue(null) is BindableProperty value) + { + globalDataList.GatheredBindableProperties.Add(value); + } } private int typeIndex; diff --git a/src/Tizen.NUI/src/internal/EXaml/Operation/GatherConvertedValue.cs b/src/Tizen.NUI/src/internal/EXaml/Operation/GatherConvertedValue.cs index 48805d8..484f65d 100755 --- a/src/Tizen.NUI/src/internal/EXaml/Operation/GatherConvertedValue.cs +++ b/src/Tizen.NUI/src/internal/EXaml/Operation/GatherConvertedValue.cs @@ -38,7 +38,7 @@ namespace Tizen.NUI.EXaml public void Do() { var converter = globalDataList.GatheredInstances[converterIndex] as TypeConverter; - globalDataList.GatheredInstances.Add(converter.ConvertFromInvariantString(value)); + globalDataList.GatheredInstances.Add(converter?.ConvertFromInvariantString(value)); } private int converterIndex; diff --git a/src/Tizen.NUI/src/internal/EXaml/Operation/SetDynamicResource.cs b/src/Tizen.NUI/src/internal/EXaml/Operation/SetDynamicResource.cs index b650fc0..00419b7 100755 --- a/src/Tizen.NUI/src/internal/EXaml/Operation/SetDynamicResource.cs +++ b/src/Tizen.NUI/src/internal/EXaml/Operation/SetDynamicResource.cs @@ -41,7 +41,7 @@ namespace Tizen.NUI.EXaml var instance = globalDataList.GatheredInstances[instanceIndex] as BindableObject; var property = globalDataList.GatheredBindableProperties[propertyIndex]; - instance.SetDynamicResource(property, key); + instance?.SetDynamicResource(property, key); } private int instanceIndex; diff --git a/src/Tizen.NUI/src/internal/Layouting/LayoutController.cs b/src/Tizen.NUI/src/internal/Layouting/LayoutController.cs index ef710cf..e9567a2 100755 --- a/src/Tizen.NUI/src/internal/Layouting/LayoutController.cs +++ b/src/Tizen.NUI/src/internal/Layouting/LayoutController.cs @@ -543,6 +543,10 @@ namespace Tizen.NUI SetupAnimationForPosition(layoutPositionData, positionTransitionComponents); SetupAnimationForSize(layoutPositionData, sizeTransitionComponents); + + // Dispose components + positionTransitionComponents.Dispose(); + sizeTransitionComponents.Dispose(); } } // class LayoutController diff --git a/src/Tizen.NUI/src/public/BaseComponents/Style/ViewStyle.cs b/src/Tizen.NUI/src/public/BaseComponents/Style/ViewStyle.cs index 3edc0d6..fec83f8 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/Style/ViewStyle.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/Style/ViewStyle.cs @@ -568,7 +568,7 @@ namespace Tizen.NUI.BaseComponents { var newStyle = value.Clone() as TOut; - newStyle.CopyFrom(other); + newStyle?.CopyFrom(other); return newStyle; } diff --git a/src/Tizen.NUI/src/public/Layouting/FlexLayout.cs b/src/Tizen.NUI/src/public/Layouting/FlexLayout.cs index dc3da47..1bf8b30 100755 --- a/src/Tizen.NUI/src/public/Layouting/FlexLayout.cs +++ b/src/Tizen.NUI/src/public/Layouting/FlexLayout.cs @@ -811,7 +811,7 @@ namespace Tizen.NUI { // Get the frame for the child, start, top, end, bottom. Vector4 frame = new Vector4(Interop.FlexLayout.GetNodeFrame(swigCPtr, childIndex), true); - childLayout.Layout(new LayoutLength(frame.X), new LayoutLength(frame.Y), new LayoutLength(frame.Z), new LayoutLength(frame.W)); + childLayout?.Layout(new LayoutLength(frame.X), new LayoutLength(frame.Y), new LayoutLength(frame.Z), new LayoutLength(frame.W)); frame.Dispose(); } } -- 2.7.4