Wrapper should not be bindable

This commit is contained in:
Alexander Sklar 2021-07-17 00:29:09 -07:00
Родитель 57a51c1028
Коммит 2d49fd6cea
3 изменённых файлов: 11 добавлений и 5 удалений

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

@ -2,7 +2,6 @@
namespace ReactNativeXaml
{
[bindable]
[default_interface]
runtimeclass Wrapper : XAML_NAMESPACE.FrameworkElement
{

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

@ -19,6 +19,7 @@
#include "Styling.h"
namespace jsi = facebook::jsi;
using namespace winrt::Microsoft::ReactNative;
@ -50,8 +51,9 @@ FrameworkElement Wrap(const winrt::Windows::Foundation::IInspectable& d) {
return fe;
}
else {
winrt::ReactNativeXaml::Wrapper wrapper;
winrt::ReactNativeXaml::Wrapper wrapper{};
wrapper.WrappedObject(d);
return wrapper;
}
}
@ -73,6 +75,10 @@ winrt::Windows::Foundation::IInspectable XamlMetadata::Create(const std::string&
return e;
}
FrameworkElement GetDataContext_Flyout(winrt::Windows::Foundation::IInspectable wrapper) {
return wrapper.as<winrt::ReactNativeXaml::Wrapper>().DataContext().as<xaml::FrameworkElement>();
}
// FlyoutBase.IsOpen is read-only but we need a way to call ShowAt/Hide, so this hooks it up
void SetIsOpen_FlyoutBase(const xaml::DependencyObject& o, const xaml::DependencyProperty&, const winrt::Microsoft::ReactNative::JSValue& v, const winrt::Microsoft::ReactNative::IReactContext&) {
auto flyout = o.try_as<Controls::Primitives::FlyoutBase>();
@ -82,7 +88,7 @@ void SetIsOpen_FlyoutBase(const xaml::DependencyObject& o, const xaml::Dependenc
// Go from the wrapping ContentControl to the flyout's parent.
// We can't use Parent() since we unparent the CC once we add the flyout to the tree
if (!target) target = o.as<winrt::ReactNativeXaml::Wrapper>().DataContext().as<FrameworkElement>();
if (!target) target = GetDataContext_Flyout(o);
auto cn = winrt::get_class_name(target);
flyout.ShowAt(target);
}

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

@ -138,7 +138,8 @@ namespace winrt::ReactNativeXaml {
else if (auto wrappedChild = child.try_as<Wrapper>()) {
if (auto childContent = wrappedChild.WrappedObject()) {
childType = winrt::get_class_name(childContent);
auto tag = wrappedChild.Tag();
auto childFE = child.as<FrameworkElement>();
auto tag = childFE.Tag();
if (auto depObj = childContent.try_as<DependencyObject>()) {
// tranfer the Tag from the wrapping ContentControl
// This is used for dispatching events and TouchEventHandler
@ -147,7 +148,7 @@ namespace winrt::ReactNativeXaml {
if (auto childFlyout = childContent.try_as<Controls::Primitives::FlyoutBase>()) {
Primitives::FlyoutBase::SetAttachedFlyout(e, childFlyout);
wrappedChild.DataContext(e);
childFE.DataContext(e);
if (auto button = e.try_as<Button>()) {
return button.Flyout(childFlyout);
}