Skip to content

Commit

Permalink
https://github.com/AndreiMisiukevich/CardView/issues/78
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreiMisiukevich committed Aug 6, 2018
1 parent bd10111 commit 0158402
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 44 deletions.
82 changes: 41 additions & 41 deletions PanCardView/CardsView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -413,22 +413,22 @@ public void OnPanUpdated(PanUpdatedEventArgs e, bool? isSwiped = null)
}
}

protected virtual void OnOrientationChanged()
{
if (CurrentView != null && ItemTemplate != null)
{
var currentViewPair = _viewsPool.FirstOrDefault(p => p.Value.Contains(CurrentView));
currentViewPair.Value.Clear();
currentViewPair.Value.Add(CurrentView);
_viewsPool.Clear();
_viewsPool.Add(currentViewPair.Key, currentViewPair.Value);
}

SetCurrentView();
RemoveUnprocessingChildren();
LayoutChildren(X, Y, Width, Height);
ForceLayout();
}
protected virtual void OnOrientationChanged()
{
if (CurrentView != null && ItemTemplate != null)
{
var currentViewPair = _viewsPool.FirstOrDefault(p => p.Value.Contains(CurrentView));
currentViewPair.Value.Clear();
currentViewPair.Value.Add(CurrentView);
_viewsPool.Clear();
_viewsPool.Add(currentViewPair.Key, currentViewPair.Value);
}

SetCurrentView();
RemoveUnprocessingChildren();
LayoutChildren(X, Y, Width, Height);
ForceLayout();
}

protected virtual void SetupBackViews()
{
Expand Down Expand Up @@ -618,31 +618,31 @@ protected override void OnSizeAllocated(double width, double height)
{
base.OnSizeAllocated(width, height);

lock (_sizeChangedLocker)
{
var parent = FindParentPage();
if (parent == null)
{
return;
}

var parerntWidth = parent.Width;
var parentHeight = parent.Height;

if (!_isViewsInited && parerntWidth > 0 && parentHeight > 0)
{
_isViewsInited = true;
_isPortraitOrientation = parentHeight > parerntWidth;
FrontViewProcessor.HandleInitView(Enumerable.Repeat(CurrentView, 1), this, AnimationDirection.Current);
BackViewProcessor.HandleInitView(PrevViews, this, AnimationDirection.Prev);
BackViewProcessor.HandleInitView(NextViews, this, AnimationDirection.Next);
}
if (_isViewsInited && _isPortraitOrientation != parentHeight > parerntWidth)
{
_isPortraitOrientation = !_isPortraitOrientation;
OnOrientationChanged();
}
}
lock (_sizeChangedLocker)
{
var parent = FindParentPage();
if (parent == null)
{
return;
}

var parerntWidth = parent.Width;
var parentHeight = parent.Height;

if (!_isViewsInited && parerntWidth > 0 && parentHeight > 0)
{
_isViewsInited = true;
_isPortraitOrientation = parentHeight > parerntWidth;
FrontViewProcessor.HandleInitView(Enumerable.Repeat(CurrentView, 1), this, AnimationDirection.Current);
BackViewProcessor.HandleInitView(PrevViews, this, AnimationDirection.Prev);
BackViewProcessor.HandleInitView(NextViews, this, AnimationDirection.Next);
}
if (_isViewsInited && _isPortraitOrientation != parentHeight > parerntWidth)
{
_isPortraitOrientation = !_isPortraitOrientation;
OnOrientationChanged();
}
}
}

protected override void OnPropertyChanged([CallerMemberName] string propertyName = null)
Expand Down
19 changes: 19 additions & 0 deletions PanCardView/Controls/IndicatorsControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ public class IndicatorsControl : StackLayout
bindable.AsIndicatorsControl().ResetVisibility();
});

public static readonly BindableProperty IsRightToLeftFlowDirectionEnabledProperty = BindableProperty.Create(nameof(IsRightToLeftFlowDirectionEnabled), typeof(bool), typeof(IndicatorsControl), false, propertyChanged: (bindable, oldValue, newValue) =>
{
bindable.AsIndicatorsControl().OnFlowDirectionChanged();
});

public static readonly BindableProperty IndicatorsContextsProperty = BindableProperty.Create(nameof(IndicatorsContexts), typeof(IList), typeof(IndicatorsControl), null);

public static readonly BindableProperty ItemTemplateProperty = BindableProperty.Create(nameof(ItemTemplate), typeof(DataTemplate), typeof(IndicatorsControl), new DataTemplate(typeof(IndicatorItemView)));
Expand All @@ -72,6 +77,7 @@ public IndicatorsControl()
this.SetBinding(IndicatorsContextsProperty, nameof(CardsView.ItemsSource));
this.SetBinding(IsUserInteractionRunningProperty, nameof(CardsView.IsUserInteractionRunning));
this.SetBinding(IsAutoInteractionRunningProperty, nameof(CardsView.IsAutoInteractionRunning));
this.SetBinding(IsRightToLeftFlowDirectionEnabledProperty, nameof(CardsView.IsRightToLeftFlowDirectionEnabled));

Margin = new Thickness(10, 20);
AbsoluteLayout.SetLayoutBounds(this, new Rectangle(.5, 1, -1, -1));
Expand Down Expand Up @@ -146,6 +152,12 @@ public bool UseParentAsBindingContext
set => SetValue(UseParentAsBindingContextProperty, value);
}

public bool IsRightToLeftFlowDirectionEnabled
{
get => (bool)GetValue(IsRightToLeftFlowDirectionEnabledProperty);
set => SetValue(IsRightToLeftFlowDirectionEnabledProperty, value);
}

public int ToFadeDuration
{
get => (int)GetValue(ToFadeDurationProperty);
Expand Down Expand Up @@ -235,11 +247,17 @@ protected virtual async void ResetVisibility(uint? appearingTime = null, Easing
}
}

protected virtual void OnFlowDirectionChanged()
{
Rotation = IsRightToLeftFlowDirectionEnabled ? 180 : 0;
}

private void ApplyStyle(View view, int cyclingIndex)
{
try
{
view.BatchBegin();
view.Rotation = 0;
if (IndexOf(view) == cyclingIndex)
{
ApplySelectedStyle(view, cyclingIndex);
Expand All @@ -249,6 +267,7 @@ private void ApplyStyle(View view, int cyclingIndex)
}
finally
{
view.Rotation += IsRightToLeftFlowDirectionEnabled ? -180 : 0;
view.BatchCommit();
}
}
Expand Down
3 changes: 1 addition & 2 deletions PanCardView/PanCardView.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{662BF768-43C5-4A71-8F1E-7FA54DD6157A}</ProjectGuid>
<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<UseMSBuildEngine>true</UseMSBuildEngine>
<OutputType>Library</OutputType>
<RootNamespace>PanCardView</RootNamespace>
<AssemblyName>PanCardView</AssemblyName>
Expand Down Expand Up @@ -96,7 +95,7 @@
<MonoDevelop>
<Properties>
<Policies>
<TextStylePolicy inheritsSet="null" scope="text/x-csharp" />
<TextStylePolicy TabWidth="4" IndentWidth="4" RemoveTrailingWhitespace="True" NoTabsAfterNonTabs="False" EolMarker="Native" FileWidth="80" TabsToSpaces="True" scope="text/x-csharp" />
<CSharpFormattingPolicy IndentBlock="True" IndentBraces="False" IndentSwitchSection="True" IndentSwitchCaseSection="True" LabelPositioning="OneLess" NewLinesForBracesInTypes="True" NewLinesForBracesInMethods="True" NewLinesForBracesInProperties="True" NewLinesForBracesInAccessors="True" NewLinesForBracesInAnonymousMethods="True" NewLinesForBracesInControlBlocks="True" NewLinesForBracesInAnonymousTypes="True" NewLinesForBracesInObjectCollectionArrayInitializers="True" NewLinesForBracesInLambdaExpressionBody="True" NewLineForElse="True" NewLineForCatch="True" NewLineForFinally="True" NewLineForMembersInObjectInit="True" NewLineForMembersInAnonymousTypes="True" NewLineForClausesInQuery="True" SpacingAfterMethodDeclarationName="False" SpaceWithinMethodDeclarationParenthesis="False" SpaceBetweenEmptyMethodDeclarationParentheses="False" SpaceAfterMethodCallName="False" SpaceWithinMethodCallParentheses="False" SpaceBetweenEmptyMethodCallParentheses="False" SpaceAfterControlFlowStatementKeyword="True" SpaceWithinExpressionParentheses="False" SpaceWithinCastParentheses="False" SpaceWithinOtherParentheses="False" SpaceAfterCast="False" SpacesIgnoreAroundVariableDeclaration="False" SpaceBeforeOpenSquareBracket="False" SpaceBetweenEmptySquareBrackets="False" SpaceWithinSquareBrackets="False" SpaceAfterColonInBaseTypeDeclaration="True" SpaceAfterComma="True" SpaceAfterDot="False" SpaceAfterSemicolonsInForStatement="True" SpaceBeforeColonInBaseTypeDeclaration="True" SpaceBeforeComma="False" SpaceBeforeDot="False" SpaceBeforeSemicolonsInForStatement="False" SpacingAroundBinaryOperator="Single" WrappingPreserveSingleLine="True" WrappingKeepStatementsOnSingleLine="True" PlaceSystemDirectiveFirst="True" scope="text/x-csharp" />
<TextStylePolicy TabWidth="4" IndentWidth="4" RemoveTrailingWhitespace="True" NoTabsAfterNonTabs="False" EolMarker="Native" FileWidth="80" TabsToSpaces="True" scope="text/plain" />
</Policies>
Expand Down
3 changes: 2 additions & 1 deletion PanCardViewSample/PanCardViewSample.sln
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,9 @@ Global
$0.DotNetNamingPolicy = $1
$1.DirectoryNamespaceAssociation = PrefixedHierarchical
$0.TextStylePolicy = $2
$2.inheritsSet = null
$2.scope = text/x-csharp
$2.FileWidth = 80
$2.TabsToSpaces = True
$0.CSharpFormattingPolicy = $3
$3.scope = text/x-csharp
$0.TextStylePolicy = $4
Expand Down

0 comments on commit 0158402

Please sign in to comment.