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
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,9 @@ void Destroy()
{
if (_destroyed)
return;

_destroyed = true;

// If the user taps very quickly on back button multiple times to pop a page,
// the app enters background state in the middle of the animation causing the fragment to be destroyed without completing the animation.
// That'll cause `IAnimationListener.onAnimationEnd` to not be called, so we need to call it manually if something is still subscribed to the event
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ public async Task ShellContentFragmentDestroyHandlesNullShellContext()
},
new ShellContent()
{
Route = "Item2",
Route = "Item2",
Content = new ContentPage { Title = "Page 2" }
},
}
Expand All @@ -555,12 +555,12 @@ await CreateHandlerAndAddToWindow<ShellHandler>(shell, async (handler) =>
await OnNavigatedToAsync(shell.CurrentPage);

// Test null context scenario
var exception = Record.Exception(() =>
var exception = Record.Exception(() =>
{
// Create fragment with null context - this should not throw
Page page = new ContentPage();
var fragment = new ShellContentFragment((IShellContext)null, page);

// Dispose the fragment which calls Destroy internally
// This validates the null-conditional operators in Destroy method
fragment.Dispose();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,123 +5,123 @@ namespace Maui.Controls.Sample;

public class EditorControlPage : NavigationPage
{
private EditorViewModel _viewModel;
private EditorViewModel _viewModel;

public EditorControlPage()
{
_viewModel = new EditorViewModel();
PushAsync(new EditorControlMainPage(_viewModel));
}
public EditorControlPage()
{
_viewModel = new EditorViewModel();
PushAsync(new EditorControlMainPage(_viewModel));
}
}

public partial class EditorControlMainPage : ContentPage
{
private EditorViewModel _viewModel;

public EditorControlMainPage(EditorViewModel viewModel)
{
InitializeComponent();
_viewModel = viewModel;
BindingContext = _viewModel;
EditorControl.PropertyChanged += UpdateEditorControl;
}

private async void NavigateToOptionsPage_Clicked(object sender, EventArgs e)
{
BindingContext = _viewModel = new EditorViewModel();
_viewModel.Text = "Test Editor";
_viewModel.Placeholder = "Enter text here";
_viewModel.VerticalTextAlignment = TextAlignment.End;
_viewModel.CursorPosition = 0;
_viewModel.SelectionLength = 0;
_viewModel.HeightRequest = -1;
await Navigation.PushAsync(new EditorOptionsPage(_viewModel));
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

if (BindingContext is EditorViewModel vm)
{
vm.UnfocusedText = eventInfo;
}
}
private EditorViewModel _viewModel;

public EditorControlMainPage(EditorViewModel viewModel)
{
InitializeComponent();
_viewModel = viewModel;
BindingContext = _viewModel;
EditorControl.PropertyChanged += UpdateEditorControl;
}

private async void NavigateToOptionsPage_Clicked(object sender, EventArgs e)
{
BindingContext = _viewModel = new EditorViewModel();
_viewModel.Text = "Test Editor";
_viewModel.Placeholder = "Enter text here";
_viewModel.VerticalTextAlignment = TextAlignment.End;
_viewModel.CursorPosition = 0;
_viewModel.SelectionLength = 0;
_viewModel.HeightRequest = -1;
await Navigation.PushAsync(new EditorOptionsPage(_viewModel));
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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