Skip to content

Microsoft.ReactNative needs equivalent to ReactUWP FindShadowNodeForTag #4327

@aschultz

Description

@aschultz

Summary

Add a function, possibly to IReactContext, that allows Native Modules to pass in a node id (the value returned by findNodeHandle() in JS) and get access to the corresponding XAML view.

Motivation

Native modules need the ability to find and act upon arbitrary XAML elements. This allows use of native modules to augment existing UI elements.

For example, XAML's UIElement provides the "StartBringIntoView" function that will trigger any containing scroll region to scroll until the element is visible. Rather than updating all existing ViewManagers to include this function, a native module could be written to enable the behavior.

REACT_MODULE(ScrollHelperModule);
class ScrollHelperModule {

    REACT_METHOD(startBringIntoView);
    void startBringIntoView(int nodeHandle) noexcept {
        m_reactInstance->FindViewByHandle(nodeHandle).as<winrt::UIElement>().StartBringIntoView();
    }
}
const ScrollHelper = NativeModules.ScrollHelperModule;

export function startBringIntoView(target: Component) {
    return ScrollHelper.startBringIntoView(findNodeHandle(target));
}

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions