Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions TabViewSample/TabViewSample.Android/MainActivity.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
using System;

using Android;
using Android.App;
using Android.Content.PM;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
using CarouselView.FormsPlugin.Android;

namespace TabViewSample.Droid
{
Expand All @@ -15,16 +14,12 @@ public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompa
{
protected override void OnCreate(Bundle bundle)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;

base.OnCreate(bundle);


global:Xamarin.Forms.Forms.SetFlags("CarouselView_Experimental");

global::Xamarin.Forms.Forms.Init(this, bundle);

// Initialize CarouselView
CarouselViewRenderer.Init();

LoadApplication(new App());
}
}
Expand Down
12,995 changes: 7,841 additions & 5,154 deletions TabViewSample/TabViewSample.Android/Resources/Resource.designer.cs

Large diffs are not rendered by default.

26 changes: 16 additions & 10 deletions TabViewSample/TabViewSample.Android/TabViewSample.Android.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AndroidLinkMode>None</AndroidLinkMode>
<AndroidSupportedAbis>arm64-v8a;armeabi-v7a;x86;x86_64</AndroidSupportedAbis>
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was unable to build the sample app without this line.

</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand All @@ -38,6 +39,12 @@
<AndroidManagedSymbols>true</AndroidManagedSymbols>
<AndroidUseSharedRuntime>false</AndroidUseSharedRuntime>
</PropertyGroup>
<PropertyGroup Condition=" '$(OS)' == 'Unix' ">
<MonoAndroidToolsDirectory>/usr/lib/mono/xbuild-frameworks/MonoAndroid</MonoAndroidToolsDirectory>
<MonoAndroidBinDirectory>/usr/lib/mono/xbuild/Xamarin</MonoAndroidBinDirectory>
<AndroidSdkDirectory>$(ANDROID_SDK_PATH)</AndroidSdkDirectory>
<AndroidNdkDirectory>$(ANDROID_NDK_PATH)</AndroidNdkDirectory>
</PropertyGroup>
<ItemGroup>
<Reference Include="Mono.Android" />
<Reference Include="System" />
Expand All @@ -46,19 +53,17 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="CarouselView.FormsPlugin">
<Version>5.2.0</Version>
</PackageReference>
<PackageReference Include="Xamarin.Forms" Version="3.1.0.583944" />
<PackageReference Include="Xamarin.Android.Support.Design" Version="25.4.0.2" />
<PackageReference Include="Xamarin.Android.Support.v7.AppCompat" Version="25.4.0.2" />
<PackageReference Include="Xamarin.Android.Support.v4" Version="25.4.0.2" />
<PackageReference Include="Xamarin.Android.Support.v7.CardView" Version="25.4.0.2" />
<PackageReference Include="Xamarin.Android.Support.v7.MediaRouter" Version="25.4.0.2" />
<PackageReference Include="Xamarin.Forms" Version="4.4.0.991220-pre3" />
<PackageReference Include="Xamarin.Android.Support.Design" Version="28.0.0.3" />
<PackageReference Include="Xamarin.Android.Support.v7.AppCompat" Version="28.0.0.3" />
<PackageReference Include="Xamarin.Android.Support.v4" Version="28.0.0.3" />
<PackageReference Include="Xamarin.Android.Support.v7.CardView" Version="28.0.0.3" />
<PackageReference Include="Xamarin.Android.Support.v7.MediaRouter" Version="28.0.0.3" />
<PackageReference Include="Xamarin.Android.Support.Core.Utils" Version="28.0.0.3" />
<PackageReference Include="Xamarin.Android.Support.CustomTabs" Version="28.0.0.3" />
</ItemGroup>
<ItemGroup>
<Compile Include="MainActivity.cs" />
<Compile Include="Resources\Resource.Designer.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
Expand All @@ -77,6 +82,7 @@
<ItemGroup>
<AndroidResource Include="Resources\layout\Tabbar.axml" />
<AndroidResource Include="Resources\layout\Toolbar.axml" />
<AndroidResource Include="Resources\Resource.designer.cs" />
<AndroidResource Include="Resources\values\styles.xml">
<SubType>Designer</SubType>
</AndroidResource>
Expand Down
2 changes: 1 addition & 1 deletion TabViewSample/TabViewSample.UWP/TabViewSample.UWP.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@
<PackageReference Include="CarouselView.FormsPlugin">
<Version>5.2.0</Version>
</PackageReference>
<PackageReference Include="Xamarin.Forms" Version="3.1.0.583944" />
<PackageReference Include="Xamarin.Forms" Version="4.4.0.991220-pre3" />
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform" Version="6.0.6" />
</ItemGroup>
<ItemGroup>
Expand Down
4 changes: 1 addition & 3 deletions TabViewSample/TabViewSample.iOS/AppDelegate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,9 @@ public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsAppli
//
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
global::Xamarin.Forms.Forms.SetFlags("CarouselView_Experimental");
global::Xamarin.Forms.Forms.Init();

