From 655ad04f4967946c21f7820187f47cb4ac37263f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9=20Larivi=C3=A8re?= Date: Fri, 10 May 2019 20:23:30 +0200 Subject: [PATCH 1/2] Added check to prevent control reuse with different AutomationId --- .paket/Paket.Restore.targets | 58 ++--------------------------- src/Fabulous.Core/ViewConverters.fs | 19 ++++++++-- 2 files changed, 20 insertions(+), 57 deletions(-) diff --git a/.paket/Paket.Restore.targets b/.paket/Paket.Restore.targets index 017f39497..c9506cc71 100644 --- a/.paket/Paket.Restore.targets +++ b/.paket/Paket.Restore.targets @@ -105,8 +105,8 @@ true - @@ -228,7 +228,6 @@ - <_NuspecFilesNewLocation Include="$(BaseIntermediateOutputPath)$(Configuration)\*.nuspec"/> @@ -238,12 +237,10 @@ $(MSBuildProjectDirectory)/$(MSBuildProjectFile) true - false - true false - true + true false - true + true false true $(BaseIntermediateOutputPath)$(Configuration) @@ -261,53 +258,6 @@ - - ) then - canReuseNavigationPage prevChild newChild + if canReuseAutomationId prevChild newChild then + if newChild.TargetType.IsAssignableFrom(typeof) then + canReuseNavigationPage prevChild newChild + else + true else - true + false else false @@ -239,6 +242,16 @@ module Converters = | ValueSome prevPages, ValueSome newPages -> (prevPages, newPages) ||> Seq.forall2 canReuseChild | _, _ -> true + /// Checks whether the control can be reused given the previous and the new AutomationId. + /// Xamarin.Forms can't change an already setted AutomationId + and internal canReuseAutomationId (prevChild: ViewElement) (newChild: ViewElement) = + let prevAutomationId = prevChild.TryGetAttribute("AutomationId") + let newAutomationId = newChild.TryGetAttribute("AutomationId") + + match prevAutomationId, newAutomationId with + | ValueSome _, _ when prevAutomationId <> newAutomationId -> false + | _, _ -> true + /// Update a control given the previous and new view elements let inline updateChild (prevChild:ViewElement) (newChild:ViewElement) targetChild = newChild.UpdateIncremental(prevChild, targetChild) From 36d677e8b5130c5263381a9c87e109fe316a6a72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9=20Larivi=C3=A8re?= Date: Fri, 10 May 2019 21:03:39 +0200 Subject: [PATCH 2/2] More concise check --- src/Fabulous.Core/ViewConverters.fs | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/Fabulous.Core/ViewConverters.fs b/src/Fabulous.Core/ViewConverters.fs index c1d1041a7..d8c7d14e7 100644 --- a/src/Fabulous.Core/ViewConverters.fs +++ b/src/Fabulous.Core/ViewConverters.fs @@ -219,14 +219,11 @@ module Converters = /// Checks whether an underlying control can be reused given the previous and new view elements let rec canReuseChild (prevChild:ViewElement) (newChild:ViewElement) = - if prevChild.TargetType = newChild.TargetType then - if canReuseAutomationId prevChild newChild then - if newChild.TargetType.IsAssignableFrom(typeof) then - canReuseNavigationPage prevChild newChild - else - true + if prevChild.TargetType = newChild.TargetType && canReuseAutomationId prevChild newChild then + if newChild.TargetType.IsAssignableFrom(typeof) then + canReuseNavigationPage prevChild newChild else - false + true else false @@ -248,9 +245,9 @@ module Converters = let prevAutomationId = prevChild.TryGetAttribute("AutomationId") let newAutomationId = newChild.TryGetAttribute("AutomationId") - match prevAutomationId, newAutomationId with - | ValueSome _, _ when prevAutomationId <> newAutomationId -> false - | _, _ -> true + match prevAutomationId with + | ValueSome _ when prevAutomationId <> newAutomationId -> false + | _ -> true /// Update a control given the previous and new view elements let inline updateChild (prevChild:ViewElement) (newChild:ViewElement) targetChild =