|
| 1 | + |
| 2 | +/* |
| 3 | + * This file is auto-generated from CalendarViewNativeComponent spec file in flow / TypeScript. |
| 4 | + */ |
| 5 | +// clang-format off |
| 6 | +#pragma once |
| 7 | + |
| 8 | +#include <NativeModules.h> |
| 9 | + |
| 10 | +#ifdef RNW_NEW_ARCH |
| 11 | +#include <JSValueComposition.h> |
| 12 | + |
| 13 | +#include <winrt/Microsoft.ReactNative.Composition.h> |
| 14 | +#include <winrt/Microsoft.UI.Composition.h> |
| 15 | +#endif // #ifdef RNW_NEW_ARCH |
| 16 | + |
| 17 | +#ifdef RNW_NEW_ARCH |
| 18 | + |
| 19 | +namespace winrt::SampleCustomComponent::Codegen { |
| 20 | + |
| 21 | +REACT_STRUCT(CalendarViewProps) |
| 22 | +struct CalendarViewProps : winrt::implements<CalendarViewProps, winrt::Microsoft::ReactNative::IComponentProps> { |
| 23 | + CalendarViewProps(winrt::Microsoft::ReactNative::ViewProps props, const winrt::Microsoft::ReactNative::IComponentProps& cloneFrom) |
| 24 | + : ViewProps(props) |
| 25 | + { |
| 26 | + if (cloneFrom) { |
| 27 | + auto cloneFromProps = cloneFrom.as<CalendarViewProps>(); |
| 28 | + label = cloneFromProps->label; |
| 29 | + } |
| 30 | + } |
| 31 | + |
| 32 | + void SetProp(uint32_t hash, winrt::hstring propName, winrt::Microsoft::ReactNative::IJSValueReader value) noexcept { |
| 33 | + winrt::Microsoft::ReactNative::ReadProp(hash, propName, value, *this); |
| 34 | + } |
| 35 | + |
| 36 | + REACT_FIELD(label) |
| 37 | + std::string label; |
| 38 | + |
| 39 | + const winrt::Microsoft::ReactNative::ViewProps ViewProps; |
| 40 | +}; |
| 41 | + |
| 42 | +REACT_STRUCT(CalendarView_OnSelectedDatesChanged) |
| 43 | +struct CalendarView_OnSelectedDatesChanged { |
| 44 | + REACT_FIELD(value) |
| 45 | + bool value{}; |
| 46 | + |
| 47 | + REACT_FIELD(startDate) |
| 48 | + std::string startDate; |
| 49 | +}; |
| 50 | + |
| 51 | +struct CalendarViewEventEmitter { |
| 52 | + CalendarViewEventEmitter(const winrt::Microsoft::ReactNative::EventEmitter &eventEmitter) |
| 53 | + : m_eventEmitter(eventEmitter) {} |
| 54 | + |
| 55 | + using OnSelectedDatesChanged = CalendarView_OnSelectedDatesChanged; |
| 56 | + |
| 57 | + void onSelectedDatesChanged(OnSelectedDatesChanged &value) const { |
| 58 | + m_eventEmitter.DispatchEvent(L"selectedDatesChanged", [value](const winrt::Microsoft::ReactNative::IJSValueWriter writer) { |
| 59 | + winrt::Microsoft::ReactNative::WriteValue(writer, value); |
| 60 | + }); |
| 61 | + } |
| 62 | + |
| 63 | + private: |
| 64 | + winrt::Microsoft::ReactNative::EventEmitter m_eventEmitter{nullptr}; |
| 65 | +}; |
| 66 | + |
| 67 | +template<typename TUserData> |
| 68 | +struct BaseCalendarView { |
| 69 | + |
| 70 | + virtual void UpdateProps( |
| 71 | + const winrt::Microsoft::ReactNative::ComponentView &/*view*/, |
| 72 | + const winrt::com_ptr<CalendarViewProps> &newProps, |
| 73 | + const winrt::com_ptr<CalendarViewProps> &/*oldProps*/) noexcept { |
| 74 | + m_props = newProps; |
| 75 | + } |
| 76 | + |
| 77 | + // UpdateLayoutMetrics will only be called if this method is overridden |
| 78 | + virtual void UpdateLayoutMetrics( |
| 79 | + const winrt::Microsoft::ReactNative::ComponentView &/*view*/, |
| 80 | + const winrt::Microsoft::ReactNative::LayoutMetrics &/*newLayoutMetrics*/, |
| 81 | + const winrt::Microsoft::ReactNative::LayoutMetrics &/*oldLayoutMetrics*/) noexcept { |
| 82 | + } |
| 83 | + |
| 84 | + // UpdateState will only be called if this method is overridden |
| 85 | + virtual void UpdateState( |
| 86 | + const winrt::Microsoft::ReactNative::ComponentView &/*view*/, |
| 87 | + const winrt::Microsoft::ReactNative::IComponentState &/*newState*/) noexcept { |
| 88 | + } |
| 89 | + |
| 90 | + virtual void UpdateEventEmitter(const std::shared_ptr<CalendarViewEventEmitter> &eventEmitter) noexcept { |
| 91 | + m_eventEmitter = eventEmitter; |
| 92 | + } |
| 93 | + |
| 94 | + // MountChildComponentView will only be called if this method is overridden |
| 95 | + virtual void MountChildComponentView(const winrt::Microsoft::ReactNative::ComponentView &/*view*/, |
| 96 | + const winrt::Microsoft::ReactNative::MountChildComponentViewArgs &/*args*/) noexcept { |
| 97 | + } |
| 98 | + |
| 99 | + // UnmountChildComponentView will only be called if this method is overridden |
| 100 | + virtual void UnmountChildComponentView(const winrt::Microsoft::ReactNative::ComponentView &/*view*/, |
| 101 | + const winrt::Microsoft::ReactNative::UnmountChildComponentViewArgs &/*args*/) noexcept { |
| 102 | + } |
| 103 | + |
| 104 | + // Initialize will only be called if this method is overridden |
| 105 | + virtual void Initialize(const winrt::Microsoft::ReactNative::ComponentView &/*view*/) noexcept { |
| 106 | + } |
| 107 | + |
| 108 | + // CreateVisual will only be called if this method is overridden |
| 109 | + virtual winrt::Microsoft::UI::Composition::Visual CreateVisual(const winrt::Microsoft::ReactNative::ComponentView &view) noexcept { |
| 110 | + return view.as<winrt::Microsoft::ReactNative::Composition::ComponentView>().Compositor().CreateSpriteVisual(); |
| 111 | + } |
| 112 | + |
| 113 | + // FinalizeUpdate will only be called if this method is overridden |
| 114 | + virtual void FinalizeUpdate(const winrt::Microsoft::ReactNative::ComponentView &/*view*/, |
| 115 | + winrt::Microsoft::ReactNative::ComponentViewUpdateMask /*mask*/) noexcept { |
| 116 | + } |
| 117 | + |
| 118 | + |
| 119 | + |
| 120 | + const std::shared_ptr<CalendarViewEventEmitter>& EventEmitter() const { return m_eventEmitter; } |
| 121 | + const winrt::com_ptr<CalendarViewProps>& Props() const { return m_props; } |
| 122 | + |
| 123 | +private: |
| 124 | + winrt::com_ptr<CalendarViewProps> m_props; |
| 125 | + std::shared_ptr<CalendarViewEventEmitter> m_eventEmitter; |
| 126 | +}; |
| 127 | + |
| 128 | +template <typename TUserData> |
| 129 | +void RegisterCalendarViewNativeComponent( |
| 130 | + winrt::Microsoft::ReactNative::IReactPackageBuilder const &packageBuilder, |
| 131 | + std::function<void(const winrt::Microsoft::ReactNative::Composition::IReactCompositionViewComponentBuilder&)> builderCallback) noexcept { |
| 132 | + packageBuilder.as<winrt::Microsoft::ReactNative::IReactPackageBuilderFabric>().AddViewComponent( |
| 133 | + L"CalendarView", [builderCallback](winrt::Microsoft::ReactNative::IReactViewComponentBuilder const &builder) noexcept { |
| 134 | + auto compBuilder = builder.as<winrt::Microsoft::ReactNative::Composition::IReactCompositionViewComponentBuilder>(); |
| 135 | + |
| 136 | + builder.SetCreateProps([](winrt::Microsoft::ReactNative::ViewProps props, |
| 137 | + const winrt::Microsoft::ReactNative::IComponentProps& cloneFrom) noexcept { |
| 138 | + return winrt::make<CalendarViewProps>(props, cloneFrom); |
| 139 | + }); |
| 140 | + |
| 141 | + builder.SetUpdatePropsHandler([](const winrt::Microsoft::ReactNative::ComponentView &view, |
| 142 | + const winrt::Microsoft::ReactNative::IComponentProps &newProps, |
| 143 | + const winrt::Microsoft::ReactNative::IComponentProps &oldProps) noexcept { |
| 144 | + auto userData = view.UserData().as<TUserData>(); |
| 145 | + userData->UpdateProps(view, newProps ? newProps.as<CalendarViewProps>() : nullptr, oldProps ? oldProps.as<CalendarViewProps>() : nullptr); |
| 146 | + }); |
| 147 | + |
| 148 | + compBuilder.SetUpdateLayoutMetricsHandler([](const winrt::Microsoft::ReactNative::ComponentView &view, |
| 149 | + const winrt::Microsoft::ReactNative::LayoutMetrics &newLayoutMetrics, |
| 150 | + const winrt::Microsoft::ReactNative::LayoutMetrics &oldLayoutMetrics) noexcept { |
| 151 | + auto userData = view.UserData().as<TUserData>(); |
| 152 | + userData->UpdateLayoutMetrics(view, newLayoutMetrics, oldLayoutMetrics); |
| 153 | + }); |
| 154 | + |
| 155 | + builder.SetUpdateEventEmitterHandler([](const winrt::Microsoft::ReactNative::ComponentView &view, |
| 156 | + const winrt::Microsoft::ReactNative::EventEmitter &eventEmitter) noexcept { |
| 157 | + auto userData = view.UserData().as<TUserData>(); |
| 158 | + userData->UpdateEventEmitter(std::make_shared<CalendarViewEventEmitter>(eventEmitter)); |
| 159 | + }); |
| 160 | + |
| 161 | + if constexpr (&TUserData::FinalizeUpdate != &BaseCalendarView<TUserData>::FinalizeUpdate) { |
| 162 | + builder.SetFinalizeUpdateHandler([](const winrt::Microsoft::ReactNative::ComponentView &view, |
| 163 | + winrt::Microsoft::ReactNative::ComponentViewUpdateMask mask) noexcept { |
| 164 | + auto userData = view.UserData().as<TUserData>(); |
| 165 | + userData->FinalizeUpdate(view, mask); |
| 166 | + }); |
| 167 | + } |
| 168 | + |
| 169 | + if constexpr (&TUserData::UpdateState != &BaseCalendarView<TUserData>::UpdateState) { |
| 170 | + builder.SetUpdateStateHandler([](const winrt::Microsoft::ReactNative::ComponentView &view, |
| 171 | + const winrt::Microsoft::ReactNative::IComponentState &newState) noexcept { |
| 172 | + auto userData = view.UserData().as<TUserData>(); |
| 173 | + userData->UpdateState(view, newState); |
| 174 | + }); |
| 175 | + } |
| 176 | + |
| 177 | + if constexpr (&TUserData::MountChildComponentView != &BaseCalendarView<TUserData>::MountChildComponentView) { |
| 178 | + builder.SetMountChildComponentViewHandler([](const winrt::Microsoft::ReactNative::ComponentView &view, |
| 179 | + const winrt::Microsoft::ReactNative::MountChildComponentViewArgs &args) noexcept { |
| 180 | + auto userData = view.UserData().as<TUserData>(); |
| 181 | + return userData->MountChildComponentView(view, args); |
| 182 | + }); |
| 183 | + } |
| 184 | + |
| 185 | + if constexpr (&TUserData::UnmountChildComponentView != &BaseCalendarView<TUserData>::UnmountChildComponentView) { |
| 186 | + builder.SetUnmountChildComponentViewHandler([](const winrt::Microsoft::ReactNative::ComponentView &view, |
| 187 | + const winrt::Microsoft::ReactNative::UnmountChildComponentViewArgs &args) noexcept { |
| 188 | + auto userData = view.UserData().as<TUserData>(); |
| 189 | + return userData->UnmountChildComponentView(view, args); |
| 190 | + }); |
| 191 | + } |
| 192 | + |
| 193 | + compBuilder.SetViewComponentViewInitializer([](const winrt::Microsoft::ReactNative::ComponentView &view) noexcept { |
| 194 | + auto userData = winrt::make_self<TUserData>(); |
| 195 | + if constexpr (&TUserData::Initialize != &BaseCalendarView<TUserData>::Initialize) { |
| 196 | + userData->Initialize(view); |
| 197 | + } |
| 198 | + view.UserData(*userData); |
| 199 | + }); |
| 200 | + |
| 201 | + if constexpr (&TUserData::CreateVisual != &BaseCalendarView<TUserData>::CreateVisual) { |
| 202 | + compBuilder.SetCreateVisualHandler([](const winrt::Microsoft::ReactNative::ComponentView &view) noexcept { |
| 203 | + auto userData = view.UserData().as<TUserData>(); |
| 204 | + return userData->CreateVisual(view); |
| 205 | + }); |
| 206 | + } |
| 207 | + |
| 208 | + // Allow app to further customize the builder |
| 209 | + if (builderCallback) { |
| 210 | + builderCallback(compBuilder); |
| 211 | + } |
| 212 | + }); |
| 213 | +} |
| 214 | + |
| 215 | +} // namespace winrt::SampleCustomComponent::Codegen |
| 216 | + |
| 217 | +#endif // #ifdef RNW_NEW_ARCH |
0 commit comments