Maui
Maui copied to clipboard
[Proposal] SelectAllTextEffect
SelectAllTextEffect
- [x] Proposed
- [x] Prototype
- [x] Implementation
- [x] iOS Support
- [x] Android Support
- [x] macOS Support
- [x] Windows Support
- [ ] Unit Tests: Not Started
- [x] Sample
- [ ] Documentation: Not Started
Summary
Highlights all text when an InputView is selected
Detailed Design
SelectAllTextEffect.shared.cs
public class SelectAllTextEffect : RoutingEffect
{
}
SelectAllTextEffect.android.cs
public class SelectAllTextEffect : PlatformEffect
{
EditText EditText => (EditText)Control;
protected override void OnAttached() => EditText?.SetSelectAllOnFocus(true);
protected override void OnDetached() => EditText?.SetSelectAllOnFocus(false);
}
SelectAllTextEffect.ios.cs
public class SelectAllTextEffect : PlatformEffect
{
protected override void OnAttached() => ApplyEffect(true);
protected override void OnDetached() => ApplyEffect(false);
void ApplyEffect(bool apply) => ApplyToControl(Control, apply);
bool ApplyToControl<T>(T controlType, bool apply) => controlType switch
{
UITextField textField => ApplyToUITextField(textField, apply),
UITextView => ApplyToUITextView(apply),
_ => throw new NotSupportedException($"Control of type: {controlType?.GetType()?.Name} is not supported by this effect.")
};
}
Usage Syntax
Blocked. Pending the result of https://github.com/CommunityToolkit/Maui/issues/124
Will review this point in a .NET MAUI team meeting next week and after that, we can validate this proposal!
I'll use this one to draw the API to implement our Effects as Behavior and after that go through all other Effects and see if it makes sense for all.
As we discussed on the last CommunityStandup
Reopening Proposal.
Only Proposals moved to the Closed Project Column and Completed Project Column can be closed.
@brminnick, @pictos seems like it can be closed as completed. any objections?