Skip to content

Support custom native components that are not FrameworkElement #5539

Closed as not planned
@aschultz

Description

@aschultz

Summary

Microsoft.ReactNative exposes the IViewManager interface to enable export of custom native UI components into the React environment. However, the interface has the notable restriction that the views it creates and manages must be based on FrameworkElement. This prevents its use with a number of unique XAML elements, such as those derived from TextElement or FlyoutBase.

The IViewManager interfaces should instead use DependencyObject as the common "view" type.

Example

I wish to create a block of text with a stylized and clickable inline link embedded in it. My React might look like:

render() {
    return <Text>This sentence includes a <Link url={...}>link</Link></Text>
}

Here the Text element is built-in to RNW as a XAML TextBlock control. The Link element would ideally be a XAML Hyperlink element that gets added as a child. Since Link is not built-in to RNW, we might create a custom view manager to provide this functionality. However, Hyperlink is not derived from FrameworkElement, so we cannot currently surface it through an IViewManager implementation.

Details

Some of the changes I expect will be needed:

  • IViewManager, IReactContext, and XamlUIService should switch to using DependencyObject instead of FrameworkElement/UIElement
  • ABIViewManager stops deriving from FrameworkViewManager and instead applies base logic depending on the views being managed.
    • View managers for FrameworkElement-derived views should get access to the same rich defaults as before (handling of layout, accessibility, and input event props).
    • View managers for other views should probably be marked as not affecting layout. FlyoutBase may need a special case here that allows it to register and host a root Yoga node.
  • Address RNW shouldn't use Tag property internally. #4187, as Tag is specific to FrameworkElement

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions