1
0
mirror of https://github.com/bitwarden/mobile.git synced 2024-11-22 11:35:21 +01:00

Expand Settings TimePicker tap recognition to entire row (#1714)

* move timepicker to separate DataTemplate
- activate timepicker when selecting row

* null check on TimePicker
This commit is contained in:
Jake Fink 2022-01-24 15:21:52 -05:00 committed by GitHub
parent 74e90da662
commit f1ccbbc105
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 54 additions and 7 deletions

View File

@ -45,20 +45,47 @@
VerticalOptions="CenterAndExpand"
TextColor="{Binding SubLabelColor}"
StyleClass="list-sub" />
<TimePicker IsVisible="{Binding ShowTimeInput}"
Time="{Binding Time}" Format="HH:mm"
</controls:ExtendedStackLayout>
</DataTemplate>
<DataTemplate
x:Key="timePickerTemplate"
x:DataType="pages:SettingsPageListItem">
<controls:ExtendedStackLayout Orientation="Horizontal"
StyleClass="list-row, list-row-platform">
<Frame
IsVisible="{Binding UseFrame}"
Padding="10"
HasShadow="False"
BackgroundColor="Transparent"
BorderColor="Accent">
<Label
Text="{Binding Name, Mode=OneWay}"
StyleClass="text-muted, text-sm, text-bold"
HorizontalTextAlignment="Center" />
</Frame>
<Label IsVisible="{Binding UseFrame, Converter={StaticResource inverseBool}}"
Text="{Binding Name, Mode=OneWay}"
LineBreakMode="{Binding LineBreakMode}"
HorizontalOptions="StartAndExpand"
VerticalOptions="CenterAndExpand"
StyleClass="list-title"/>
<TimePicker Time="{Binding Time}" Format="HH:mm"
PropertyChanged="OnTimePickerPropertyChanged"
HorizontalOptions="End"
VerticalOptions="Center"
FontSize="Small"
TextColor="{Binding SubLabelColor}"
StyleClass="list-sub" Margin="-5" />
StyleClass="list-sub" Margin="-5"/>
<controls:ExtendedStackLayout.GestureRecognizers>
<TapGestureRecognizer Tapped="ActivateTimePicker"/>
</controls:ExtendedStackLayout.GestureRecognizers>
</controls:ExtendedStackLayout>
</DataTemplate>
</DataTemplate>
<pages:SettingsPageListItemSelector
x:Key="listItemDataTemplateSelector"
RegularTemplate="{StaticResource regularTemplate}" />
RegularTemplate="{StaticResource regularTemplate}"
TimePickerTemplate="{StaticResource timePickerTemplate}" />
</ResourceDictionary>
</ContentPage.Resources>

View File

@ -1,4 +1,5 @@
using System.ComponentModel;
using System;
using System.ComponentModel;
using System.Linq;
using System.Threading.Tasks;
using Bit.App.Abstractions;
@ -45,6 +46,17 @@ namespace Bit.App.Pages
return base.OnBackButtonPressed();
}
void ActivateTimePicker(object sender, EventArgs args)
{
var stackLayout = (ExtendedStackLayout)sender;
SettingsPageListItem item = (SettingsPageListItem)stackLayout.BindingContext;
if (item.ShowTimeInput)
{
var timePicker = stackLayout.Children.Where(x => x is TimePicker).FirstOrDefault();
((TimePicker)timePicker)?.Focus();
}
}
async void OnTimePickerPropertyChanged(object sender, PropertyChangedEventArgs args)
{
var s = (TimePicker) sender;

View File

@ -5,12 +5,20 @@ namespace Bit.App.Pages
public class SettingsPageListItemSelector : DataTemplateSelector
{
public DataTemplate RegularTemplate { get; set; }
public DataTemplate TimePickerTemplate { get; set; }
protected override DataTemplate OnSelectTemplate(object item, BindableObject container)
{
if (item is SettingsPageListItem listItem)
{
return RegularTemplate;
if (listItem.ShowTimeInput)
{
return TimePickerTemplate;
}
else
{
return RegularTemplate;
}
}
return null;
}