// Initialize CarouselView
CarouselViewRenderer.Init();

LoadApplication(new App());

return base.FinishedLaunching(app, options);
Expand Down
15 changes: 11 additions & 4 deletions TabViewSample/TabViewSample.iOS/TabViewSample.iOS.csproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\..\packages\Xamarin.Forms.4.4.0.991220-pre3\build\Xamarin.Forms.props" Condition="Exists('..\..\packages\Xamarin.Forms.4.4.0.991220-pre3\build\Xamarin.Forms.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">iPhoneSimulator</Platform>
Expand Down Expand Up @@ -93,6 +94,7 @@
<None Include="Entitlements.plist" />
<None Include="Info.plist" />
<Compile Include="Properties\AssemblyInfo.cs" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<BundleResource Include="Resources\Default-568h%402x.png" />
Expand All @@ -119,10 +121,7 @@
<Reference Include="Xamarin.iOS" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="CarouselView.FormsPlugin">
<Version>5.2.0</Version>
</PackageReference>
<PackageReference Include="Xamarin.Forms" Version="3.1.0.583944" />
<PackageReference Include="Xamarin.Forms" Version="4.4.0.991220-pre3" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.CSharp.targets" />
<ItemGroup>
Expand All @@ -134,4 +133,12 @@
<ItemGroup>
<BundleResource Include="Resources\monkey.png" />
</ItemGroup>
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105.The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\..\packages\Xamarin.Forms.4.4.0.991220-pre3\build\Xamarin.Forms.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\Xamarin.Forms.4.4.0.991220-pre3\build\Xamarin.Forms.props'))" />
<Error Condition="!Exists('..\..\packages\Xamarin.Forms.4.4.0.991220-pre3\build\Xamarin.Forms.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\Xamarin.Forms.4.4.0.991220-pre3\build\Xamarin.Forms.targets'))" />
</Target>
<Import Project="..\..\packages\Xamarin.Forms.4.4.0.991220-pre3\build\Xamarin.Forms.targets" Condition="Exists('..\..\packages\Xamarin.Forms.4.4.0.991220-pre3\build\Xamarin.Forms.targets')" />
</Project>
2 changes: 1 addition & 1 deletion TabViewSample/TabViewSample.iOS/packages.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Xamarin.Forms" version="2.4.0.266-pre1" targetFramework="xamarinios10" />
<package id="Xamarin.Forms" version="4.4.0.991220-pre3" targetFramework="net" />
</packages>
2 changes: 1 addition & 1 deletion TabViewSample/TabViewSample/TabViewSample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Xamarin.Forms" Version="3.1.0.583944" />
<PackageReference Include="Xamarin.Forms" Version="4.4.0.991220-pre3" />
</ItemGroup>

<ItemGroup>
Expand Down
59 changes: 29 additions & 30 deletions Xam.Plugin.TabView/Xam.Plugin.TabView.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using CarouselView.FormsPlugin.Abstractions;
using System;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
using Xam.Plugin.TabView.Converters;
using Xamarin.Forms;

Expand All @@ -18,13 +18,7 @@ public class PositionChangingEventArgs : EventArgs
public int NewPosition { get; set; }
public int OldPosition { get; set; }
}

public class PositionChangedEventArgs : EventArgs
{
public int NewPosition { get; set; }
public int OldPosition { get; set; }
}


