-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathScrollViewComponentView.cpp
More file actions
1520 lines (1302 loc) · 63.2 KB
/
ScrollViewComponentView.cpp
File metadata and controls
1520 lines (1302 loc) · 63.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
#pragma once
#include "ScrollViewComponentView.h"
#include <Fabric/ComponentView.h>
#include <Utils/ValueUtils.h>
#pragma warning(push)
#pragma warning(disable : 4305)
#include <react/renderer/components/scrollview/ScrollViewShadowNode.h>
#pragma warning(pop)
#include <windows.ui.composition.interop.h>
#include <winrt/Windows.UI.ViewManagement.Core.h>
#include <AutoDraw.h>
#include <Fabric/DWriteHelpers.h>
#include <unicode.h>
#include <functional>
#include "ContentIslandComponentView.h"
#include "JSValueReader.h"
#include "RootComponentView.h"
#include "TooltipService.h"
namespace winrt::Microsoft::ReactNative::Composition::implementation {
constexpr float c_scrollerLineDelta = 16.0f;
enum class ScrollbarHitRegion : int {
Unknown = -1,
ArrowFirst = 0,
PageUp = 1,
Thumb = 2,
PageDown = 3,
ArrowLast = 4,
};
struct ScrollBarComponent {
ScrollBarComponent(
const winrt::Microsoft::ReactNative::Composition::ScrollViewComponentView &outer,
const winrt::Microsoft::ReactNative::Composition::Experimental::ICompositionContext &compContext,
winrt::Microsoft::ReactNative::ReactContext const &reactContext,
bool vertical)
: m_wkOuter(outer), m_compContext(compContext), m_reactContext(reactContext), m_vertical(vertical) {
m_rootVisual = m_compContext.CreateSpriteVisual();
m_trackVisual = m_compContext.CreateRoundedRectangleVisual();
m_thumbVisual = m_compContext.CreateRoundedRectangleVisual();
m_arrowVisualFirst = m_compContext.CreateSpriteVisual();
m_arrowVisualLast = m_compContext.CreateSpriteVisual();
m_rootVisual.InsertAt(m_trackVisual, 0);
m_rootVisual.InsertAt(m_arrowVisualFirst, 1);
m_rootVisual.InsertAt(m_arrowVisualLast, 2);
m_rootVisual.InsertAt(m_thumbVisual, 3);
m_trackVisual.AnimationClass(winrt::Microsoft::ReactNative::Composition::Experimental::AnimationClass::ScrollBar);
m_arrowVisualFirst.AnimationClass(
winrt::Microsoft::ReactNative::Composition::Experimental::AnimationClass::ScrollBar);
m_arrowVisualLast.AnimationClass(
winrt::Microsoft::ReactNative::Composition::Experimental::AnimationClass::ScrollBar);
m_thumbVisual.AnimationClass(
vertical ? winrt::Microsoft::ReactNative::Composition::Experimental::AnimationClass::ScrollBarThumbVertical
: winrt::Microsoft::ReactNative::Composition::Experimental::AnimationClass::ScrollBarThumbHorizontal);
updateShy(true);
onScaleChanged();
UpdateColorForScrollBarRegions();
}
void UpdateColorForScrollBarRegions() noexcept {
updateHighlight(ScrollbarHitRegion::ArrowFirst);
updateHighlight(ScrollbarHitRegion::ArrowLast);
updateHighlight(ScrollbarHitRegion::Thumb);
if (auto outer = m_wkOuter.get()) {
m_trackVisual.Brush(
winrt::get_self<winrt::Microsoft::ReactNative::Composition::implementation::Theme>(outer.Theme())
->InternalPlatformBrush(L"ScrollBarTrackFill"));
}
}
void ContentSize(winrt::Windows::Foundation::Size contentSize) noexcept {
if (m_contentSize == contentSize) {
return;
}
m_contentSize = contentSize;
updateThumb();
updateVisibility(m_visible);
}
void updateTrack() noexcept {
if (m_vertical) {
m_trackVisual.Size({m_arrowSize, std::max(m_size.Height - (m_trackMargin * 2), 0.0f)});
m_trackVisual.Offset({-m_arrowSize, m_trackMargin, 0.0f}, {1.0f, 0.0f, 0.0f});
} else {
m_trackVisual.Size({std::max(m_size.Width - (m_trackMargin * 2), 0.0f), m_arrowSize});
m_trackVisual.Offset({m_trackMargin, -m_arrowSize, 0.0f}, {0.0f, 1.0f, 0.0f});
}
}
void updateLayoutMetrics(facebook::react::LayoutMetrics const &layoutMetrics) noexcept {
m_size = {
layoutMetrics.frame.size.width * layoutMetrics.pointScaleFactor,
layoutMetrics.frame.size.height * layoutMetrics.pointScaleFactor};
if (m_scaleFactor != layoutMetrics.pointScaleFactor) {
m_scaleFactor = layoutMetrics.pointScaleFactor;
onScaleChanged();
}
updateTrack();
updateThumb();
updateVisibility(m_visible);
}
void updateVisibility(bool visible) noexcept {
if ((m_size.Width <= 0.0f && m_size.Height <= 0.0f) ||
(m_contentSize.Width <= 0.0f && m_contentSize.Height <= 0.0f)) {
m_rootVisual.IsVisible(false);
return;
}
if (!visible) {
m_visible = false;
m_rootVisual.IsVisible(visible);
return;
}
bool newVisibility = false;
if (m_vertical) {
newVisibility = (m_contentSize.Height > m_size.Height);
} else {
newVisibility = (m_contentSize.Width > m_size.Width);
}
m_visible = newVisibility;
m_rootVisual.IsVisible(m_visible);
}
void updateRootAndArrowVisualOffsets() noexcept {
if (m_vertical) {
m_rootVisual.RelativeSizeWithOffset({m_arrowSize, 0.0f}, {0.0f, 1.0f});
m_rootVisual.Offset({-(m_arrowSize + m_trackEdgeMargin), 0.0f, 0.0f}, {1.0f, 0.0f, 0.0f});
m_arrowVisualFirst.Offset({0.0f, m_arrowMargin, 0.0f});
m_arrowVisualLast.Offset({0.0f, -(m_arrowSize + m_arrowMargin), 0.0f}, {0.0f, 1.0f, 0.0f});
} else {
m_rootVisual.RelativeSizeWithOffset({0.0f, m_arrowSize}, {1.0f, 0.0f});
m_rootVisual.Offset({0.0f, -(m_arrowSize + m_trackEdgeMargin), 0.0f}, {0.0f, 1.0f, 0.0f});
m_arrowVisualFirst.Offset({m_arrowMargin, 0.0f, 0.0f});
m_arrowVisualLast.Offset({-(m_arrowSize + m_arrowMargin), 0.0f, 0.0f}, {1.0f, 0.0f, 0.0f});
}
}
void onScaleChanged() noexcept {
m_arrowSize = 12 * m_scaleFactor; // From Xaml resource: ScrollBarSize
m_thumbWidth = 6 * m_scaleFactor; // From Xaml resource: ScrollBarThumbStrokeThickness
m_thumbShyWidth = 2 * m_scaleFactor;
m_arrowMargin = 4 * m_scaleFactor; // From Xaml resource: ScrollBar(Vertical|Horizontal)(Increase|Decrease)Margin
m_trackEdgeMargin = 1 * m_scaleFactor; // From Xaml resource: ScrollViewerScrollBarMargin
m_trackMargin =
(2 + 1) * m_scaleFactor; // From Xaml template VerticalPanningThumb.Margin + ScrollViewerScrollBarMargin
m_minThumbSize = static_cast<int>(
30 * m_scaleFactor); // From Xaml resource: ScrollBarVerticalThumbMinHeight / ScrollBarHorizontalThumbMinWidth
m_thumbVisual.CornerRadius({m_thumbWidth / 2.0f, m_thumbWidth / 2.0f});
m_trackVisual.CornerRadius({m_arrowSize / 2.0f, m_arrowSize / 2.0f});
m_arrowVisualFirst.Size({m_arrowSize, m_arrowSize});
m_arrowVisualLast.Size({m_arrowSize, m_arrowSize});
m_arrowFirstDrawingSurface = nullptr; // Reset arrow textures when scale changes
m_arrowLastDrawingSurface = nullptr;
updateRootAndArrowVisualOffsets();
}
void ContentOffset(const winrt::Windows::Foundation::Numerics::float3 &offset) noexcept {
m_offset = offset;
updateThumb();
}
ScrollbarHitRegion HitTest(winrt::Windows::Foundation::Point pt) noexcept {
pt = {pt.X * m_scaleFactor, pt.Y * m_scaleFactor};
if (m_vertical) {
if (pt.X < m_size.Width - (m_arrowSize + m_trackEdgeMargin)) {
return ScrollbarHitRegion::Unknown;
}
if (pt.Y < (m_arrowSize + m_arrowMargin)) {
return ScrollbarHitRegion::ArrowFirst;
}
if (pt.Y < (m_arrowSize + m_arrowMargin) + m_thumbPos) {
return ScrollbarHitRegion::PageUp;
}
if (pt.Y < (m_arrowSize + m_arrowMargin) + m_thumbPos + m_thumbSize) {
return ScrollbarHitRegion::Thumb;
}
if (pt.Y < m_size.Height - (m_arrowSize + m_arrowMargin)) {
return ScrollbarHitRegion::PageDown;
}
return ScrollbarHitRegion::ArrowLast;
} else {
if (pt.Y < m_size.Height - (m_arrowSize + m_trackEdgeMargin)) {
return ScrollbarHitRegion::Unknown;
}
if (pt.X < (m_arrowSize + m_arrowMargin)) {
return ScrollbarHitRegion::ArrowFirst;
}
if (pt.X < (m_arrowSize + m_arrowMargin) + m_thumbPos) {
return ScrollbarHitRegion::PageUp;
}
if (pt.X < (m_arrowSize + m_arrowMargin) + m_thumbPos + m_thumbSize) {
return ScrollbarHitRegion::Thumb;
}
if (pt.X < m_size.Width - (m_arrowSize + m_arrowMargin)) {
return ScrollbarHitRegion::PageDown;
}
return ScrollbarHitRegion::ArrowLast;
}
return ScrollbarHitRegion::Unknown;
}
int getViewportSize() const noexcept {
return static_cast<int>(m_vertical ? m_size.Height : m_size.Width);
}
int calulateMaxThumbLength() const noexcept {
return std::max(static_cast<int>(getViewportSize() - (2 * (m_arrowSize + m_arrowMargin))), 0);
}
int getScrollRange() const noexcept {
return static_cast<int>(m_vertical ? m_contentSize.Height : m_contentSize.Width);
}
int getComputedPixelThumbSize() const noexcept {
auto maxThumbLength = calulateMaxThumbLength();
auto scrollRange = getScrollRange();
auto viewportSize = getViewportSize();
return std::max(::MulDiv(std::min(scrollRange, viewportSize), maxThumbLength, scrollRange), 0);
}
float scrollOffsetFromThumbPos(int thumbPos) const noexcept {
auto maxThumbLength = calulateMaxThumbLength();
auto scrollRange = getScrollRange();
const int computedPixelThumbSize = getComputedPixelThumbSize();
int thumbCorrection = 0;
if (!(m_minThumbSize <= computedPixelThumbSize || maxThumbLength < 2 * m_minThumbSize)) {
thumbCorrection = m_minThumbSize - computedPixelThumbSize;
}
return std::clamp(
static_cast<float>(::MulDiv(thumbPos, scrollRange, (maxThumbLength - thumbCorrection))),
0.0f,
static_cast<float>(scrollRange));
}
void updateThumb() noexcept {
auto maxThumbLength = calulateMaxThumbLength();
auto scrollRange = getScrollRange();
auto scrollOffset = static_cast<int>(m_vertical ? m_offset.y : m_offset.x);
const int computedPixelThumbSize = getComputedPixelThumbSize();
m_thumbSize = 0;
int thumbCorrection = 0;
if (m_minThumbSize <= computedPixelThumbSize || maxThumbLength < 2 * m_minThumbSize)
m_thumbSize = computedPixelThumbSize;
else {
thumbCorrection = m_minThumbSize - computedPixelThumbSize;
m_thumbSize = m_minThumbSize;
}
// Position is relative to available area for thumb
m_thumbPos = (scrollRange > 0 ? ::MulDiv(scrollOffset, maxThumbLength - thumbCorrection, scrollRange) : 0);
auto thumbOffset = (m_arrowSize - m_thumbWidth) / 2.0f;
auto shyOffset = m_shy ? (m_thumbWidth - m_thumbShyWidth) : 0.0f;
auto thumbScale = m_shy ? (m_thumbShyWidth / m_thumbWidth) : 1.0f;
if (m_vertical) {
m_thumbVisual.Size({m_thumbWidth, static_cast<float>(m_thumbSize)});
m_thumbVisual.Offset(
{-m_arrowSize + thumbOffset + shyOffset, m_arrowSize + m_arrowMargin + static_cast<float>(m_thumbPos), 0.0f},
{1.0f, 0.0f, 0.0f});
m_thumbVisual.Scale({thumbScale, 1.0f, 1.0f});
} else {
m_thumbVisual.Size({static_cast<float>(m_thumbSize), m_thumbWidth});
m_thumbVisual.Offset(
{m_arrowSize + m_arrowMargin + static_cast<float>(m_thumbPos), -m_arrowSize + thumbOffset + shyOffset, 0.0f},
{0.0f, 1.0f, 0.0f});
m_thumbVisual.Scale({1.0f, thumbScale, 1.0f});
}
}
winrt::Microsoft::ReactNative::Composition::Experimental::IVisual Visual() const noexcept {
return m_rootVisual;
}
void OnPointerReleased(const winrt::Microsoft::ReactNative::Composition::Input::PointerRoutedEventArgs &args) {
if (auto outer = m_wkOuter.get()) {
if (!m_visible)
return;
auto pt = args.GetCurrentPoint(outer.Tag());
if (m_nTrackInputOffset != -1 &&
pt.PointerDeviceType() == winrt::Microsoft::ReactNative::Composition::Input::PointerDeviceType::Mouse &&
pt.Properties().PointerUpdateKind() ==
winrt::Microsoft::ReactNative::Composition::Input::PointerUpdateKind::LeftButtonReleased) {
handleMoveThumb(args);
stopTrackingThumb();
outer.ReleasePointerCapture(args.Pointer());
auto reg = HitTest(pt.Position());
updateShy(reg == ScrollbarHitRegion::Unknown);
}
}
}
void stopTrackingThumb() noexcept {
m_nTrackInputOffset = -1;
m_thumbVisual.AnimationClass(
m_vertical
? winrt::Microsoft::ReactNative::Composition::Experimental::AnimationClass::ScrollBarThumbVertical
: winrt::Microsoft::ReactNative::Composition::Experimental::AnimationClass::ScrollBarThumbHorizontal);
}
void handleMoveThumb(const winrt::Microsoft::ReactNative::Composition::Input::PointerRoutedEventArgs &args) {
if (auto outer = m_wkOuter.get()) {
auto pt = args.GetCurrentPoint(outer.Tag());
auto pos = pt.Position();
auto newTrackingPosition = static_cast<int>((m_vertical ? pos.Y : pos.X) * m_scaleFactor) - m_nTrackInputOffset;
winrt::get_self<ScrollViewComponentView>(outer)->scrollTo(
m_vertical ? winrt::Windows::Foundation::Numerics::
float3{m_offset.x, scrollOffsetFromThumbPos(newTrackingPosition), m_offset.z}
: winrt::Windows::Foundation::Numerics::
float3{scrollOffsetFromThumbPos(newTrackingPosition), m_offset.y, m_offset.z},
false);
}
args.Handled(true);
}
void OnPointerPressed(const winrt::Microsoft::ReactNative::Composition::Input::PointerRoutedEventArgs &args) {
if (auto outer = m_wkOuter.get()) {
if (!m_visible)
return;
auto pt = args.GetCurrentPoint(outer.Tag());
if (pt.PointerDeviceType() == winrt::Microsoft::ReactNative::Composition::Input::PointerDeviceType::Mouse) {
auto pos = pt.Position();
auto reg = HitTest(pos);
switch (reg) {
case ScrollbarHitRegion::ArrowFirst:
if (m_vertical) {
winrt::get_self<ScrollViewComponentView>(outer)->lineUp(false);
} else {
winrt::get_self<ScrollViewComponentView>(outer)->lineLeft(false);
}
args.Handled(true);
break;
case ScrollbarHitRegion::ArrowLast:
if (m_vertical) {
winrt::get_self<ScrollViewComponentView>(outer)->lineDown(false);
} else {
winrt::get_self<ScrollViewComponentView>(outer)->lineRight(false);
}
args.Handled(true);
break;
case ScrollbarHitRegion::PageUp:
if (m_vertical) {
winrt::get_self<ScrollViewComponentView>(outer)->pageUp(false);
}
args.Handled(true);
break;
case ScrollbarHitRegion::PageDown:
if (m_vertical) {
winrt::get_self<ScrollViewComponentView>(outer)->pageDown(false);
}
args.Handled(true);
break;
case ScrollbarHitRegion::Thumb: {
outer.CapturePointer(args.Pointer());
m_nTrackInputOffset = static_cast<int>((m_vertical ? pos.Y : pos.X) * m_scaleFactor) - m_thumbPos;
m_thumbVisual.AnimationClass(
winrt::Microsoft::ReactNative::Composition::Experimental::AnimationClass::None);
handleMoveThumb(args);
}
}
}
}
}
void OnPointerMoved(const winrt::Microsoft::ReactNative::Composition::Input::PointerRoutedEventArgs &args) {
if (auto outer = m_wkOuter.get()) {
if (!m_visible)
return;
auto pt = args.GetCurrentPoint(outer.Tag());
if (pt.PointerDeviceType() == winrt::Microsoft::ReactNative::Composition::Input::PointerDeviceType::Mouse) {
if (m_nTrackInputOffset != -1) {
handleMoveThumb(args);
} else {
auto pos = pt.Position();
auto reg = HitTest(pos);
updateShy(reg == ScrollbarHitRegion::Unknown);
setHighlightedRegion(reg);
}
}
}
}
void OnPointerCaptureLost() {
if (!m_visible)
return;
stopTrackingThumb();
updateShy(true);
}
void updateShy(bool shy) {
if (shy == m_shy)
return;
m_shy = shy;
m_trackVisual.Opacity(m_shy ? 0.0f : 1.0f);
m_arrowVisualFirst.Opacity(m_shy ? 0.0f : 1.0f);
m_arrowVisualLast.Opacity(m_shy ? 0.0f : 1.0f);
updateThumb();
}
void setHighlightedRegion(ScrollbarHitRegion region) noexcept {
if (m_highlightedRegion == region)
return;
auto oldRegion = m_highlightedRegion;
m_highlightedRegion = region;
updateHighlight(oldRegion);
updateHighlight(m_highlightedRegion);
}
// Renders the text into our composition surface
void drawArrow(ScrollbarHitRegion region, bool disabled, bool hovered) noexcept {
if (auto outer = m_wkOuter.get()) {
auto &drawingSurface =
(region == ScrollbarHitRegion::ArrowFirst) ? m_arrowFirstDrawingSurface : m_arrowLastDrawingSurface;
if (!drawingSurface) {
drawingSurface = m_compContext.CreateDrawingSurfaceBrush(
{m_arrowSize, m_arrowSize},
winrt::Windows::Graphics::DirectX::DirectXPixelFormat::B8G8R8A8UIntNormalized,
winrt::Windows::Graphics::DirectX::DirectXAlphaMode::Premultiplied);
}
if (winrt::get_self<ScrollViewComponentView>(outer)->theme()->IsEmpty()) {
return;
}
winrt::com_ptr<IDWriteTextFormat> spTextFormat;
winrt::check_hresult(::Microsoft::ReactNative::DWriteFactory()->CreateTextFormat(
L"Segoe Fluent Icons",
nullptr, // Font collection (nullptr sets it to use the system font collection).
DWRITE_FONT_WEIGHT_REGULAR,
DWRITE_FONT_STYLE_NORMAL,
DWRITE_FONT_STRETCH_NORMAL,
8, // Xaml resource: ScrollBarButtonArrowIconFontSize
L"",
spTextFormat.put()));
winrt::check_hresult(spTextFormat->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_CENTER));
winrt::com_ptr<IDWriteTextLayout> spTextLayout;
winrt::check_hresult(::Microsoft::ReactNative::DWriteFactory()->CreateTextLayout(
m_vertical ? ((region == ScrollbarHitRegion::ArrowFirst) ? L"\uEDDB" : L"\uEDDC")
: ((region == ScrollbarHitRegion::ArrowFirst) ? L"\uEDD9" : L"\uEDDA"),
1, // The length of the string.
spTextFormat.get(), // The text format to apply to the string (contains font information, etc).
(m_arrowSize / m_scaleFactor), // The width of the layout box.
(m_arrowSize / m_scaleFactor), // The height of the layout box.
spTextLayout.put() // The IDWriteTextLayout interface pointer.
));
POINT offset;
{
::Microsoft::ReactNative::Composition::AutoDrawDrawingSurface autoDraw(drawingSurface, m_scaleFactor, &offset);
if (auto d2dDeviceContext = autoDraw.GetRenderTarget()) {
d2dDeviceContext->Clear(D2D1::ColorF(D2D1::ColorF::Black, 0.0f));
assert(d2dDeviceContext->GetUnitMode() == D2D1_UNIT_MODE_DIPS);
// Create a solid color brush for the text. A more sophisticated application might want
// to cache and reuse a brush across all text elements instead, taking care to recreate
// it in the event of device removed.
winrt::com_ptr<ID2D1SolidColorBrush> brush;
D2D1::ColorF color{0};
if (disabled) {
color = winrt::get_self<ScrollViewComponentView>(outer)->theme()->D2DPlatformColor(
"ScrollBarButtonArrowForegroundDisabled");
} else if (hovered) {
color = winrt::get_self<ScrollViewComponentView>(outer)->theme()->D2DPlatformColor(
"ScrollBarButtonArrowForegroundPointerOver");
} else {
color = winrt::get_self<ScrollViewComponentView>(outer)->theme()->D2DPlatformColor(
"ScrollBarButtonArrowForeground");
}
winrt::check_hresult(d2dDeviceContext->CreateSolidColorBrush(color, brush.put()));
{
DWRITE_TEXT_METRICS dtm{};
winrt::check_hresult(spTextLayout->GetMetrics(&dtm));
offset.y += static_cast<int>((m_arrowSize - dtm.height) / 2.0f);
}
// Draw the line of text at the specified offset, which corresponds to the top-left
// corner of our drawing surface. Notice we don't call BeginDraw on the D2D device
// context; this has already been done for us by the composition API.
d2dDeviceContext->DrawTextLayout(
D2D1::Point2F(
static_cast<FLOAT>((offset.x) / m_scaleFactor), static_cast<FLOAT>((offset.y) / m_scaleFactor)),
spTextLayout.get(),
brush.get(),
D2D1_DRAW_TEXT_OPTIONS_ENABLE_COLOR_FONT);
}
}
if (drawingSurface) {
drawingSurface.HorizontalAlignmentRatio(0.0f);
drawingSurface.VerticalAlignmentRatio(0.0f);
drawingSurface.Stretch(winrt::Microsoft::ReactNative::Composition::Experimental::CompositionStretch::None);
}
auto &arrowVisual = (region == ScrollbarHitRegion::ArrowFirst) ? m_arrowVisualFirst : m_arrowVisualLast;
arrowVisual.Brush(drawingSurface);
}
}
void updateHighlight(ScrollbarHitRegion region) noexcept {
if (auto outer = m_wkOuter.get()) {
switch (region) {
case ScrollbarHitRegion::ArrowFirst:
case ScrollbarHitRegion::ArrowLast: {
auto disabled = !std::static_pointer_cast<const facebook::react::ScrollViewProps>(
winrt::get_self<ScrollViewComponentView>(outer)->viewProps())
->scrollEnabled;
drawArrow(region, disabled, m_highlightedRegion == region);
}
case ScrollbarHitRegion::Thumb: {
if (!std::static_pointer_cast<const facebook::react::ScrollViewProps>(
winrt::get_self<ScrollViewComponentView>(outer)->viewProps())
->scrollEnabled) {
m_thumbVisual.Brush(
winrt::get_self<Theme>(outer.Theme())->InternalPlatformBrush(L"ScrollBarThumbFillDisabled"));
} else if (m_highlightedRegion == region) {
m_thumbVisual.Brush(
winrt::get_self<Theme>(outer.Theme())->InternalPlatformBrush(L"ScrollBarThumbFillPointerOver"));
} else {
m_thumbVisual.Brush(winrt::get_self<Theme>(outer.Theme())->InternalPlatformBrush(L"ScrollBarThumbFill"));
}
}
}
}
}
private:
winrt::weak_ref<winrt::Microsoft::ReactNative::Composition::ScrollViewComponentView> m_wkOuter;
winrt::Microsoft::ReactNative::Composition::Experimental::ICompositionContext m_compContext;
winrt::Microsoft::ReactNative::ReactContext m_reactContext;
const bool m_vertical;
bool m_visible{true};
bool m_shy{false};
int m_thumbSize{0};
float m_arrowSize{0};
float m_arrowMargin{0}; // margin on outside end of arrow buttons
float m_trackEdgeMargin{0}; // margin between track and edge of component
float m_trackMargin{0}; // margin of track background to ends of scrollbar
float m_thumbWidth{0};
float m_thumbShyWidth{0};
int m_minThumbSize{0};
float m_scaleFactor{1};
int m_thumbPos{0};
int m_nTrackInputOffset{-1};
ScrollbarHitRegion m_highlightedRegion{ScrollbarHitRegion::Unknown};
winrt::Windows::Foundation::Numerics::float3 m_offset{0};
winrt::Windows::Foundation::Size m_contentSize{0, 0};
winrt::Windows::Foundation::Size m_size{0, 0};
winrt::Microsoft::ReactNative::Composition::Experimental::ISpriteVisual m_rootVisual{nullptr};
winrt::Microsoft::ReactNative::Composition::Experimental::IRoundedRectangleVisual m_thumbVisual{nullptr};
winrt::Microsoft::ReactNative::Composition::Experimental::ISpriteVisual m_arrowVisualFirst{nullptr};
winrt::Microsoft::ReactNative::Composition::Experimental::ISpriteVisual m_arrowVisualLast{nullptr};
winrt::Microsoft::ReactNative::Composition::Experimental::IDrawingSurfaceBrush m_arrowFirstDrawingSurface{nullptr};
winrt::Microsoft::ReactNative::Composition::Experimental::IDrawingSurfaceBrush m_arrowLastDrawingSurface{nullptr};
winrt::Microsoft::ReactNative::Composition::Experimental::IRoundedRectangleVisual m_trackVisual{nullptr};
};
winrt::Microsoft::ReactNative::ComponentView ScrollViewComponentView::Create(
const winrt::Microsoft::ReactNative::Composition::Experimental::ICompositionContext &compContext,
facebook::react::Tag tag,
winrt::Microsoft::ReactNative::ReactContext const &reactContext) noexcept {
return winrt::make<ScrollViewComponentView>(compContext, tag, reactContext);
}
facebook::react::SharedViewProps ScrollViewComponentView::defaultProps() noexcept {
static auto const defaultViewProps = std::make_shared<facebook::react::ScrollViewProps const>();
return defaultViewProps;
}
ScrollViewComponentView::ScrollViewComponentView(
const winrt::Microsoft::ReactNative::Composition::Experimental::ICompositionContext &compContext,
facebook::react::Tag tag,
winrt::Microsoft::ReactNative::ReactContext const &reactContext)
: Super(
ScrollViewComponentView::defaultProps(),
compContext,
tag,
reactContext,
ComponentViewFeatures::Default & ~ComponentViewFeatures::Background) {
// m_element.Content(m_contentPanel);
/*
m_scrollViewerViewChangingRevoker =
m_element.ViewChanging(winrt::auto_revoke, [this](const auto &sender, const auto &args) {
const auto scrollViewerNotNull = sender.as<xaml::Controls::ScrollViewer>();
facebook::react::ScrollViewMetrics scrollMetrics;
scrollMetrics.containerSize.height = static_cast<facebook::react::Float>(m_element.ActualHeight());
scrollMetrics.containerSize.width = static_cast<facebook::react::Float>(m_element.ActualWidth());
scrollMetrics.contentOffset.x = static_cast<facebook::react::Float>(args.NextView().HorizontalOffset());
scrollMetrics.contentOffset.y = static_cast<facebook::react::Float>(args.NextView().VerticalOffset());
scrollMetrics.zoomScale = args.NextView().ZoomFactor();
scrollMetrics.contentSize.height = static_cast<facebook::react::Float>(m_contentPanel.ActualHeight());
scrollMetrics.contentSize.width = static_cast<facebook::react::Float>(m_contentPanel.ActualWidth());
// If we are transitioning to inertial scrolling.
if (m_isScrolling && !m_isScrollingFromInertia && args.IsInertial()) {
m_isScrollingFromInertia = true;
if (m_eventEmitter) {
std::static_pointer_cast<facebook::react::ScrollViewEventEmitter const>(m_eventEmitter)
->onScrollEndDrag(scrollMetrics);
std::static_pointer_cast<facebook::react::ScrollViewEventEmitter const>(m_eventEmitter)
->onMomentumScrollBegin(scrollMetrics);
}
}
if (m_eventEmitter) {
std::static_pointer_cast<facebook::react::ScrollViewEventEmitter const>(m_eventEmitter)
->onScroll(scrollMetrics);
}
});
m_scrollViewerDirectManipulationStartedRevoker =
m_element.DirectManipulationStarted(winrt::auto_revoke, [this](const auto &sender, const auto &) {
m_isScrolling = true;
//if (m_dismissKeyboardOnDrag && m_SIPEventHandler) {
// m_SIPEventHandler->TryHide();
//}
facebook::react::ScrollViewMetrics scrollMetrics;
scrollMetrics.containerSize.height = static_cast<facebook::react::Float>(m_element.ActualHeight());
scrollMetrics.containerSize.width = static_cast<facebook::react::Float>(m_element.ActualWidth());
scrollMetrics.contentOffset.x = static_cast<facebook::react::Float>(m_element.HorizontalOffset());
scrollMetrics.contentOffset.y = static_cast<facebook::react::Float>(m_element.VerticalOffset());
scrollMetrics.zoomScale = m_element.ZoomFactor();
scrollMetrics.contentSize.height = static_cast<facebook::react::Float>(m_contentPanel.ActualHeight());
scrollMetrics.contentSize.width = static_cast<facebook::react::Float>(m_contentPanel.ActualWidth());
const auto scrollViewer = sender.as<xaml::Controls::ScrollViewer>();
if (m_eventEmitter) {
std::static_pointer_cast<facebook::react::ScrollViewEventEmitter const>(m_eventEmitter)
->onScrollBeginDrag(scrollMetrics);
}
});
m_scrollViewerDirectManipulationCompletedRevoker =
m_element.DirectManipulationCompleted(winrt::auto_revoke, [this](const auto &sender, const auto &args) {
const auto scrollViewer = sender.as<xaml::Controls::ScrollViewer>();
facebook::react::ScrollViewMetrics scrollMetrics;
scrollMetrics.containerSize.height = static_cast<facebook::react::Float>(m_element.ActualHeight());
scrollMetrics.containerSize.width = static_cast<facebook::react::Float>(m_element.ActualWidth());
scrollMetrics.contentOffset.x = static_cast<facebook::react::Float>(m_element.HorizontalOffset());
scrollMetrics.contentOffset.y = static_cast<facebook::react::Float>(m_element.VerticalOffset());
scrollMetrics.zoomScale = m_element.ZoomFactor();
scrollMetrics.contentSize.height = static_cast<facebook::react::Float>(m_contentPanel.ActualHeight());
scrollMetrics.contentSize.width = static_cast<facebook::react::Float>(m_contentPanel.ActualWidth());
if (m_eventEmitter) {
if (m_isScrollingFromInertia) {
std::static_pointer_cast<facebook::react::ScrollViewEventEmitter const>(m_eventEmitter)
->onMomentumScrollEnd(scrollMetrics);
} else {
std::static_pointer_cast<facebook::react::ScrollViewEventEmitter const>(m_eventEmitter)
->onScrollEndDrag(scrollMetrics);
}
}
m_isScrolling = false;
m_isScrollingFromInertia = false;
});
*/
}
void ScrollViewComponentView::MountChildComponentView(
const winrt::Microsoft::ReactNative::ComponentView &childComponentView,
uint32_t index) noexcept {
// Call ComponentView::UnmountChildComponentView instead of base to handle out own Visual hosting
ComponentView::MountChildComponentView(childComponentView, index);
ensureVisual();
m_scrollVisual.InsertAt(
childComponentView.as<winrt::Microsoft::ReactNative::Composition::implementation::ComponentView>()->OuterVisual(),
index);
}
void ScrollViewComponentView::UnmountChildComponentView(
const winrt::Microsoft::ReactNative::ComponentView &childComponentView,
uint32_t index) noexcept {
// Call ComponentView::UnmountChildComponentView instead of base to handle out own Visual hosting
ComponentView::UnmountChildComponentView(childComponentView, index);
m_scrollVisual.Remove(childComponentView.as<ComponentView>()->OuterVisual());
}
void ScrollViewComponentView::updateBackgroundColor(const facebook::react::SharedColor &color) noexcept {
if (color) {
m_scrollVisual.Brush(theme()->Brush(*color));
} else {
m_scrollVisual.Brush(m_compContext.CreateColorBrush({0, 0, 0, 0}));
}
}
void ScrollViewComponentView::updateProps(
facebook::react::Props::Shared const &props,
facebook::react::Props::Shared const &oldProps) noexcept {
const auto &newViewProps = *std::static_pointer_cast<const facebook::react::ScrollViewProps>(props);
const auto &oldViewProps =
*std::static_pointer_cast<const facebook::react::ScrollViewProps>(oldProps ? oldProps : viewProps());
ensureVisual();
if (!oldProps || oldViewProps.backgroundColor != newViewProps.backgroundColor) {
updateBackgroundColor(newViewProps.backgroundColor);
}
// update BaseComponentView props
base_type::updateProps(props, oldProps);
// Update the color only after updating the m_props in BaseComponentView
// to avoid scrollbarcomponents reading outdated scrollEnabled value.
if (!oldProps || oldViewProps.scrollEnabled != newViewProps.scrollEnabled) {
m_scrollVisual.ScrollEnabled(newViewProps.scrollEnabled);
m_horizontalScrollbarComponent->UpdateColorForScrollBarRegions();
m_verticalScrollbarComponent->UpdateColorForScrollBarRegions();
}
if (!oldProps || oldViewProps.horizontal != newViewProps.horizontal) {
m_scrollVisual.Horizontal(newViewProps.horizontal);
}
if (!oldProps || oldViewProps.showsHorizontalScrollIndicator != newViewProps.showsHorizontalScrollIndicator) {
updateShowsHorizontalScrollIndicator(newViewProps.showsHorizontalScrollIndicator);
}
if (!oldProps || oldViewProps.showsVerticalScrollIndicator != newViewProps.showsVerticalScrollIndicator) {
updateShowsVerticalScrollIndicator(newViewProps.showsVerticalScrollIndicator);
}
if (!oldProps || oldViewProps.decelerationRate != newViewProps.decelerationRate) {
updateDecelerationRate(newViewProps.decelerationRate);
}
if (!oldProps || oldViewProps.scrollEventThrottle != newViewProps.scrollEventThrottle) {
// Zero means "send value only once per significant logical event".
// Prop value is in milliseconds.
auto throttleInSeconds = newViewProps.scrollEventThrottle / 1000.0;
auto msPerFrame = 1.0 / 60.0;
if (throttleInSeconds < 0) {
m_scrollEventThrottle = INFINITY;
} else if (throttleInSeconds <= msPerFrame) {
m_scrollEventThrottle = 0;
} else {
m_scrollEventThrottle = throttleInSeconds;
}
}
if (oldViewProps.maximumZoomScale != newViewProps.maximumZoomScale) {
m_scrollVisual.SetMaximumZoomScale(newViewProps.maximumZoomScale);
}
if (oldViewProps.minimumZoomScale != newViewProps.minimumZoomScale) {
m_scrollVisual.SetMinimumZoomScale(newViewProps.minimumZoomScale);
}
if (oldViewProps.zoomScale != newViewProps.zoomScale) {
m_scrollVisual.Scale({newViewProps.zoomScale, newViewProps.zoomScale, newViewProps.zoomScale});
}
if (oldViewProps.snapToStart != newViewProps.snapToStart || oldViewProps.snapToEnd != newViewProps.snapToEnd ||
oldViewProps.snapToOffsets != newViewProps.snapToOffsets) {
const auto snapToOffsets = winrt::single_threaded_vector<float>();
for (const auto &offset : newViewProps.snapToOffsets) {
snapToOffsets.Append(static_cast<float>(offset));
}
m_scrollVisual.SetSnapPoints(newViewProps.snapToStart, newViewProps.snapToEnd, snapToOffsets.GetView());
}
if (!oldProps || oldViewProps.pagingEnabled != newViewProps.pagingEnabled) {
m_scrollVisual.PagingEnabled(newViewProps.pagingEnabled);
}
if (!oldProps || oldViewProps.snapToInterval != newViewProps.snapToInterval) {
m_scrollVisual.SnapToInterval(static_cast<float>(newViewProps.snapToInterval));
}
if (!oldProps || oldViewProps.snapToAlignment != newViewProps.snapToAlignment) {
using SnapPointsAlignment = winrt::Microsoft::ReactNative::Composition::Experimental::SnapPointsAlignment;
SnapPointsAlignment alignment = SnapPointsAlignment::Near; // default is "start"
if (newViewProps.snapToAlignment == facebook::react::ScrollViewSnapToAlignment::Center) {
alignment = SnapPointsAlignment::Center;
} else if (newViewProps.snapToAlignment == facebook::react::ScrollViewSnapToAlignment::End) {
alignment = SnapPointsAlignment::Far;
}
m_scrollVisual.SnapToAlignment(alignment);
}
}
void ScrollViewComponentView::updateState(
facebook::react::State::Shared const &state,
facebook::react::State::Shared const &oldState) noexcept {
m_state = std::static_pointer_cast<facebook::react::ScrollViewShadowNode::ConcreteState const>(state);
m_contentSize = m_state->getData().getContentSize();
updateContentVisualSize();
}
void ScrollViewComponentView::updateStateWithContentOffset() noexcept {
if (!m_state) {
return;
}
auto scrollPosition = m_scrollVisual.ScrollPosition();
m_verticalScrollbarComponent->ContentOffset(scrollPosition);
m_horizontalScrollbarComponent->ContentOffset(scrollPosition);
m_state->updateState([scrollPosition](const facebook::react::ScrollViewShadowNode::ConcreteState::Data &data) {
auto newData = data;
newData.contentOffset = {scrollPosition.x, scrollPosition.y};
return std::make_shared<facebook::react::ScrollViewShadowNode::ConcreteState::Data const>(newData);
});
}
void ScrollViewComponentView::updateLayoutMetrics(
facebook::react::LayoutMetrics const &layoutMetrics,
facebook::react::LayoutMetrics const &oldLayoutMetrics) noexcept {
// Set Position & Size Properties
ensureVisual();
if (oldLayoutMetrics != layoutMetrics) {
m_verticalScrollbarComponent->updateLayoutMetrics(layoutMetrics);
m_horizontalScrollbarComponent->updateLayoutMetrics(layoutMetrics);
base_type::updateLayoutMetrics(layoutMetrics, oldLayoutMetrics);
m_scrollVisual.Size(
{layoutMetrics.frame.size.width * layoutMetrics.pointScaleFactor,
layoutMetrics.frame.size.height * layoutMetrics.pointScaleFactor});
updateContentVisualSize();
}
}
void ScrollViewComponentView::updateContentVisualSize() noexcept {
winrt::Windows::Foundation::Size contentSize = {
std::max(m_contentSize.width, m_layoutMetrics.frame.size.width) * m_layoutMetrics.pointScaleFactor,
std::max(m_contentSize.height, m_layoutMetrics.frame.size.height) * m_layoutMetrics.pointScaleFactor};
m_verticalScrollbarComponent->ContentSize(contentSize);
m_horizontalScrollbarComponent->ContentSize(contentSize);
m_scrollVisual.ContentSize(contentSize);
}
void ScrollViewComponentView::prepareForRecycle() noexcept {}
void ScrollViewComponentView::updateChildrenClippingPath(
facebook::react::LayoutMetrics const & /*layoutMetrics*/,
const facebook::react::ViewProps & /*viewProps*/) noexcept {
// No-op: ScrollView mounts children into m_scrollVisual (not Visual()),
// and scroll visuals inherently clip their content.
}
/*
ScrollViewComponentView::ScrollInteractionTrackerOwner::ScrollInteractionTrackerOwner(
ScrollViewComponentView *outer)
: m_outer(outer) {}
void ScrollViewComponentView::ScrollInteractionTrackerOwner::CustomAnimationStateEntered(
winrt::Windows::UI::Composition::Interactions::InteractionTracker sender,
winrt::Windows::UI::Composition::Interactions::InteractionTrackerCustomAnimationStateEnteredArgs args) noexcept {}
void ScrollViewComponentView::ScrollInteractionTrackerOwner::IdleStateEntered(
winrt::Windows::UI::Composition::Interactions::InteractionTracker sender,
winrt::Windows::UI::Composition::Interactions::InteractionTrackerIdleStateEnteredArgs args) noexcept {}
void ScrollViewComponentView::ScrollInteractionTrackerOwner::InertiaStateEntered(
winrt::Windows::UI::Composition::Interactions::InteractionTracker sender,
winrt::Windows::UI::Composition::Interactions::InteractionTrackerInertiaStateEnteredArgs args) noexcept {}
void ScrollViewComponentView::ScrollInteractionTrackerOwner::InteractingStateEntered(
winrt::Windows::UI::Composition::Interactions::InteractionTracker sender,
winrt::Windows::UI::Composition::Interactions::InteractionTrackerInteractingStateEnteredArgs args) noexcept {}
void ScrollViewComponentView::ScrollInteractionTrackerOwner::RequestIgnored(
winrt::Windows::UI::Composition::Interactions::InteractionTracker sender,
winrt::Windows::UI::Composition::Interactions::InteractionTrackerRequestIgnoredArgs args) noexcept {}
void ScrollViewComponentView::ScrollInteractionTrackerOwner::ValuesChanged(
winrt::Windows::UI::Composition::Interactions::InteractionTracker sender,
winrt::Windows::UI::Composition::Interactions::InteractionTrackerValuesChangedArgs args) noexcept {
auto eventEmitter = m_outer->GetEventEmitter();
if (eventEmitter) {
facebook::react::ScrollViewMetrics scrollMetrics;
scrollMetrics.containerSize.height = m_outer->Visual().Size().y / m_outer->m_layoutMetrics.pointScaleFactor;
scrollMetrics.containerSize.width = m_outer->Visual().Size().x / m_outer->m_layoutMetrics.pointScaleFactor;
scrollMetrics.contentOffset.x = args.Position().x / m_outer->m_layoutMetrics.pointScaleFactor;
scrollMetrics.contentOffset.y = args.Position().y / m_outer->m_layoutMetrics.pointScaleFactor;
scrollMetrics.zoomScale = m_outer->ContentVisual().Scale().x;
scrollMetrics.contentSize.height = m_outer->ContentVisual().Size().y / m_outer->m_layoutMetrics.pointScaleFactor;
scrollMetrics.contentSize.width = m_outer->ContentVisual().Size().x / m_outer->m_layoutMetrics.pointScaleFactor;
std::static_pointer_cast<facebook::react::ScrollViewEventEmitter const>(eventEmitter)->onScroll(scrollMetrics);
}
}
*/
/*
void ScrollViewComponentView::OnPointerDown(const winrt::Windows::UI::Input::PointerPoint &pp) noexcept {
m_visualInteractionSource.TryRedirectForManipulation(pp);
}
*/
void ScrollViewComponentView::onThemeChanged() noexcept {
updateBackgroundColor(std::static_pointer_cast<const facebook::react::ScrollViewProps>(viewProps())->backgroundColor);
m_verticalScrollbarComponent->UpdateColorForScrollBarRegions();
m_horizontalScrollbarComponent->UpdateColorForScrollBarRegions();
Super::onThemeChanged();
}
void ScrollViewComponentView::OnPointerWheelChanged(
const winrt::Microsoft::ReactNative::Composition::Input::PointerRoutedEventArgs &args) noexcept {
auto ppp = args.GetCurrentPoint(-1).Properties();
auto delta = static_cast<float>(ppp.MouseWheelDelta());
if (ppp.IsHorizontalMouseWheel()) {
if (delta > 0) {
if (scrollLeft(delta * m_layoutMetrics.pointScaleFactor, true)) {
args.Handled(true);
}
} else if (delta < 0) {
if (scrollRight(-delta * m_layoutMetrics.pointScaleFactor, true)) {
args.Handled(true);
}
}
} else {
if (delta > 0) {
if (scrollUp(delta * m_layoutMetrics.pointScaleFactor, true)) {
args.Handled(true);
}
} else if (delta < 0) {
if (scrollDown(-delta * m_layoutMetrics.pointScaleFactor, true)) {
args.Handled(true);
}
}
}
Super::OnPointerWheelChanged(args);
}
void ScrollViewComponentView::OnPointerPressed(
const winrt::Microsoft::ReactNative::Composition::Input::PointerRoutedEventArgs &args) noexcept {
m_verticalScrollbarComponent->OnPointerPressed(args);
m_horizontalScrollbarComponent->OnPointerPressed(args);
Super::OnPointerPressed(args);
if (!args.Handled()) {
auto f = args.Pointer();
auto g = f.PointerDeviceType();
m_scrollVisual.OnPointerPressed(args);
}
}
void ScrollViewComponentView::OnPointerReleased(
const winrt::Microsoft::ReactNative::Composition::Input::PointerRoutedEventArgs &args) noexcept {
m_verticalScrollbarComponent->OnPointerReleased(args);
m_horizontalScrollbarComponent->OnPointerReleased(args);
Super::OnPointerReleased(args);
}
void ScrollViewComponentView::OnPointerMoved(
const winrt::Microsoft::ReactNative::Composition::Input::PointerRoutedEventArgs &args) noexcept {
m_verticalScrollbarComponent->OnPointerMoved(args);