1
0
mirror of https://github.com/bitwarden/mobile.git synced 2025-01-02 18:07:56 +01:00

Created device specific navigation push/pops in order to support non-modal navigation on android (so we get the back button in nav).

This commit is contained in:
Kyle Spearrin 2016-08-29 23:50:22 -04:00
parent 0cba25fc0c
commit 22ac095dce
12 changed files with 65 additions and 38 deletions

View File

@ -56,7 +56,7 @@ namespace Bit.App
} }
else else
{ {
MainPage = new HomePage(); MainPage = new ExtendedNavigationPage(new HomePage());
} }
MessagingCenter.Subscribe<Application, bool>(Current, "Resumed", async (sender, args) => MessagingCenter.Subscribe<Application, bool>(Current, "Resumed", async (sender, args) =>
@ -203,7 +203,7 @@ namespace Bit.App
_googleAnalyticsService.TrackAppEvent("LoggedOut"); _googleAnalyticsService.TrackAppEvent("LoggedOut");
_googleAnalyticsService.RefreshUserId(); _googleAnalyticsService.RefreshUserId();
Current.MainPage = new HomePage(); Current.MainPage = new ExtendedNavigationPage(new HomePage());
if(!string.IsNullOrWhiteSpace(logoutMessage)) if(!string.IsNullOrWhiteSpace(logoutMessage))
{ {
_userDialogs.Toast(logoutMessage); _userDialogs.Toast(logoutMessage);

View File

@ -77,6 +77,7 @@ namespace Bit.App.Pages
}; };
Title = "bitwarden"; Title = "bitwarden";
NavigationPage.SetHasNavigationBar(this, false);
Content = new ScrollView { Content = buttonStackLayout }; Content = new ScrollView { Content = buttonStackLayout };
} }
@ -88,18 +89,18 @@ namespace Bit.App.Pages
public async Task LoginAsync() public async Task LoginAsync()
{ {
await Navigation.PushModalAsync(new ExtendedNavigationPage(new LoginPage())); await Navigation.PushForDeviceAsync(new LoginPage());
} }
public async Task RegisterAsync() public async Task RegisterAsync()
{ {
await Navigation.PushModalAsync(new ExtendedNavigationPage(new RegisterPage(this))); await Navigation.PushForDeviceAsync(new RegisterPage(this));
} }
public async Task DismissRegisterAndLoginAsync(string email) public async Task DismissRegisterAndLoginAsync(string email)
{ {
await Navigation.PopModalAsync(); await Navigation.PopForDeviceAsync();
await Navigation.PushModalAsync(new ExtendedNavigationPage(new LoginPage(email))); await Navigation.PushForDeviceAsync(new LoginPage(email));
_userDialogs.Toast("Your new account has been created! You may now log in."); _userDialogs.Toast("Your new account has been created! You may now log in.");
} }
} }

View File

@ -79,7 +79,7 @@ namespace Bit.App.Pages
if(saveResult.Succeeded) if(saveResult.Succeeded)
{ {
await Navigation.PopModalAsync(); await Navigation.PopForDeviceAsync();
_userDialogs.Toast("New folder created."); _userDialogs.Toast("New folder created.");
_googleAnalyticsService.TrackAppEvent("CreatedFolder"); _googleAnalyticsService.TrackAppEvent("CreatedFolder");
} }

View File

@ -93,7 +93,7 @@ namespace Bit.App.Pages
if(saveResult.Succeeded) if(saveResult.Succeeded)
{ {
await Navigation.PopModalAsync(); await Navigation.PopForDeviceAsync();
_userDialogs.Toast("Folder updated."); _userDialogs.Toast("Folder updated.");
_googleAnalyticsService.TrackAppEvent("EditedFolder"); _googleAnalyticsService.TrackAppEvent("EditedFolder");
} }
@ -147,7 +147,7 @@ namespace Bit.App.Pages
if(deleteTask.Succeeded) if(deleteTask.Succeeded)
{ {
await Navigation.PopModalAsync(); await Navigation.PopForDeviceAsync();
_userDialogs.Toast("Folder deleted."); _userDialogs.Toast("Folder deleted.");
} }
else if(deleteTask.Errors.Count() > 0) else if(deleteTask.Errors.Count() > 0)

View File

@ -55,11 +55,11 @@ namespace Bit.App.Pages
Folders.ResetWithRange(pageFolders); Folders.ResetWithRange(pageFolders);
} }
private void FolderSelected(object sender, SelectedItemChangedEventArgs e) private async void FolderSelected(object sender, SelectedItemChangedEventArgs e)
{ {
var folder = e.SelectedItem as SettingsFolderPageModel; var folder = e.SelectedItem as SettingsFolderPageModel;
var page = new ExtendedNavigationPage(new SettingsEditFolderPage(folder.Id)); var page = new SettingsEditFolderPage(folder.Id);
Navigation.PushModalAsync(page); await Navigation.PushForDeviceAsync(page);
} }
private class AddFolderToolBarItem : ToolbarItem private class AddFolderToolBarItem : ToolbarItem
@ -76,8 +76,8 @@ namespace Bit.App.Pages
private async void ClickedItem(object sender, EventArgs e) private async void ClickedItem(object sender, EventArgs e)
{ {
var page = new ExtendedNavigationPage(new SettingsAddFolderPage()); var page = new SettingsAddFolderPage();
await _page.Navigation.PushModalAsync(page); await _page.Navigation.PushForDeviceAsync(page);
} }
} }

View File

@ -52,7 +52,7 @@ namespace Bit.App.Pages
"Use the bitwarden accessibility service to auto-fill your logins.", "upload"); "Use the bitwarden accessibility service to auto-fill your logins.", "upload");
autofillServiceCell.Tapped += (object sender, EventArgs e) => autofillServiceCell.Tapped += (object sender, EventArgs e) =>
{ {
Navigation.PushModalAsync(new ExtendedNavigationPage(new ToolsAutofillServicePage())); Navigation.PushAsync(new ToolsAutofillServicePage());
}; };
section.Add(autofillServiceCell); section.Add(autofillServiceCell);
} }
@ -81,9 +81,9 @@ namespace Bit.App.Pages
Content = table; Content = table;
} }
private void GeneratorCell_Tapped(object sender, EventArgs e) private async void GeneratorCell_Tapped(object sender, EventArgs e)
{ {
Navigation.PushModalAsync(new ExtendedNavigationPage(new ToolsPasswordGeneratorPage())); await Navigation.PushForDeviceAsync(new ToolsPasswordGeneratorPage());
} }
private void WebCell_Tapped(object sender, EventArgs e) private void WebCell_Tapped(object sender, EventArgs e)

View File

@ -112,7 +112,7 @@ namespace Bit.App.Pages
{ {
_googleAnalyticsService.TrackAppEvent("SelectedGeneratedPassword"); _googleAnalyticsService.TrackAppEvent("SelectedGeneratedPassword");
_passwordValueAction(Password.Text); _passwordValueAction(Password.Text);
await Navigation.PopModalAsync(); await Navigation.PopForDeviceAsync();
}, ToolbarItemOrder.Default, 0); }, ToolbarItemOrder.Default, 0);
ToolbarItems.Add(selectToolBarItem); ToolbarItems.Add(selectToolBarItem);

View File

@ -146,7 +146,7 @@ namespace Bit.App.Pages
_userDialogs.HideLoading(); _userDialogs.HideLoading();
if(saveTask.Succeeded) if(saveTask.Succeeded)
{ {
await Navigation.PopModalAsync(); await Navigation.PopForDeviceAsync();
_userDialogs.Toast("New site created."); _userDialogs.Toast("New site created.");
_googleAnalyticsService.TrackAppEvent("CreatedSite"); _googleAnalyticsService.TrackAppEvent("CreatedSite");
} }
@ -187,14 +187,14 @@ namespace Bit.App.Pages
} }
} }
private void GenerateCell_Tapped(object sender, EventArgs e) private async void GenerateCell_Tapped(object sender, EventArgs e)
{ {
var page = new ToolsPasswordGeneratorPage((password) => var page = new ToolsPasswordGeneratorPage((password) =>
{ {
PasswordCell.Entry.Text = password; PasswordCell.Entry.Text = password;
_userDialogs.Toast("Password generated."); _userDialogs.Toast("Password generated.");
}); });
Navigation.PushModalAsync(new ExtendedNavigationPage(page)); await Navigation.PushForDeviceAsync(page);
} }
private void AlertNoConnection() private void AlertNoConnection()

View File

@ -176,7 +176,7 @@ namespace Bit.App.Pages
if(saveTask.Succeeded) if(saveTask.Succeeded)
{ {
await Navigation.PopModalAsync(); await Navigation.PopForDeviceAsync();
_userDialogs.Toast("Site updated."); _userDialogs.Toast("Site updated.");
_googleAnalyticsService.TrackAppEvent("EditedSite"); _googleAnalyticsService.TrackAppEvent("EditedSite");
} }
@ -222,7 +222,7 @@ namespace Bit.App.Pages
PasswordCell.Entry.Text = password; PasswordCell.Entry.Text = password;
_userDialogs.Toast("Password generated."); _userDialogs.Toast("Password generated.");
}); });
await Navigation.PushModalAsync(new ExtendedNavigationPage(page)); await Navigation.PushForDeviceAsync(page);
} }
private async void DeleteCell_Tapped(object sender, EventArgs e) private async void DeleteCell_Tapped(object sender, EventArgs e)
@ -244,7 +244,7 @@ namespace Bit.App.Pages
if(deleteTask.Succeeded) if(deleteTask.Succeeded)
{ {
await Navigation.PopModalAsync(); await Navigation.PopForDeviceAsync();
_userDialogs.Toast("Site deleted."); _userDialogs.Toast("Site deleted.");
_googleAnalyticsService.TrackAppEvent("DeletedSite"); _googleAnalyticsService.TrackAppEvent("DeletedSite");
} }

View File

@ -354,11 +354,11 @@ namespace Bit.App.Pages
}); });
} }
private void SiteSelected(object sender, SelectedItemChangedEventArgs e) private async void SiteSelected(object sender, SelectedItemChangedEventArgs e)
{ {
var site = e.SelectedItem as VaultListPageModel.Site; var site = e.SelectedItem as VaultListPageModel.Site;
var page = new ExtendedNavigationPage(new VaultViewSitePage(site.Id)); var page = new VaultViewSitePage(site.Id);
Navigation.PushModalAsync(page); await Navigation.PushForDeviceAsync(page);
} }
private async void MoreClickedAsync(VaultListPageModel.Site site) private async void MoreClickedAsync(VaultListPageModel.Site site)
@ -382,13 +382,13 @@ namespace Bit.App.Pages
if(selection == AppResources.View) if(selection == AppResources.View)
{ {
var page = new ExtendedNavigationPage(new VaultViewSitePage(site.Id)); var page = new VaultViewSitePage(site.Id);
await Navigation.PushModalAsync(page); await Navigation.PushForDeviceAsync(page);
} }
else if(selection == AppResources.Edit) else if(selection == AppResources.Edit)
{ {
var page = new ExtendedNavigationPage(new VaultEditSitePage(site.Id)); var page = new VaultEditSitePage(site.Id);
await Navigation.PushModalAsync(page); await Navigation.PushForDeviceAsync(page);
} }
else if(selection == AppResources.CopyPassword) else if(selection == AppResources.CopyPassword)
{ {
@ -412,8 +412,8 @@ namespace Bit.App.Pages
private async void AddSite() private async void AddSite()
{ {
var page = new ExtendedNavigationPage(new VaultAddSitePage()); var page = new VaultAddSitePage();
await Navigation.PushModalAsync(page); await Navigation.PushForDeviceAsync(page);
} }
private class AddSiteToolBarItem : ToolbarItem private class AddSiteToolBarItem : ToolbarItem

View File

@ -116,7 +116,7 @@ namespace Bit.App.Pages
var site = await _siteService.GetByIdAsync(_siteId); var site = await _siteService.GetByIdAsync(_siteId);
if(site == null) if(site == null)
{ {
await Navigation.PopModalAsync(); await Navigation.PopForDeviceAsync();
return; return;
} }
@ -182,8 +182,8 @@ namespace Bit.App.Pages
private async void ClickedItem(object sender, EventArgs e) private async void ClickedItem(object sender, EventArgs e)
{ {
var page = new ExtendedNavigationPage(new VaultEditSitePage(_siteId)); var page = new VaultEditSitePage(_siteId);
await _page.Navigation.PushModalAsync(page); await _page.Navigation.PushForDeviceAsync(page);
} }
} }
} }

View File

@ -3,6 +3,8 @@ using Bit.App.Abstractions;
using Bit.App.Models; using Bit.App.Models;
using Xamarin.Forms; using Xamarin.Forms;
using XLabs.Ioc; using XLabs.Ioc;
using System.Threading.Tasks;
using Bit.App.Controls;
namespace Bit.App namespace Bit.App
{ {
@ -33,9 +35,9 @@ namespace Bit.App
{ {
if(Device.OS == TargetPlatform.Android) if(Device.OS == TargetPlatform.Android)
{ {
System.Threading.Tasks.Task.Run(async () => Task.Run(async () =>
{ {
await System.Threading.Tasks.Task.Delay(delay); await Task.Delay(delay);
Device.BeginInvokeOnMainThread(() => entry.Focus()); Device.BeginInvokeOnMainThread(() => entry.Focus());
}); });
} }
@ -45,6 +47,30 @@ namespace Bit.App
} }
} }
public static async Task PushForDeviceAsync(this INavigation navigation, Page page)
{
if(Device.OS == TargetPlatform.iOS)
{
await navigation.PushModalAsync(new ExtendedNavigationPage(page), true);
}
else
{
await navigation.PushAsync(page, true);
}
}
public static async Task PopForDeviceAsync(this INavigation navigation)
{
if(Device.OS == TargetPlatform.iOS)
{
await navigation.PopModalAsync(true);
}
else
{
await navigation.PopAsync(true);
}
}
public static void AdjustMarginsForDevice(this View view) public static void AdjustMarginsForDevice(this View view)
{ {
if(Device.OS == TargetPlatform.Android) if(Device.OS == TargetPlatform.Android)