-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds TextPropertyChangedParentVisitor for Text tree traversals when t…
…ext or highlights are updated
- Loading branch information
Showing
17 changed files
with
165 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
vnext/Microsoft.ReactNative/Views/Text/TextPropertyChangedParentVisitor.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
#include "TextPropertyChangedParentVisitor.h" | ||
#include <UI.Xaml.Automation.Peers.h> | ||
#include <UI.Xaml.Automation.h> | ||
#include <Views/TextViewManager.h> | ||
#include <Views/VirtualTextViewManager.h> | ||
|
||
namespace winrt { | ||
using namespace xaml::Automation; | ||
using namespace xaml::Automation::Peers; | ||
} // namespace winrt | ||
|
||
namespace Microsoft::ReactNative { | ||
void TextPropertyChangedParentVisitor::VisitExtensionText(ShadowNodeBase *node) { | ||
// Update nested flag for fast text updates | ||
m_isNested = true; | ||
Super::VisitExtensionText(node); | ||
} | ||
|
||
void TextPropertyChangedParentVisitor::VisitText(ShadowNodeBase *node) { | ||
// Raise LiveRegionChanged event | ||
const auto isTextUpdate = HasPropertyChangeType(PropertyChangeType::Text); | ||
if (isTextUpdate) { | ||
const auto element = node->GetView().as<xaml::Controls::TextBlock>(); | ||
|
||
// If name is set, it's controlled by accessibilityLabel, and it's already | ||
// handled in FrameworkElementViewManager. Here it only handles when name is | ||
// not set. | ||
if (xaml::Automation::AutomationProperties::GetLiveSetting(element) != winrt::AutomationLiveSetting::Off && | ||
xaml::Automation::AutomationProperties::GetName(element).empty() && | ||
xaml::Automation::AutomationProperties::GetAccessibilityView(element) != winrt::Peers::AccessibilityView::Raw) { | ||
if (auto peer = xaml::Automation::Peers::FrameworkElementAutomationPeer::FromElement(element)) { | ||
peer.RaiseAutomationEvent(winrt::AutomationEvents::LiveRegionChanged); | ||
} | ||
} | ||
|
||
// Update fast text content | ||
if (!m_isNested && node->m_children.size() == 1) { | ||
if (const auto childNode = GetShadowNode(node->m_children[0])) { | ||
const auto run = static_cast<ShadowNodeBase *>(childNode)->GetView().as<winrt::Run>(); | ||
element.Text(run.Text()); | ||
} | ||
} | ||
} | ||
|
||
// Refresh text highlighters | ||
const auto isHighlightAdded = HasPropertyChangeType(PropertyChangeType::AddHighlight); | ||
const auto isHighlightRemoved = HasPropertyChangeType(PropertyChangeType::RemoveHighlight); | ||
if (isTextUpdate || isHighlightAdded || isHighlightRemoved) { | ||
TextViewManager::UpdateTextHighlighters(node, isHighlightAdded); | ||
} | ||
|
||
Super::VisitText(node); | ||
} | ||
|
||
void TextPropertyChangedParentVisitor::VisitVirtualText(ShadowNodeBase *node) { | ||
// Update nested flag for fast text updates | ||
m_isNested = true; | ||
|
||
// Update descendant text highlight flag | ||
if (HasPropertyChangeType(PropertyChangeType::AddHighlight)) { | ||
static_cast<VirtualTextShadowNode *>(node)->hasDescendantTextHighlighter = true; | ||
} | ||
|
||
Super::VisitVirtualText(node); | ||
} | ||
|
||
} // namespace Microsoft::ReactNative |
42 changes: 42 additions & 0 deletions
42
vnext/Microsoft.ReactNative/Views/Text/TextPropertyChangedParentVisitor.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
#pragma once | ||
|
||
#include <Views/TextViewManager.h> | ||
#include "TextParentVisitor.h" | ||
|
||
namespace Microsoft::ReactNative { | ||
|
||
enum class PropertyChangeType : std::uint_fast8_t { | ||
None = 0, | ||
Text = 1 << 0, | ||
AddHighlight = 1 << 1, | ||
RemoveHighlight = 1 << 2, | ||
}; | ||
|
||
DEFINE_ENUM_FLAG_OPERATORS(PropertyChangeType); | ||
|
||
class TextPropertyChangedParentVisitor : public TextParentVisitor { | ||
using Super = TextParentVisitor; | ||
|
||
public: | ||
TextPropertyChangedParentVisitor(PropertyChangeType type) : m_propertyChangeType{type} {} | ||
|
||
protected: | ||
void VisitExtensionText(ShadowNodeBase *node) override; | ||
|
||
void VisitText(ShadowNodeBase *node) override; | ||
|
||
void VisitVirtualText(ShadowNodeBase *node) override; | ||
|
||
private: | ||
PropertyChangeType m_propertyChangeType; | ||
bool m_isNested{false}; | ||
|
||
bool HasPropertyChangeType(PropertyChangeType type) { | ||
return (m_propertyChangeType & type) == type; | ||
} | ||
}; | ||
|
||
} // namespace Microsoft::ReactNative |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.