diff options
Diffstat (limited to 'Xamarin.Forms.Controls')
-rw-r--r-- | Xamarin.Forms.Controls/App.cs | 31 | ||||
-rw-r--r-- | Xamarin.Forms.Controls/CoreGallery.cs | 1 | ||||
-rw-r--r-- | Xamarin.Forms.Controls/GalleryPages/AppLinkPageGallery.cs | 80 | ||||
-rw-r--r-- | Xamarin.Forms.Controls/Xamarin.Forms.Controls.csproj | 5 |
4 files changed, 117 insertions, 0 deletions
diff --git a/Xamarin.Forms.Controls/App.cs b/Xamarin.Forms.Controls/App.cs index 31c356e3..b297097c 100644 --- a/Xamarin.Forms.Controls/App.cs +++ b/Xamarin.Forms.Controls/App.cs @@ -32,6 +32,37 @@ namespace Xamarin.Forms.Controls }; } + protected override void OnAppLinkRequestReceived(Uri uri) + { + + var appDomain = "http://" + AppName.ToLowerInvariant() + "/"; + + if (!uri.ToString().ToLowerInvariant().StartsWith(appDomain)) + return; + + var url = uri.ToString().Replace(appDomain, ""); + + var parts = url.Split('/'); + if (parts.Length == 2) + { + var isPage = parts[0].Trim().ToLower() == "gallery"; + if (isPage) + { + string page = parts[1].Trim(); + var pageForms = Activator.CreateInstance(Type.GetType(page)); + + var appLinkPageGallery = pageForms as AppLinkPageGallery; + if (appLinkPageGallery != null) + { + appLinkPageGallery.ShowLabel = true; + (MainPage as MasterDetailPage)?.Detail.Navigation.PushAsync((pageForms as Page)); + } + } + } + + base.OnAppLinkRequestReceived(uri); + } + public static Dictionary<string, string> Config { get diff --git a/Xamarin.Forms.Controls/CoreGallery.cs b/Xamarin.Forms.Controls/CoreGallery.cs index 7b6ed150..d060fbbc 100644 --- a/Xamarin.Forms.Controls/CoreGallery.cs +++ b/Xamarin.Forms.Controls/CoreGallery.cs @@ -196,6 +196,7 @@ namespace Xamarin.Forms.Controls { var pages = new List<Page> { new CarouselViewGallaryPage {Title = "CarouselView Gallery"}, + new AppLinkPageGallery {Title = "App Link Page Gallery"}, new NestedNativeControlGalleryPage {Title = "Nested Native Controls Gallery"}, new CellForceUpdateSizeGalleryPage {Title = "Cell Force Update Size Gallery"}, new AppearingGalleryPage {Title = "Appearing Gallery"}, diff --git a/Xamarin.Forms.Controls/GalleryPages/AppLinkPageGallery.cs b/Xamarin.Forms.Controls/GalleryPages/AppLinkPageGallery.cs new file mode 100644 index 00000000..bc765dd9 --- /dev/null +++ b/Xamarin.Forms.Controls/GalleryPages/AppLinkPageGallery.cs @@ -0,0 +1,80 @@ +using System; + +namespace Xamarin.Forms.Controls +{ + public class AppLinkPageGallery : ContentPage + { + public AppLinkPageGallery () + { + _linkEntry = GetEntry (); + _lbl = new Label { + Text = "You are on a demo page via app url", IsVisible = ShowLabel + }; + + var btnRegister = new Button { Text = "Index this Page", + Command = new Command (() => Application.Current.AppLinks.RegisterLink (LinkEntry)) + }; + var btnRemove = new Button { Text = "Remove this Page from index", + Command = new Command (() => Application.Current.AppLinks.DeregisterLink (LinkEntry)) + }; + + var btnClearAll = new Button { Text = "Clear All Indexed Data", + // Command = new Command (() => Application.Current.AppLinks.DeregisterAll ()) + }; + + Content = new StackLayout { Children = { _lbl, btnRegister, btnRemove, btnClearAll } }; + } + + protected override void OnAppearing () + { + LinkEntry.IsLinkActive = true; + } + + protected override void OnDisappearing () + { + LinkEntry.IsLinkActive = false; + } + + public bool ShowLabel { + get { + return _showlabel; + } + set { + _showlabel = value; + _lbl.IsVisible = _showlabel; + } + } + + internal IAppLinkEntry LinkEntry { + get { + return _linkEntry; + } + } + + bool _showlabel; + IAppLinkEntry _linkEntry; + Label _lbl; + + AppLinkEntry GetEntry () + { + if (string.IsNullOrEmpty (Title)) + Title = "App Link Page Gallery"; + + var type = GetType ().ToString (); + var entry = new AppLinkEntry { + Title = Title, + Description =$"This is the page {Title} \nof Xamarin Forms Gallery", + AppLinkUri = new Uri ($"http://{App.AppName}/gallery/{type}", UriKind.RelativeOrAbsolute), + IsLinkActive = true, + Thumbnail = ImageSource.FromFile ("seth.png") + }; + + entry.KeyValues.Add ("contentType", "GalleryPage"); + entry.KeyValues.Add ("appName", App.AppName); + entry.KeyValues.Add ("companyName", "Xamarin"); + + return entry; + } + } +} + diff --git a/Xamarin.Forms.Controls/Xamarin.Forms.Controls.csproj b/Xamarin.Forms.Controls/Xamarin.Forms.Controls.csproj index b5dd6af5..3252403b 100644 --- a/Xamarin.Forms.Controls/Xamarin.Forms.Controls.csproj +++ b/Xamarin.Forms.Controls/Xamarin.Forms.Controls.csproj @@ -72,6 +72,10 @@ <Project>{7d13bac2-c6a4-416a-b07e-c169b199e52b}</Project> <Name>Xamarin.Forms.Maps</Name> </ProjectReference> + <ProjectReference Include="..\Xamarin.Forms.Pages\Xamarin.Forms.Pages.csproj"> + <Project>{d6133dbd-6c60-4bd5-bea2-07e0a3927c31}</Project> + <Name>Xamarin.Forms.Pages</Name> + </ProjectReference> <ProjectReference Include="..\Xamarin.Forms.Xaml\Xamarin.Forms.Xaml.csproj"> <Project>{9db2f292-8034-4e06-89ad-98bbda4306b9}</Project> <Name>Xamarin.Forms.Xaml</Name> @@ -224,6 +228,7 @@ <Compile Include="ControlGalleryPages\PinchGestureTestPage.cs" /> <Compile Include="ControlGalleryPages\AppearingGalleryPage.cs" /> <Compile Include="ControlGalleryPages\AutomationIDGallery.cs" /> + <Compile Include="GalleryPages\AppLinkPageGallery.cs" /> </ItemGroup> <Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" /> <Import Project="..\.nuspec\Xamarin.Forms.targets" /> |