-
Notifications
You must be signed in to change notification settings - Fork 743
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1208 from unoplatform/dev/nich/template-recycling
Check for dataContext to avoid recyclingTemplate when unneeded
- Loading branch information
Showing
7 changed files
with
271 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
...esApp.UITests/Windows_UI_Xaml_Controls/ToggleSwitchTests/UnoSamples_Tests.ToggleSwitch.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using System.Drawing; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using NUnit.Framework; | ||
using Uno.UITest.Helpers; | ||
using Uno.UITest.Helpers.Queries; | ||
|
||
namespace SamplesApp.UITests.Windows_UI_Xaml_Controls.ToggleSwitchTests | ||
{ | ||
[TestFixture] | ||
public partial class ToggleSwitch_Tests : SampleControlUITestBase | ||
{ | ||
[Test] | ||
public void ToggleSwitch_TemplateReuseTest() | ||
{ | ||
Run("UITests.Shared.Windows_UI_Xaml_Controls.ToggleSwitchControl.ToggleSwitch_TemplateReuse"); | ||
|
||
var toggleSwitchGroup = _app.Marked("toggleSwitchGroup"); | ||
|
||
_app.WaitForElement(toggleSwitchGroup); | ||
|
||
var separatedToggleSwitch = _app.Marked("separatedToggleSwitch"); | ||
var unloadButton = _app.Marked("unload"); | ||
var reloadButton = _app.Marked("reload"); | ||
|
||
// Assert inital state | ||
Assert.AreEqual("False", toggleSwitchGroup.GetDependencyPropertyValue("IsOn")?.ToString()); | ||
Assert.AreEqual("True", separatedToggleSwitch.GetDependencyPropertyValue("IsOn")?.ToString()); | ||
|
||
unloadButton.Tap(); | ||
reloadButton.Tap(); | ||
|
||
//Assert final state | ||
Assert.AreEqual("False", toggleSwitchGroup.GetDependencyPropertyValue("IsOn")?.ToString()); | ||
Assert.AreEqual("True", separatedToggleSwitch.GetDependencyPropertyValue("IsOn")?.ToString()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
160 changes: 160 additions & 0 deletions
160
...Tests.Shared/Windows_UI_Xaml_Controls/ToggleSwitchControl/ToggleSwitch_TemplateReuse.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
<Page | ||
x:Class="UITests.Shared.Windows_UI_Xaml_Controls.ToggleSwitchControl.ToggleSwitch_TemplateReuse" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:local="using:UITests.Shared.Windows_UI_Xaml_Controls.ToggleSwitchControl" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
mc:Ignorable="d" | ||
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> | ||
|
||
<Page.Resources> | ||
<Style x:Key="BrokenToggleSwitchStyle" | ||
TargetType="ToggleSwitch"> | ||
<Setter Property="HorizontalAlignment" | ||
Value="Stretch" /> | ||
<Setter Property="VerticalAlignment" | ||
Value="Center" /> | ||
<Setter Property="HorizontalContentAlignment" | ||
Value="Left" /> | ||
<Setter Property="Padding" | ||
Value="0" /> | ||
<Setter Property="FontSize" | ||
Value="17" /> | ||
<Setter Property="BorderThickness" | ||
Value="0,0,0,1" /> | ||
<Setter Property="FontWeight" | ||
Value="Normal" /> | ||
<Setter Property="ManipulationMode" | ||
Value="System,TranslateX" /> | ||
<Setter Property="UseSystemFocusVisuals" | ||
Value="True" /> | ||
<Setter Property="Template"> | ||
<Setter.Value> | ||
<ControlTemplate TargetType="ToggleSwitch"> | ||
<Grid Margin="18,0" | ||
MinHeight="50" | ||
BorderBrush="Black" | ||
BorderThickness="{TemplateBinding BorderThickness}" | ||
Background="Pink"> | ||
<Grid.ColumnDefinitions> | ||
<ColumnDefinition Width="*" /> | ||
<ColumnDefinition Width="Auto" /> | ||
</Grid.ColumnDefinitions> | ||
<VisualStateManager.VisualStateGroups> | ||
<VisualStateGroup x:Name="CommonStates"> | ||
<VisualState x:Name="Normal" /> | ||
<VisualState x:Name="PointerOver" /> | ||
<VisualState x:Name="Pressed" /> | ||
<VisualState x:Name="Disabled" /> | ||
</VisualStateGroup> | ||
<VisualStateGroup x:Name="ToggleStates"> | ||
<VisualState x:Name="Dragging" /> | ||
<VisualState x:Name="Off" /> | ||
<VisualState x:Name="On"> | ||
<Storyboard> | ||
<DoubleAnimation Duration="0" | ||
To="16" | ||
Storyboard.TargetProperty="X" | ||
Storyboard.TargetName="KnobTranslateTransform" /> | ||
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Opacity" | ||
Storyboard.TargetName="SwitchKnobBounds"> | ||
<DiscreteObjectKeyFrame KeyTime="0" | ||
Value="1" /> | ||
</ObjectAnimationUsingKeyFrames> | ||
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Opacity" | ||
Storyboard.TargetName="OuterBorder"> | ||
<DiscreteObjectKeyFrame KeyTime="0" | ||
Value="0" /> | ||
</ObjectAnimationUsingKeyFrames> | ||
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Opacity" | ||
Storyboard.TargetName="SwitchKnobOn"> | ||
<DiscreteObjectKeyFrame KeyTime="0" | ||
Value="1" /> | ||
</ObjectAnimationUsingKeyFrames> | ||
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Opacity" | ||
Storyboard.TargetName="SwitchKnobOff"> | ||
<DiscreteObjectKeyFrame KeyTime="0" | ||
Value="0" /> | ||
</ObjectAnimationUsingKeyFrames> | ||
</Storyboard> | ||
</VisualState> | ||
</VisualStateGroup> | ||
<VisualStateGroup x:Name="ContentStates"> | ||
<VisualState x:Name="OffContent" /> | ||
<VisualState x:Name="OnContent" /> | ||
</VisualStateGroup> | ||
</VisualStateManager.VisualStateGroups> | ||
<ContentPresenter x:Name="ContentPresenter" | ||
Grid.ColumnSpan="2" | ||
AutomationProperties.AccessibilityView="Raw" | ||
ContentTemplate="{TemplateBinding OnContentTemplate}" | ||
Content="{TemplateBinding OnContent}" | ||
Foreground="{TemplateBinding Foreground}" | ||
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" | ||
VerticalAlignment="{TemplateBinding VerticalContentAlignment}" /> | ||
<Border x:Name="OuterBorder" | ||
Background="Blue" | ||
Margin="1,0" | ||
Height="14" | ||
CornerRadius="7" | ||
HorizontalAlignment="Left" | ||
Width="37" | ||
Grid.Column="1" | ||
IsHitTestVisible="False" /> | ||
<Border x:Name="SwitchKnobBounds" | ||
Background="WhiteSmoke" | ||
Height="14" | ||
Opacity="0" | ||
CornerRadius="7" | ||
Width="37" | ||
Grid.Column="1" | ||
HorizontalAlignment="Left" | ||
IsHitTestVisible="False" /> | ||
<Grid x:Name="SwitchKnob" | ||
HorizontalAlignment="Left" | ||
Height="22" | ||
Width="22" | ||
Grid.Column="1" | ||
IsHitTestVisible="False" | ||
RenderTransformOrigin="0,0.5"> | ||
<Grid.RenderTransform> | ||
<TranslateTransform x:Name="KnobTranslateTransform" /> | ||
</Grid.RenderTransform> | ||
<Ellipse x:Name="SwitchKnobOn" | ||
Fill="Orange" | ||
Stroke="Brown" | ||
StrokeThickness="1" | ||
Height="22" | ||
Opacity="0" | ||
Width="22" /> | ||
<Ellipse x:Name="SwitchKnobOff" | ||
Stroke="Yellow" | ||
StrokeThickness="1" | ||
Fill="SandyBrown" | ||
Height="22" | ||
Width="22" /> | ||
</Grid> | ||
</Grid> | ||
</ControlTemplate> | ||
</Setter.Value> | ||
</Setter> | ||
</Style> | ||
</Page.Resources> | ||
|
||
<StackPanel> | ||
<Button x:Name="unload">Unload</Button> | ||
<Button x:Name="reload" IsEnabled="False">Reload</Button> | ||
<CheckBox x:Name="chk" /> | ||
<Border x:Name="root"> | ||
<StackPanel x:Name="theStackPanel"> | ||
<ToggleSwitch x:Name="toggleSwitchGroup" IsOn="{Binding IsChecked, ElementName=chk, Mode=TwoWay}" Style="{StaticResource BrokenToggleSwitchStyle}" /> | ||
<ToggleSwitch IsOn="{Binding IsChecked, ElementName=chk, Mode=TwoWay}" Style="{StaticResource BrokenToggleSwitchStyle}" /> | ||
<TextBlock Text="{Binding IsChecked, ElementName=chk}" /> | ||
</StackPanel> | ||
</Border> | ||
<Border> | ||
<ToggleSwitch x:Name="separatedToggleSwitch" IsOn="{Binding [IsOn2], Mode=TwoWay}" Style="{StaticResource BrokenToggleSwitchStyle}" /> | ||
</Border> | ||
</StackPanel> | ||
</Page> |
50 changes: 50 additions & 0 deletions
50
...ts.Shared/Windows_UI_Xaml_Controls/ToggleSwitchControl/ToggleSwitch_TemplateReuse.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using SamplesApp.Windows_UI_Xaml_Controls.ToggleSwitchControl.Models; | ||
using Uno.UI.Samples.Controls; | ||
using Uno.UI; | ||
using Windows.UI.Xaml; | ||
using Windows.UI.Xaml.Controls; | ||
|
||
namespace UITests.Shared.Windows_UI_Xaml_Controls.ToggleSwitchControl | ||
{ | ||
[SampleControlInfo("ToggleSwitch", "ToggleSwitch_TemplateReuse", typeof(ToggleSwitchViewModel))] | ||
public sealed partial class ToggleSwitch_TemplateReuse : Page | ||
{ | ||
public ToggleSwitch_TemplateReuse() | ||
{ | ||
this.InitializeComponent(); | ||
|
||
SetPoolingEnabled(true); | ||
|
||
var c = root.Child; | ||
|
||
unload.Tapped += (snd, evt) => | ||
{ | ||
c = root.Child; | ||
root.Child = null; | ||
unload.IsEnabled = false; | ||
reload.IsEnabled = true; | ||
}; | ||
|
||
reload.Tapped += (snd, evt) => | ||
{ | ||
root.Child = c; | ||
unload.IsEnabled = true; | ||
reload.IsEnabled = false; | ||
(theStackPanel as StackPanel).Children.Add(separatedToggleSwitch); | ||
}; | ||
|
||
unload.Unloaded += (snd, evt) => | ||
{ | ||
SetPoolingEnabled(false); | ||
}; | ||
} | ||
|
||
private void SetPoolingEnabled(bool enabled) | ||
{ | ||
#if __ANDROID || __IOS__ | ||
FeatureConfiguration.Page.IsPoolingEnabled = enabled; | ||
FrameworkTemplatePool.IsPoolingEnabled = enabled; | ||
#endif | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters