Skip to content
Merged
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
29 changes: 29 additions & 0 deletions src/Controls/src/Core/Entry/Entry.Android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,34 @@ public static void MapText(IEntryHandler handler, Entry entry)

Platform.EditTextExtensions.UpdateText(handler.PlatformView, entry);
}

// TODO: Material3: Make it public in .NET 11
// MaterialEntryHandler-specific overloads
internal static void MapImeOptions(EntryHandler2 handler, Entry entry)
{
if (handler.PlatformView?.EditText is null)
{
return;
}

Platform.EditTextExtensions.UpdateImeOptions(handler.PlatformView.EditText, entry);
}

// TODO: Material3: Make it public in .NET 11
internal static void MapText(EntryHandler2 handler, Entry entry)
{
if (handler.PlatformView?.EditText is null)
{
return;
}

if (handler.DataFlowDirection == DataFlowDirection.FromPlatform)
{
Platform.EditTextExtensions.UpdateTextFromPlatform(handler.PlatformView.EditText, entry);
return;
}

Platform.EditTextExtensions.UpdateText(handler.PlatformView.EditText, entry);
}
}
}
13 changes: 13 additions & 0 deletions src/Controls/src/Core/Entry/Entry.Mapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,19 @@ public partial class Entry
EntryHandler.Mapper.ReplaceMapping<Entry, IEntryHandler>(nameof(Text), MapText);
EntryHandler.Mapper.ReplaceMapping<Entry, IEntryHandler>(nameof(TextTransform), MapText);

// Material3 Entry Handler mappings
#if ANDROID
if (RuntimeFeature.IsMaterial3Enabled)
{
EntryHandler2.Mapper.ReplaceMapping<Entry, EntryHandler2>(PlatformConfiguration.AndroidSpecific.Entry.ImeOptionsProperty.PropertyName, MapImeOptions);
EntryHandler2.Mapper.ReplaceMapping<Entry, EntryHandler2>(nameof(Text), MapText);
EntryHandler2.Mapper.ReplaceMapping<Entry, EntryHandler2>(nameof(TextTransform), MapText);
Comment thread
HarishwaranVijayakumar marked this conversation as resolved.
Comment thread
HarishwaranVijayakumar marked this conversation as resolved.
EntryHandler2.Mapper.AppendToMapping(nameof(VisualElement.IsFocused), InputView.MapIsFocused);
Comment thread
HarishwaranVijayakumar marked this conversation as resolved.
EntryHandler2.Mapper.AppendToMapping(nameof(VisualElement.IsVisible), InputView.MapIsVisible);
EntryHandler2.CommandMapper.PrependToMapping(nameof(IEntry.Focus), InputView.MapFocus);
}
#endif