static class TabDefaults
{
public static readonly Color DefaultColor = Color.White;
Expand All @@ -36,8 +30,9 @@ public class TabViewControl : ContentView
{
private StackLayout _mainContainerSL;
private Grid _headerContainerGrid;
private CarouselViewControl _carouselView;
private CarouselView _carouselView;
private ScrollView _tabHeadersContainerSv;
private ConstructorInfo _positionChangedEventArgsInfo;

public event PositionChangingEventHandler PositionChanging;
public event PositionChangedEventHandler PositionChanged;
Expand Down Expand Up @@ -124,10 +119,10 @@ private void _carouselView_PropertyChanged(object sender, PropertyChangedEventAr
if (positionChangingArgs != null && positionChangingArgs.Canceled)
{
_supressCarouselViewPositionChangedEvent = true;
_carouselView.PositionSelected -= _carouselView_PositionSelected;
_carouselView.PositionChanged -= _carouselView_PositionSelected;
_carouselView.PropertyChanged -= _carouselView_PropertyChanged;
_carouselView.Position = SelectedTabIndex;
_carouselView.PositionSelected += _carouselView_PositionSelected;
_carouselView.PositionChanged += _carouselView_PositionSelected;
_carouselView.PropertyChanged += _carouselView_PropertyChanged;
_supressCarouselViewPositionChangedEvent = false;
}
Expand Down Expand Up @@ -158,18 +153,23 @@ private void Init()
HorizontalOptions = LayoutOptions.FillAndExpand
};

_carouselView = new CarouselViewControl
_carouselView = new CarouselView()
{
HorizontalOptions = LayoutOptions.FillAndExpand,
VerticalOptions = LayoutOptions.FillAndExpand,
HeightRequest = ContentHeight,
ShowArrows = false,
ShowIndicators = false,
BindingContext = this
BindingContext = this,
ItemTemplate = new DataTemplate(() =>
{
ContentView c = new ContentView();
c.SetBinding(ContentView.ContentProperty, "Content");
return c;
})
};

_positionChangedEventArgsInfo = typeof(PositionChangedEventArgs).GetTypeInfo().DeclaredConstructors.First();

_carouselView.PropertyChanged += _carouselView_PropertyChanged;
_carouselView.PositionSelected += _carouselView_PositionSelected;
_carouselView.PositionChanged += _carouselView_PositionSelected;

_mainContainerSL = new StackLayout
{
Expand Down Expand Up @@ -199,11 +199,11 @@ protected override void OnBindingContextChanged()
}
}

private void _carouselView_PositionSelected(object sender, PositionSelectedEventArgs e)
private void _carouselView_PositionSelected(object sender, PositionChangedEventArgs e)
{
if (_carouselView.Position != e.NewValue || SelectedTabIndex != e.NewValue)
if (_carouselView.Position != e.CurrentPosition || SelectedTabIndex != e.CurrentPosition)
{
SetPosition(e.NewValue);
SetPosition(e.CurrentPosition);
}
}

Expand Down Expand Up @@ -291,7 +291,7 @@ private void AddTabToView(TabItem tab)
};
headerItemSL.GestureRecognizers.Add(tapRecognizer);
_headerContainerGrid.Children.Add(headerItemSL, _headerContainerGrid.ColumnDefinitions.Count - 1, 0);
_carouselView.ItemsSource = ItemSource.Select(t => t.Content);
_carouselView.ItemsSource = ItemSource;
}

#region IsSwipingEnabled
Expand Down Expand Up @@ -548,9 +548,9 @@ public void SetPosition(int position, bool initialRun = false)
{
if (_carouselView.Position != position || initialRun)
{
_carouselView.PositionSelected -= _carouselView_PositionSelected;
_carouselView.PositionChanged -= _carouselView_PositionSelected;
_carouselView.Position = position;
_carouselView.PositionSelected += _carouselView_PositionSelected;
_carouselView.PositionChanged += _carouselView_PositionSelected;
}
if (oldPosition != position)
{
Expand All @@ -565,11 +565,9 @@ public void SetPosition(int position, bool initialRun = false)
}
}

var positionChangedArgs = new PositionChangedEventArgs()
{
NewPosition = SelectedTabIndex,
OldPosition = oldPosition
};
var positionChangedArgs = _positionChangedEventArgsInfo.Invoke(
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PositionChangedEventArgs has an internal constructor so this is a "hacky" way to call it.

Copy link

@tmijieux tmijieux Dec 17, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kapseliboi you do not have to remove the PositionChangedEventArgs definition in the Xam.Plugin.TabView namespace nor to use the internal constructor:

Just use the fully qualified name "Xamarin.Forms.PositionChangedEventArgs" in the _carouselView_PositionSelected method parameter and continue using Xam.Plugin.TabView.PositionChangedEventArgs for the rest (fully qualified name is not required for this one i think)

That would prevent the API breakage

new object[] { oldPosition, SelectedTabIndex }) as PositionChangedEventArgs;

OnPositionChanged(positionChangedArgs);
}

Expand Down Expand Up @@ -623,7 +621,8 @@ public void RemoveTab(int position = -1)
_headerContainerGrid.Children.RemoveAt(_headerContainerGrid.Children.Count - 1);
_headerContainerGrid.ColumnDefinitions.Remove(_headerContainerGrid.ColumnDefinitions.Last());
}
_carouselView.ItemsSource = ItemSource.Select(t => t.Content);

_carouselView.ItemsSource = ItemSource;
SelectedTabIndex = position >= 0 && position < ItemSource.Count ? position : ItemSource.Count - 1;
}
}
Expand Down
3 changes: 1 addition & 2 deletions Xam.Plugin.TabView/Xam.Plugin.TabView.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CarouselView.FormsPlugin" Version="5.2.0" />
<PackageReference Include="Xamarin.Forms" Version="3.1.0.583944" />
<PackageReference Include="Xamarin.Forms" Version="4.4.0.991220-pre3" />
</ItemGroup>

</Project>
3 changes: 1 addition & 2 deletions Xam.Plugin.TabView/Xam.Plugin.TabView.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
<tags>xamarin forms android ios uwp tabview tab control plugin chaosifier xam</tags>
<dependencies>
<group targetFramework=".NETStandard2.0">
<dependency id="CarouselView.FormsPlugin" version="5.2.0" exclude="Build,Analyzers" />
<dependency id="Xamarin.Forms" version="3.1.0.583944" exclude="Build,Analyzers" />
<dependency id="Xamarin.Forms" version="4.4.0.991220-pre3" exclude="Build,Analyzers" />
</group>
</dependencies>
</metadata>
Expand Down