1010#include < react/renderer/core/LayoutConstraints.h>
1111#include < react/renderer/textlayoutmanager/TextLayoutManager.h>
1212#include < winrt/Microsoft.ReactNative.Composition.h>
13+ #include < winrt/Windows.UI.ViewManagement.h>
1314#include " TextDrawing.h"
1415#include " dwmapi.h"
1516
@@ -49,7 +50,9 @@ facebook::react::AttributedStringBox CreateTooltipAttributedString(const std::st
4950 auto fragment = facebook::react::AttributedString::Fragment{};
5051 fragment.string = tooltip;
5152 fragment.textAttributes .fontSize = tooltipFontSize;
52- attributedString.appendFragment (fragment);
53+ fragment.textAttributes .fontSizeMultiplier =
54+ static_cast <float >(winrt::Windows::UI::ViewManagement::UISettings ().TextScaleFactor ());
55+ attributedString.appendFragment (std::move (fragment));
5356 return facebook::react::AttributedStringBox{attributedString};
5457}
5558
@@ -231,14 +234,13 @@ void TooltipTracker::OnUnmounted(
231234}
232235
233236void TooltipTracker::ShowTooltip (const winrt::Microsoft::ReactNative::ComponentView &view) noexcept {
234- auto viewCompView = view.as <winrt::Microsoft::ReactNative::Composition::ViewComponentView>();
235-
236- auto selfView =
237- winrt::get_self<winrt::Microsoft::ReactNative::Composition::implementation::ViewComponentView>(viewCompView);
238- auto parentHwnd = selfView->GetHwndForParenting ();
239237 DestroyTimer ();
240238
241239 if (!m_hwndTip) {
240+ auto viewCompView = view.as <winrt::Microsoft::ReactNative::Composition::ViewComponentView>();
241+ auto selfView =
242+ winrt::get_self<winrt::Microsoft::ReactNative::Composition::implementation::ViewComponentView>(viewCompView);
243+ auto parentHwnd = selfView->GetHwndForParenting ();
242244 auto tooltipData = std::make_unique<TooltipData>(view);
243245 tooltipData->attributedString = CreateTooltipAttributedString (*selfView->viewProps ()->tooltip );
244246
@@ -256,37 +258,39 @@ void TooltipTracker::ShowTooltip(const winrt::Microsoft::ReactNative::ComponentV
256258 facebook::react::TextLayoutManager::GetTextLayout (
257259 tooltipData->attributedString , {} /* paragraphAttributes*/ , layoutConstraints, tooltipData->textLayout );
258260
259- DWRITE_TEXT_METRICS tm;
260- winrt::check_hresult (tooltipData->textLayout ->GetMetrics (&tm));
261-
262- tooltipData->width =
263- static_cast <int >(tm.width + ((tooltipHorizontalPadding + tooltipHorizontalPadding) * scaleFactor));
264- tooltipData->height = static_cast <int >(tm.height + ((tooltipTopPadding + tooltipBottomPadding) * scaleFactor));
265-
266- POINT pt = {static_cast <LONG>(m_pos.X ), static_cast <LONG>(m_pos.Y )};
267- ClientToScreen (parentHwnd, &pt);
268-
269- RegisterTooltipWndClass ();
270- HINSTANCE hInstance = GetModuleHandle (NULL );
271- m_hwndTip = CreateWindow (
272- c_tooltipWindowClassName,
273- L" Tooltip" ,
274- WS_POPUP,
275- pt.x - tooltipData->width / 2 ,
276- static_cast <int >(pt.y - tooltipData->height - (toolTipPlacementMargin * scaleFactor)),
277- tooltipData->width ,
278- tooltipData->height ,
279- parentHwnd,
280- NULL ,
281- hInstance,
282- tooltipData.get ());
283-
284- DWM_WINDOW_CORNER_PREFERENCE preference = DWMWCP_ROUNDSMALL;
285- UINT borderThickness = 0 ;
286- DwmSetWindowAttribute (m_hwndTip, DWMWA_WINDOW_CORNER_PREFERENCE, &preference, sizeof (preference));
287-
288- tooltipData.release ();
289- AnimateWindow (m_hwndTip, toolTipAnimationTimeMs, AW_BLEND);
261+ if (tooltipData->textLayout ) {
262+ DWRITE_TEXT_METRICS tm;
263+ winrt::check_hresult (tooltipData->textLayout ->GetMetrics (&tm));
264+
265+ tooltipData->width =
266+ static_cast <int >((tm.width + tooltipHorizontalPadding + tooltipHorizontalPadding) * scaleFactor);
267+ tooltipData->height = static_cast <int >((tm.height + tooltipTopPadding + tooltipBottomPadding) * scaleFactor);
268+
269+ POINT pt = {static_cast <LONG>(m_pos.X ), static_cast <LONG>(m_pos.Y )};
270+ ClientToScreen (parentHwnd, &pt);
271+
272+ RegisterTooltipWndClass ();
273+ HINSTANCE hInstance = GetModuleHandle (NULL );
274+ m_hwndTip = CreateWindow (
275+ c_tooltipWindowClassName,
276+ L" Tooltip" ,
277+ WS_POPUP,
278+ pt.x - tooltipData->width / 2 ,
279+ static_cast <int >(pt.y - tooltipData->height - (toolTipPlacementMargin * scaleFactor)),
280+ tooltipData->width ,
281+ tooltipData->height ,
282+ parentHwnd,
283+ NULL ,
284+ hInstance,
285+ tooltipData.get ());
286+
287+ DWM_WINDOW_CORNER_PREFERENCE preference = DWMWCP_ROUNDSMALL;
288+ UINT borderThickness = 0 ;
289+ DwmSetWindowAttribute (m_hwndTip, DWMWA_WINDOW_CORNER_PREFERENCE, &preference, sizeof (preference));
290+
291+ tooltipData.release ();
292+ AnimateWindow (m_hwndTip, toolTipAnimationTimeMs, AW_BLEND);
293+ }
290294 }
291295}
292296
0 commit comments