#if IOS || ANDROID
EntryHandler.Mapper.AppendToMapping(nameof(VisualElement.IsFocused), InputView.MapIsFocused);
EntryHandler.Mapper.AppendToMapping(nameof(VisualElement.IsVisible), InputView.MapIsVisible);
Expand Down
4 changes: 3 additions & 1 deletion src/Controls/src/Core/Hosting/AppHostBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ internal static IMauiHandlersCollection AddControlsHandlers(this IMauiHandlersCo
handlersCollection.AddHandler<SearchBar, SearchBarHandler2>();
handlersCollection.AddHandler<Slider, SliderHandler2>();
handlersCollection.AddHandler<DatePicker, DatePickerHandler2>();
handlersCollection.AddHandler<Entry, EntryHandler2>();
}
else
{
Expand All @@ -100,6 +101,7 @@ internal static IMauiHandlersCollection AddControlsHandlers(this IMauiHandlersCo
handlersCollection.AddHandler<SearchBar, SearchBarHandler>();
handlersCollection.AddHandler<Slider, SliderHandler>();
handlersCollection.AddHandler<DatePicker, DatePickerHandler>();
handlersCollection.AddHandler<Entry, EntryHandler>();
}
#else
handlersCollection.AddHandler<Label, LabelHandler>();
Expand All @@ -114,11 +116,11 @@ internal static IMauiHandlersCollection AddControlsHandlers(this IMauiHandlersCo
handlersCollection.AddHandler<SearchBar, SearchBarHandler>();
handlersCollection.AddHandler<Slider, SliderHandler>();
handlersCollection.AddHandler<DatePicker, DatePickerHandler>();
handlersCollection.AddHandler<Entry, EntryHandler>();
#endif
handlersCollection.AddHandler<Application, ApplicationHandler>();
handlersCollection.AddHandler<BoxView, BoxViewHandler>();
handlersCollection.AddHandler<Button, ButtonHandler>();
handlersCollection.AddHandler<Entry, EntryHandler>();
handlersCollection.AddHandler<GraphicsView, GraphicsViewHandler>();
handlersCollection.AddHandler<Layout, LayoutHandler>();
handlersCollection.AddHandler<ScrollView, ScrollViewHandler>();
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public override string ToString()
new GalleryPageFactory(() => new LabelControlPage(), "Label Feature Matrix"),
new GalleryPageFactory(() => new CarouselViewFeaturePage(), "CarouselView Feature Matrix"),
new GalleryPageFactory(() => new EntryControlPage(), "Entry Feature Matrix"),
new GalleryPageFactory(() => new Material3_EntryControlPage(), "Entry Material3 Feature Matrix"),
new GalleryPageFactory(() => new ImageControlPage(), "Image Feature Matrix"),
new GalleryPageFactory(() => new ImageButtonControlPage(), "ImageButton Feature Matrix"),
new GalleryPageFactory(() => new BoxViewControlPage(), "BoxView Feature Matrix"),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:Maui.Controls.Sample"
x:DataType="local:EntryViewModel"
SafeAreaEdges="Container"
x:Class="Maui.Controls.Sample.Material3_EntryControlMainPage">
<ContentPage.ToolbarItems>
<ToolbarItem Text="Options"
Clicked="NavigateToOptionsPage_Clicked"
AutomationId="Options"/>
</ContentPage.ToolbarItems>

<VerticalStackLayout Padding="20"
Spacing="8">
<Label Text="Material3 Entry Control"
FontSize="20"
Margin="0,0,0,50"
HorizontalOptions="Center"/>

<Entry x:Name="EntryControl"
Text="{Binding Text}"
Placeholder="{Binding Placeholder}"
PlaceholderColor="{Binding PlaceholderColor}"
TextColor="{Binding TextColor}"
ClearButtonVisibility="{Binding ClearButtonVisibility}"
HorizontalTextAlignment="{Binding HorizontalTextAlignment}"
VerticalTextAlignment="{Binding VerticalTextAlignment}"
IsPassword="{Binding IsPassword}"
FontSize="{Binding FontSize}"
CharacterSpacing="{Binding CharacterSpacing}"
IsReadOnly="{Binding IsReadOnly}"
IsTextPredictionEnabled="{Binding IsTextPredictionEnabled}"
IsSpellCheckEnabled="{Binding IsSpellCheckEnabled}"
Shadow="{Binding EntryShadow}"
MaxLength="{Binding MaxLength}"
SelectionLength="{Binding SelectionLength}"
CursorPosition="{Binding CursorPosition, Mode=TwoWay}"
ReturnType="{Binding ReturnType}"
ReturnCommand="{Binding ReturnCommand}"
ReturnCommandParameter="{Binding Text}"
Keyboard="{Binding Keyboard}"
FontFamily="{Binding FontFamily}"
IsVisible="{Binding IsVisible}"
IsEnabled="{Binding IsEnabled}"
FlowDirection="{Binding FlowDirection}"
HeightRequest="{Binding HeightRequest}"
FontAttributes="{Binding FontAttributes}"
TextTransform="{Binding TextTransform}"
TextChanged="EntryControl_TextChanged"
Completed="EntryControl_Completed"
Focused="EntryControl_Focused"
Unfocused="EntryControl_Unfocused"
AutomationId="TestEntry"/>

<Grid HeightRequest="130"/>

<Grid ColumnSpacing="10"
Margin="0,10,0,10">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>

<Label Text="Selection Length:"
FontSize="11"
Grid.Row="0"
Grid.Column="0"/>
<Label Text="Cursor position:"
FontSize="11"
Grid.Row="0"
Grid.Column="1"/>

<local:UITestEntry x:Name="SelectionLengthEntry"
Text="{Binding SelectionLength}"
AutomationId="SelectionLengthEntry"
IsCursorVisible="False"
TextChanged="SelectionLength_Clicked"
Grid.Row="1"
Grid.Column="0"/>
<local:UITestEntry x:Name="CursorPositionEntry"
Text="{Binding CursorPosition}"
AutomationId="CursorPositionEntry"
IsCursorVisible="False"
Grid.Row="1"
Grid.Column="1"/>
</Grid>

<Button Text="Update Cursor Selection"
FontSize="11"
Clicked="OnUpdateCursorAndSelectionClicked"
AutomationId="UpdateCursorAndSelectionButton"/>

<Label Text="Events:"
FontSize="11"/>
<Label x:Name="TextChangedLabel"
Text="{Binding TextChangedText}"
AutomationId="TextChangedLabel"
FontSize="11"/>
<Label x:Name="CompletedLabel"
Text="{Binding CompletedText}"
AutomationId="CompletedLabel"
FontSize="11"/>
<Label x:Name="FocusedLabel"
Text="{Binding FocusedText}"
AutomationId="FocusedLabel"
FontSize="11"/>
<Label x:Name="UnfocusedLabel"
Text="{Binding UnfocusedText}"
AutomationId="UnfocusedLabel"
FontSize="11"/>
</VerticalStackLayout>
</ContentPage>
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
using System.ComponentModel;
using Microsoft.Maui.Controls;

namespace Maui.Controls.Sample;

public class Material3_EntryControlPage : NavigationPage
{
EntryViewModel _viewModel;

public Material3_EntryControlPage()
{
_viewModel = new EntryViewModel();
PushAsync(new Material3_EntryControlMainPage(_viewModel));
}
}

public partial class Material3_EntryControlMainPage : ContentPage
{
EntryViewModel _viewModel;

public Material3_EntryControlMainPage(EntryViewModel viewModel)
{
InitializeComponent();
_viewModel = viewModel;
BindingContext = _viewModel;
EntryControl.PropertyChanged += UpdateEntryControl;
}

async void NavigateToOptionsPage_Clicked(object sender, EventArgs e)
{
BindingContext = _viewModel = new EntryViewModel();
_viewModel.Text = "Test Entry";
_viewModel.Placeholder = "Enter text here";
_viewModel.CursorPosition = 0;
_viewModel.SelectionLength = 0;
await Navigation.PushAsync(new EntryOptionsPage(_viewModel));
}

void CursorPositionButton_Clicked(object sender, EventArgs e)
{
if (int.TryParse(CursorPositionEntry.Text, out int cursorPosition))
{
_viewModel.CursorPosition = cursorPosition;
}
}

void SelectionLength_Clicked(object sender, EventArgs e)
{
if (int.TryParse(SelectionLengthEntry.Text, out int selectionLength))
{
_viewModel.SelectionLength = selectionLength;
}
}

void OnUpdateCursorAndSelectionClicked(object sender, EventArgs e)
{
if (int.TryParse(CursorPositionEntry.Text, out int cursorPosition))
{
EntryControl.Focus();
EntryControl.CursorPosition = cursorPosition;

if (BindingContext is EntryViewModel vm)
vm.CursorPosition = cursorPosition;
}

if (int.TryParse(SelectionLengthEntry.Text, out int selectionLength))
{
EntryControl.Focus();
EntryControl.SelectionLength = selectionLength;

if (BindingContext is EntryViewModel vm)
vm.SelectionLength = selectionLength;
}
CursorPositionEntry.Text = EntryControl.CursorPosition.ToString();
SelectionLengthEntry.Text = EntryControl.SelectionLength.ToString();
}

void UpdateEntryControl(object sender, PropertyChangedEventArgs args)
{
if (args.PropertyName == Entry.CursorPositionProperty.PropertyName)
CursorPositionEntry.Text = EntryControl.CursorPosition.ToString();
else if (args.PropertyName == Entry.SelectionLengthProperty.PropertyName)
SelectionLengthEntry.Text = EntryControl.SelectionLength.ToString();
}

void EntryControl_TextChanged(object sender, TextChangedEventArgs e)
{
string eventInfo = $"TextChanged: Old='{e.OldTextValue}', New='{e.NewTextValue}'";

if (BindingContext is EntryViewModel vm)
{
vm.TextChangedText = eventInfo;
}
}

void EntryControl_Completed(object sender, EventArgs e)
{
string eventInfo = $"Completed: Event Triggered";

if (BindingContext is EntryViewModel vm)
{
vm.CompletedText = eventInfo;
}
}

void EntryControl_Focused(object sender, FocusEventArgs e)
{
string eventInfo = $"Focused: Event Triggered";

if (BindingContext is EntryViewModel vm)
{
vm.FocusedText = eventInfo;
}
}

void EntryControl_Unfocused(object sender, FocusEventArgs e)
{
string eventInfo = $"Unfocused: Event Triggered";

if (BindingContext is EntryViewModel vm)
{
vm.UnfocusedText = eventInfo;
}
}
}
Loading
Loading