Skip to content

Add support for a container view#1025

Merged
jsuarezruiz merged 21 commits into
mainfrom
dev/container-view
May 20, 2021
Merged

Add support for a container view#1025
jsuarezruiz merged 21 commits into
mainfrom
dev/container-view

Conversation

@mattleibow

@mattleibow mattleibow commented May 13, 2021

Copy link
Copy Markdown
Member

Description of Change

Many controls are "missing" features, so we have to wrap them into a container view that can support them.

This might be backgrounds on labels, clipping on unclippable views or even just a way to get a feature that can't work properly on the native view - such as gestures.

Additions made

  • Adds object? IViewHandler.ContainerView { get; }
  • Adds NativeView? INativeViewHandler.ContainerView { get; }
  • Adds object? ViewHandler.NeedsContainer { get; }
  • Adds WrapperView : NativeView

PR Checklist

  • Targets the correct branch
  • Tests are passing (or failures are unrelated)
  • Targets a single property for a single control (or intertwined few properties)
  • Adds the property to the appropriate interface
  • Avoids any changes not essential to the handler property
  • Adds the mapping to the PropertyMapper in the handler
  • Adds the mapping method to the Android, iOS, and Standard aspects of the handler
  • Implements the actual property updates (usually in extension methods in the Platform section of Core)
  • Tags ported renderer methods with [PortHandler]
  • Adds an example of the property to the sample project (MainPage)
  • Adds the property to the stub class
  • Implements basic property tests in DeviceTests

Does this PR touch anything that might affect accessibility?

  • Does this PR introduce a new control? (If yes, add an example using SemanticProperties to the SemanticsPage)
  • APIs that modify focusability?
  • APIs that modify any text property on a control?
  • Does this PR modify view nesting or view arrangement in anyway?
  • Is there the smallest possibility that your PR will change accessibility?
  • I'm not sure, please help me

If any of the above checkboxes apply to your PR, then the PR will need to provide testing to demonstrate that accessibility still works.

{
new AView? NativeView { get; }

new AView? ContainerView { get; }

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this should be on the interface.

Actions =
{
[nameof(IFrameworkElement.InvalidateMeasure)] = MapInvalidateMeasure,
[nameof(ViewHandler.NeedsContainer)] = MapNeedsContainer,

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an action that can be fired from within the handler to update the HasContainer.

Comment thread src/Core/src/Handlers/View/ViewHandler.cs
Comment thread src/Core/src/Handlers/View/ViewHandlerOfT.iOS.cs
Comment thread src/Core/src/Handlers/Image/ImageHandler.Windows.cs
Comment on lines +14 to +16
public override bool NeedsContainer =>
VirtualView?.BackgroundColor != null ||
base.NeedsContainer;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also have to override the NeedsContainer property to control whether or not the handler is using a container or not.

Comment on lines +41 to +46
public static void MapBackgroundColor(ImageHandler handler, IImage image)
{
handler.UpdateValue(nameof(IViewHandler.ContainerView));

handler.ContainerView?.UpdateBackgroundColor(image);
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But, as a result, all the properties that need to work on the container are now redirected to the container instead of the default version that used the NativeView. In addition, we also have to let the handler know that how we might be changing the container, so first fire that and then we will have the container view to use.

I somehow feel that this could be changed... I was thinking that if the view has a container, then the base ViewHandler would use that for all the properties - for example: enabled, a11y, width, height - but this now means that if I add a background to my view, all the properties will need to be set on the new container and unset on the view. And it may be the case that setting a a11y property on a button handles differently when set on a border that contains a button. So for now, overriding the specific properties that need the container is not too bad. Maybe we need a way to mark properties (per handler) as a "this is a container property" and then if any of those are set the handler automatically creates a container.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For A11y, there is accessibilityTraits on iOS and I don't think there is an equivalent concept for Android. For width and height, the container view should always be the same as the child view, no?

Comment on lines +13 to +15
#if WINDOWS
[nameof(ILabel.BackgroundColor)] = MapBackgroundColor,
#endif

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what is needed now.

# Conflicts:
#	src/Core/src/Handlers/Label/LabelHandler.cs
#	src/Core/src/Platform/iOS/ViewExtensions.cs
Comment thread src/Controls/samples/Controls.Sample.Droid/MainApplication.cs Outdated
Comment thread src/Core/src/Handlers/Image/ImageHandler.Windows.cs
Comment thread src/Core/src/Handlers/View/ViewHandler.cs

protected View? WrappedNativeView => ContainerView ?? (View?)NativeView;

public new WrapperView? ContainerView

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if, we rename ContainerView (currently used by Hot Reload) to ReloadableView and keep ContainerView for the Wrapper?


DefaultTextColors = nativeView.TextColors;
DefaultPlaceholderTextColors = nativeView.HintTextColors;
DefaultBackground = nativeView.Background;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add a handler test in these cases with custom code to assign the Background?

@jsuarezruiz jsuarezruiz merged commit 4c33bd8 into main May 20, 2021
@jsuarezruiz jsuarezruiz deleted the dev/container-view branch May 20, 2021 10:51
@ghost ghost added the legacy-area-controls Label, Button, CheckBox, Slider, Stepper, Switch, Picker, Entry, Editor label Jul 11, 2023
@github-actions github-actions Bot locked and limited conversation to collaborators Dec 26, 2023
@Eilon Eilon removed legacy-area-controls Label, Button, CheckBox, Slider, Stepper, Switch, Picker, Entry, Editor area-image Image loading, sources, caching labels May 10, 2024
@samhouts samhouts added the fixed-in-6.0.100-preview.5 Look for this fix in 6.0.100-preview.5! label Aug 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants