|
4 | 4 | #include "pch.h"
|
5 | 5 |
|
6 | 6 | #include "TextViewManager.h"
|
| 7 | +#include "Utils/Helpers.h" |
7 | 8 |
|
8 | 9 | #include <Views/RawTextViewManager.h>
|
9 | 10 | #include <Views/ShadowNodeBase.h>
|
10 | 11 | #include <Views/VirtualTextViewManager.h>
|
11 | 12 |
|
12 | 13 | #include <UI.Xaml.Automation.Peers.h>
|
13 | 14 | #include <UI.Xaml.Automation.h>
|
| 15 | +#include <UI.Xaml.Controls.Primitives.h> |
14 | 16 | #include <UI.Xaml.Controls.h>
|
15 | 17 | #include <UI.Xaml.Documents.h>
|
16 | 18 | #include <Utils/PropertyUtils.h>
|
@@ -211,10 +213,24 @@ bool TextViewManager::UpdateProperty(
|
211 | 213 | textBlock.ClearValue(xaml::Controls::TextBlock::LineStackingStrategyProperty());
|
212 | 214 | }
|
213 | 215 | } else if (propertyName == "selectable") {
|
214 |
| - if (propertyValue.Type() == winrt::Microsoft::ReactNative::JSValueType::Boolean) |
215 |
| - textBlock.IsTextSelectionEnabled(propertyValue.AsBoolean()); |
216 |
| - else if (propertyValue.IsNull()) |
| 216 | + if (propertyValue.Type() == winrt::Microsoft::ReactNative::JSValueType::Boolean) { |
| 217 | + const auto selectable = propertyValue.AsBoolean(); |
| 218 | + textBlock.IsTextSelectionEnabled(selectable); |
| 219 | + // This works around a XAML Islands bug where the XamlRoot of the first |
| 220 | + // window the flyout is shown on takes ownership of the flyout and attempts |
| 221 | + // to show the flyout on other windows cause the first window to get focus. |
| 222 | + // https://github.com/microsoft/microsoft-ui-xaml/issues/5341 |
| 223 | + if (selectable && IsXamlIsland() && |
| 224 | + winrt::Windows::Foundation::Metadata::ApiInformation::IsApiContractPresent( |
| 225 | + L"Windows.Foundation.UniversalApiContract", 7)) { |
| 226 | + xaml::Controls::TextCommandBarFlyout flyout; |
| 227 | + flyout.Placement(xaml::Controls::Primitives::FlyoutPlacementMode::BottomEdgeAlignedLeft); |
| 228 | + textBlock.ContextFlyout(flyout); |
| 229 | + textBlock.SelectionFlyout(flyout); |
| 230 | + } |
| 231 | + } else if (propertyValue.IsNull()) { |
217 | 232 | textBlock.ClearValue(xaml::Controls::TextBlock::IsTextSelectionEnabledProperty());
|
| 233 | + } |
218 | 234 | } else if (propertyName == "allowFontScaling") {
|
219 | 235 | if (propertyValue.Type() == winrt::Microsoft::ReactNative::JSValueType::Boolean) {
|
220 | 236 | textBlock.IsTextScaleFactorEnabled(propertyValue.AsBoolean());
|
|
0 commit comments