microsoft / microsoft/react-native-windows

I shouldn't have to prepend my eventnames with "top"

Open
#4,206 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Documentation enhancement Workstream: Developer Experience
Dominant language
C++
Stars
17.3k
Forks
1.2k
Avg merge
1d 13h
Merged PRs (30d)
33

Description

ConstantProviderDelegate SomeViewManager::ExportedCustomDirectEventTypeConstants() noexcept
{
    return [](winrt::Microsoft::ReactNative::IJSValueWriter const& constantWriter) {
        WriteCustomDirectEventTypeConstant(constantWriter, "Foo");
}
...
 ReactContext().DispatchEvent(someView, L"topFoo", args);

Most of our code is built around some constants in the class (e.g. SomeViewManager::Foo) instead of using literals everywhere.
Which means I need to do things like
winrt::to_hstring(std::string("top") + eventName);

It used to work without having to manually add "top", the internal DispatchEvent should handle these types of things or have appropriate functions to call like DispatchTopEvent

Even in the SampleApp
they are using "topLabelChanged" and "LabelChanged"

Also in places like this

https://github.com/react-native-community/react-native-video/blob/91384d848953d8c8b526a10f45d44f1bd38c62f0/windows/ReactNativeVideoCPP/ReactVideoView.cpp#L103
where Load, End, Seek, Progress were the registered names, but then someone had to fire "topLoad", "topEnd", "topSeek", and "topProgress"

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading ExportedCustomDirectEventTypeConstants and the ReactContext().DispatchEvent call shown in the issue, then compare the registered names with the SampleApp examples and ReactVideoView.cpp. Done means native event dispatch no longer requires callers to manually prepend "top" to registered event names, with the affected event behavior covered by the repository's tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, react-native
Domain
api
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.