|
| 1 | +// Copyright (c) Microsoft Corporation. |
| 2 | +// Licensed under the MIT License. |
| 3 | + |
| 4 | +#pragma once |
| 5 | + |
| 6 | +#include "ActivityIndicatorComponentView.h" |
| 7 | +#include "CompositionDynamicAutomationProvider.h" |
| 8 | + |
| 9 | +#include <Windows.UI.Composition.h> |
| 10 | +#include <Windows.h> |
| 11 | +#include "CompositionContextHelper.h" |
| 12 | + |
| 13 | +namespace Microsoft::ReactNative { |
| 14 | + |
| 15 | +std::shared_ptr<ActivityIndicatorComponentView> ActivityIndicatorComponentView::Create( |
| 16 | + const winrt::Microsoft::ReactNative::Composition::ICompositionContext &compContext, |
| 17 | + facebook::react::Tag tag, |
| 18 | + winrt::Microsoft::ReactNative::ReactContext const &reactContext) noexcept { |
| 19 | + return std::shared_ptr<ActivityIndicatorComponentView>( |
| 20 | + new ActivityIndicatorComponentView(compContext, tag, reactContext)); |
| 21 | +} |
| 22 | + |
| 23 | +ActivityIndicatorComponentView::ActivityIndicatorComponentView( |
| 24 | + const winrt::Microsoft::ReactNative::Composition::ICompositionContext &compContext, |
| 25 | + facebook::react::Tag tag, |
| 26 | + winrt::Microsoft::ReactNative::ReactContext const &reactContext) |
| 27 | + : Super(compContext, tag), m_context(reactContext) { |
| 28 | + m_props = std::make_shared<facebook::react::ActivityIndicatorViewProps const>(); |
| 29 | +} |
| 30 | + |
| 31 | +void ActivityIndicatorComponentView::mountChildComponentView( |
| 32 | + IComponentView &childComponentView, |
| 33 | + uint32_t index) noexcept { |
| 34 | + assert(false); |
| 35 | +} |
| 36 | + |
| 37 | +void ActivityIndicatorComponentView::unmountChildComponentView( |
| 38 | + IComponentView &childComponentView, |
| 39 | + uint32_t index) noexcept { |
| 40 | + assert(false); |
| 41 | +} |
| 42 | + |
| 43 | +void ActivityIndicatorComponentView::handleCommand(std::string const &commandName, folly::dynamic const &arg) noexcept { |
| 44 | + Super::handleCommand(commandName, arg); |
| 45 | +} |
| 46 | + |
| 47 | +void ActivityIndicatorComponentView::updateProps( |
| 48 | + facebook::react::Props::Shared const &props, |
| 49 | + facebook::react::Props::Shared const &oldProps) noexcept { |
| 50 | + const auto oldViewProps = std::static_pointer_cast<const facebook::react::ActivityIndicatorViewProps>(m_props); |
| 51 | + const auto newViewProps = std::static_pointer_cast<const facebook::react::ActivityIndicatorViewProps>(props); |
| 52 | + |
| 53 | + ensureVisual(); |
| 54 | + |
| 55 | + // update color if needed |
| 56 | + if (newViewProps->color && (!oldProps || newViewProps->color != oldViewProps->color)) { |
| 57 | + m_ActivityIndicatorVisual.updateColor(newViewProps->color.AsWindowsColor()); |
| 58 | + } |
| 59 | + |
| 60 | + updateBorderProps(*oldViewProps, *newViewProps); |
| 61 | + m_props = std::static_pointer_cast<facebook::react::ViewProps const>(props); |
| 62 | +} |
| 63 | + |
| 64 | +void ActivityIndicatorComponentView::updateState( |
| 65 | + facebook::react::State::Shared const &state, |
| 66 | + facebook::react::State::Shared const &oldState) noexcept {} |
| 67 | + |
| 68 | +void ActivityIndicatorComponentView::updateLayoutMetrics( |
| 69 | + facebook::react::LayoutMetrics const &layoutMetrics, |
| 70 | + facebook::react::LayoutMetrics const &oldLayoutMetrics) noexcept { |
| 71 | + // Set Position & Size Properties |
| 72 | + ensureVisual(); |
| 73 | + |
| 74 | + if ((layoutMetrics.displayType != m_layoutMetrics.displayType)) { |
| 75 | + OuterVisual().IsVisible(layoutMetrics.displayType != facebook::react::DisplayType::None); |
| 76 | + } |
| 77 | + |
| 78 | + updateBorderLayoutMetrics(layoutMetrics, *m_props); |
| 79 | + m_layoutMetrics = layoutMetrics; |
| 80 | + |
| 81 | + UpdateCenterPropertySet(); |
| 82 | + m_visual.Size( |
| 83 | + {layoutMetrics.frame.size.width * layoutMetrics.pointScaleFactor, |
| 84 | + layoutMetrics.frame.size.height * layoutMetrics.pointScaleFactor}); |
| 85 | +} |
| 86 | + |
| 87 | +void ActivityIndicatorComponentView::finalizeUpdates(RNComponentViewUpdateMask updateMask) noexcept {} |
| 88 | + |
| 89 | +void ActivityIndicatorComponentView::prepareForRecycle() noexcept {} |
| 90 | + |
| 91 | +facebook::react::Props::Shared ActivityIndicatorComponentView::props() noexcept { |
| 92 | + return m_props; |
| 93 | +} |
| 94 | + |
| 95 | +void ActivityIndicatorComponentView::ensureVisual() noexcept { |
| 96 | + if (!m_visual) { |
| 97 | + m_visual = m_compContext.CreateSpriteVisual(); |
| 98 | + m_ActivityIndicatorVisual = m_compContext.CreateActivityVisual(); // creates COM control |
| 99 | + |
| 100 | + OuterVisual().InsertAt(m_ActivityIndicatorVisual, 0); |
| 101 | + OuterVisual().InsertAt(m_visual, 0); |
| 102 | + } |
| 103 | +} |
| 104 | + |
| 105 | +facebook::react::Tag ActivityIndicatorComponentView::hitTest( |
| 106 | + facebook::react::Point pt, |
| 107 | + facebook::react::Point &localPt, |
| 108 | + bool ignorePointerEvents) const noexcept { |
| 109 | + facebook::react::Point ptLocal{pt.x - m_layoutMetrics.frame.origin.x, pt.y - m_layoutMetrics.frame.origin.y}; |
| 110 | + |
| 111 | + if ((ignorePointerEvents || m_props->pointerEvents == facebook::react::PointerEventsMode::Auto || |
| 112 | + m_props->pointerEvents == facebook::react::PointerEventsMode::BoxOnly) && |
| 113 | + ptLocal.x >= 0 && ptLocal.x <= m_layoutMetrics.frame.size.width && ptLocal.y >= 0 && |
| 114 | + ptLocal.y <= m_layoutMetrics.frame.size.height) { |
| 115 | + localPt = ptLocal; |
| 116 | + return tag(); |
| 117 | + } |
| 118 | + return -1; |
| 119 | +} |
| 120 | + |
| 121 | +winrt::Microsoft::ReactNative::Composition::IVisual ActivityIndicatorComponentView::Visual() const noexcept { |
| 122 | + return m_visual; |
| 123 | +} |
| 124 | + |
| 125 | +bool ActivityIndicatorComponentView::focusable() const noexcept { |
| 126 | + return false; |
| 127 | +} |
| 128 | + |
| 129 | +} // namespace Microsoft::ReactNative |
0 commit comments