hide keydown/keyup since they're pre-registered as bubbling by the framework

This commit is contained in:
Alexander Sklar 2021-02-25 04:34:01 -08:00
Родитель ac24380ae1
Коммит 12bd5ace87
3 изменённых файлов: 11 добавлений и 24 удалений

Просмотреть файл

@ -109,7 +109,7 @@ class Program
var propsToAdd = type.GetProperties().Where(p => Util.ShouldEmitPropertyMetadata(p));
properties.AddRange(propsToAdd);
var eventsToAdd = type.GetEvents().Where(e => e.GetMemberModifiers().IsPublic);
var eventsToAdd = type.GetEvents().Where(e => Util.ShouldEmitEventMetadata(e));
events.AddRange(eventsToAdd);
}

Просмотреть файл

@ -122,6 +122,15 @@ namespace Codegen
}
}
public static bool ShouldEmitEventMetadata(MrEvent e)
{
// KeyboardEventHandler already registers these events as bubbling
// we currently register all events as direct, so this causes a conflict (can't be registered as both bubbling and direct) for these two events;
// so hide them for now
var bannedEvents = new string[] { "KeyDown", "KeyUp" };
return e.GetMemberModifiers().IsPublic && !bannedEvents.Contains(e.GetName());
}
public static bool HasCtor(MrType t)
{
t.GetMethodsAndConstructors(out var methods, out var ctors);

Просмотреть файл

@ -95,28 +95,6 @@ void SerializeEventArgs(winrt::Microsoft::ReactNative::IJSValueWriter const& wri
});
}
} },
{"KeyDown", [](winrt::Windows::Foundation::IInspectable o, IReactContext reactContext) {
if (auto c = o.try_as<winrt::Windows::UI::Xaml::UIElement>()) {
c.KeyDown([reactContext] (const winrt::Windows::Foundation::IInspectable& sender, const winrt::Windows::UI::Xaml::Input::KeyRoutedEventArgs& args) {
if (auto fe = sender ? sender.try_as<xaml::FrameworkElement>() : nullptr) {
reactContext.DispatchEvent(fe, L"topKeyDown", [args](winrt::Microsoft::ReactNative::IJSValueWriter const& evtDataWriter) noexcept {
SerializeEventArgs(evtDataWriter, args);
});
}
});
}
} },
{"KeyUp", [](winrt::Windows::Foundation::IInspectable o, IReactContext reactContext) {
if (auto c = o.try_as<winrt::Windows::UI::Xaml::UIElement>()) {
c.KeyUp([reactContext] (const winrt::Windows::Foundation::IInspectable& sender, const winrt::Windows::UI::Xaml::Input::KeyRoutedEventArgs& args) {
if (auto fe = sender ? sender.try_as<xaml::FrameworkElement>() : nullptr) {
reactContext.DispatchEvent(fe, L"topKeyUp", [args](winrt::Microsoft::ReactNative::IJSValueWriter const& evtDataWriter) noexcept {
SerializeEventArgs(evtDataWriter, args);
});
}
});
}
} },
{"LostFocus", [](winrt::Windows::Foundation::IInspectable o, IReactContext reactContext) {
if (auto c = o.try_as<winrt::Windows::UI::Xaml::UIElement>()) {
c.LostFocus([reactContext] (const winrt::Windows::Foundation::IInspectable& sender, const winrt::Windows::UI::Xaml::RoutedEventArgs& args) {
@ -2925,7 +2903,7 @@ void SerializeEventArgs(winrt::Microsoft::ReactNative::IJSValueWriter const& wri
};
static_assert(ARRAYSIZE(EventInfo::xamlEventMap) == 264);
static_assert(ARRAYSIZE(EventInfo::xamlEventMap) == 262);
void JsEvent(winrt::Microsoft::ReactNative::IJSValueWriter const& constantWriter, std::wstring topName, std::wstring onName) {
constantWriter.WritePropertyName(topName);