react-native-windows 0.0.0-canary.461 → 0.0.0-canary.464

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/Libraries/Pressability/Pressability.windows.js +5 -5
  2. package/Microsoft.ReactNative/Fabric/ComponentView.h +1 -0
  3. package/Microsoft.ReactNative/Fabric/ComponentViewRegistry.cpp +8 -1
  4. package/Microsoft.ReactNative/Fabric/FabricUIManagerModule.cpp +29 -1
  5. package/Microsoft.ReactNative/Fabric/SliderComponentView.cpp +107 -0
  6. package/Microsoft.ReactNative/Fabric/SliderComponentView.h +51 -0
  7. package/Microsoft.ReactNative/Fabric/SwitchComponentView.cpp +109 -0
  8. package/Microsoft.ReactNative/Fabric/SwitchComponentView.h +52 -0
  9. package/Microsoft.ReactNative/Fabric/ViewComponentView.cpp +4 -0
  10. package/Microsoft.ReactNative/Fabric/ViewComponentView.h +1 -0
  11. package/Microsoft.ReactNative/Fabric/platform/react/renderer/components/rncore/EventEmitters.h +5 -0
  12. package/Microsoft.ReactNative/Fabric/platform/react/renderer/components/rncore/Props.h +5 -0
  13. package/Microsoft.ReactNative/Fabric/platform/react/renderer/components/slider/SliderMeasurementsManager.cpp +35 -0
  14. package/Microsoft.ReactNative/Fabric/platform/react/renderer/components/slider/SliderMeasurementsManager.h +30 -0
  15. package/Microsoft.ReactNative/Fabric/platform/react/renderer/textlayoutmanager/TextLayoutManager.cpp +50 -49
  16. package/Microsoft.ReactNative/Fabric/platform/react/renderer/textlayoutmanager/TextLayoutManager.h +3 -0
  17. package/Microsoft.ReactNative/IViewManager.idl +10 -2
  18. package/Microsoft.ReactNative/Microsoft.ReactNative.vcxproj +6 -0
  19. package/Microsoft.ReactNative/Views/SliderViewManager.cpp +12 -4
  20. package/Microsoft.ReactNative/Views/TouchEventHandler.cpp +22 -13
  21. package/Microsoft.ReactNative.Managed/packages.lock.json +1 -1
  22. package/{template/cs-app/proj/Directory.Build.props → PropertySheets/CppEnablePackageReferences.props} +0 -0
  23. package/PropertySheets/External/Microsoft.ReactNative.CSharp.PackageReferences.props +12 -0
  24. package/PropertySheets/External/{Microsoft.ReactNative.Uwp.CSharpApp.SourceReferences.targets → Microsoft.ReactNative.CSharp.ProjectReferences.props} +2 -2
  25. package/PropertySheets/External/Microsoft.ReactNative.Common.props +3 -0
  26. package/PropertySheets/External/Microsoft.ReactNative.Cpp.PackageReferences.props +12 -0
  27. package/PropertySheets/External/{Microsoft.ReactNative.Uwp.CppApp.SourceReferences.targets → Microsoft.ReactNative.Cpp.ProjectReferences.props} +1 -0
  28. package/PropertySheets/External/Microsoft.ReactNative.Uwp.CSharpApp.targets +6 -2
  29. package/PropertySheets/External/Microsoft.ReactNative.Uwp.CSharpLib.targets +5 -12
  30. package/PropertySheets/External/Microsoft.ReactNative.Uwp.CppApp.targets +5 -2
  31. package/PropertySheets/External/Microsoft.ReactNative.Uwp.CppLib.props +1 -1
  32. package/PropertySheets/External/Microsoft.ReactNative.Uwp.CppLib.targets +5 -9
  33. package/PropertySheets/Generated/PackageVersion.g.props +1 -1
  34. package/PropertySheets/OutputMSBuildProperties.targets +31 -0
  35. package/Scripts/rnw-dependencies.ps1 +41 -10
  36. package/codegen/react/components/rnwcore/EventEmitters.cpp +149 -0
  37. package/package.json +4 -4
  38. package/template/shared-lib/proj/ExperimentalFeatures.props +29 -1
  39. package/typings-index.js +5 -1
  40. package/typings-index.js.map +1 -1
  41. package/template/cs-lib/proj/Directory.Build.props +0 -13
@@ -486,7 +486,6 @@ export default class Pressability {
486
486
 
487
487
  onResponderGrant: (event: PressEvent): void => {
488
488
  event.persist();
489
-
490
489
  this._cancelPressOutDelayTimeout();
491
490
 
492
491
  this._responderID = event.currentTarget;
@@ -771,7 +770,8 @@ export default class Pressability {
771
770
  this._deactivate(event);
772
771
  }
773
772
  const {onLongPress, onPress, android_disableSound} = this._config;
774
- if (onPress != null) {
773
+
774
+ if (onPress != null && getTouchFromPressEvent(event).button === 0) {
775
775
  const isPressCanceledByLongPress =
776
776
  onLongPress != null &&
777
777
  prevState === 'RESPONDER_ACTIVE_LONG_PRESS_IN' &&
@@ -790,17 +790,17 @@ export default class Pressability {
790
790
 
791
791
  _activate(event: PressEvent): void {
792
792
  const {onPressIn} = this._config;
793
- const {pageX, pageY} = getTouchFromPressEvent(event);
793
+ const {pageX, pageY, button} = getTouchFromPressEvent(event);
794
794
  this._touchActivatePosition = {pageX, pageY};
795
795
  this._touchActivateTime = Date.now();
796
- if (onPressIn != null) {
796
+ if (onPressIn != null && button === 0) {
797
797
  onPressIn(event);
798
798
  }
799
799
  }
800
800
 
801
801
  _deactivate(event: PressEvent): void {
802
802
  const {onPressOut} = this._config;
803
- if (onPressOut != null) {
803
+ if (onPressOut != null && getTouchFromPressEvent(event).button === 0) {
804
804
  const minPressDuration = normalizeDelay(
805
805
  this._config.minPressDuration,
806
806
  0,
@@ -39,6 +39,7 @@ struct IComponentView {
39
39
  virtual void finalizeUpdates(RNComponentViewUpdateMask updateMask) noexcept = 0;
40
40
  virtual void prepareForRecycle() noexcept = 0;
41
41
  virtual facebook::react::SharedProps props() noexcept = 0;
42
+ virtual void handleCommand(std::string const &commandName, folly::dynamic const &arg) noexcept = 0;
42
43
  };
43
44
 
44
45
  } // namespace Microsoft::ReactNative
@@ -13,6 +13,7 @@
13
13
  #include <react/components/rnwcore/ShadowNodes.h>
14
14
  #include <react/renderer/components/image/ImageShadowNode.h>
15
15
  #include <react/renderer/components/root/RootShadowNode.h>
16
+ #include <react/renderer/components/slider/SliderShadowNode.h>
16
17
  #include <react/renderer/components/text/ParagraphShadowNode.h>
17
18
  #include <react/renderer/components/text/RawTextShadowNode.h>
18
19
  #include <react/renderer/components/text/TextShadowNode.h>
@@ -23,6 +24,8 @@
23
24
  #include "ImageComponentView.h"
24
25
  #include "ParagraphComponentView.h"
25
26
  #include "ScrollViewComponentView.h"
27
+ #include "SliderComponentView.h"
28
+ #include "SwitchComponentView.h"
26
29
  #include "TextComponentView.h"
27
30
  #include "ViewComponentView.h"
28
31
  #include "XamlView.h"
@@ -48,6 +51,10 @@ ComponentViewDescriptor const &ComponentViewRegistry::dequeueComponentViewWithCo
48
51
  view = std::make_shared<ScrollViewComponentView>();
49
52
  } else if (componentHandle == facebook::react::ImageShadowNode::Handle()) {
50
53
  view = std::make_shared<ImageComponentView>(m_context);
54
+ } else if (componentHandle == facebook::react::SliderShadowNode::Handle()) {
55
+ view = std::make_shared<SliderComponentView>(m_context);
56
+ } else if (componentHandle == facebook::react::SwitchShadowNode::Handle()) {
57
+ view = std::make_shared<SwitchComponentView>(m_context);
51
58
  } else if (componentHandle == facebook::react::ActivityIndicatorViewShadowNode::Handle()) {
52
59
  view = std::make_shared<ActivityIndicatorComponentView>();
53
60
  } else {
@@ -80,6 +87,6 @@ void ComponentViewRegistry::enqueueComponentViewWithComponentHandle(
80
87
  assert(m_registry.find(tag) != m_registry.end());
81
88
 
82
89
  m_registry.erase(tag);
83
- SetTag(static_cast<ViewComponentView &>(*componentViewDescriptor.view).Element(), nullptr);
90
+ SetTag(static_cast<ViewComponentView &>(*componentViewDescriptor.view).Element(), InvalidTag);
84
91
  }
85
92
  } // namespace Microsoft::ReactNative
@@ -17,6 +17,7 @@
17
17
  #include <react/components/rnwcore/ComponentDescriptors.h>
18
18
  #include <react/renderer/componentregistry/ComponentDescriptorProviderRegistry.h>
19
19
  #include <react/renderer/components/image/ImageComponentDescriptor.h>
20
+ #include <react/renderer/components/slider/SliderComponentDescriptor.h>
20
21
  #include <react/renderer/components/text/ParagraphComponentDescriptor.h>
21
22
  #include <react/renderer/components/text/RawTextComponentDescriptor.h>
22
23
  #include <react/renderer/components/text/TextComponentDescriptor.h>
@@ -142,6 +143,10 @@ std::shared_ptr<facebook::react::ComponentDescriptorProviderRegistry const> shar
142
143
  facebook::react::concreteComponentDescriptorProvider<facebook::react::RawTextComponentDescriptor>());
143
144
  providerRegistry->add(
144
145
  facebook::react::concreteComponentDescriptorProvider<facebook::react::ScrollViewComponentDescriptor>());
146
+ providerRegistry->add(
147
+ facebook::react::concreteComponentDescriptorProvider<facebook::react::SliderComponentDescriptor>());
148
+ providerRegistry->add(
149
+ facebook::react::concreteComponentDescriptorProvider<facebook::react::SwitchComponentDescriptor>());
145
150
  providerRegistry->add(
146
151
  facebook::react::concreteComponentDescriptorProvider<facebook::react::TextComponentDescriptor>());
147
152
  providerRegistry->add(
@@ -200,6 +205,9 @@ void FabricUIManager::installFabricUIManager() noexcept {
200
205
  toolbox.runtimeExecutor = runtimeExecutor;
201
206
  toolbox.synchronousEventBeatFactory = synchronousBeatFactory;
202
207
  toolbox.asynchronousEventBeatFactory = asynchronousBeatFactory;
208
+ // We currently rely on using XAML elements to perform measure/layout,
209
+ // which requires that the background thread also be the UI thread
210
+ /*
203
211
  toolbox.backgroundExecutor = [context = m_context,
204
212
  dispatcher = Mso::DispatchQueue::MakeLooperQueue()](std::function<void()> &&callback) {
205
213
  if (context.UIDispatcher().HasThreadAccess()) {
@@ -209,6 +217,15 @@ void FabricUIManager::installFabricUIManager() noexcept {
209
217
 
210
218
  dispatcher.Post(std::move(callback));
211
219
  };
220
+ */
221
+ toolbox.backgroundExecutor = [context = m_context](std::function<void()> &&callback) {
222
+ if (context.UIDispatcher().HasThreadAccess()) {
223
+ callback();
224
+ return;
225
+ }
226
+
227
+ context.UIDispatcher().Post(std::move(callback));
228
+ };
212
229
 
213
230
  m_scheduler = std::make_shared<facebook::react::Scheduler>(
214
231
  toolbox, (/*animationDriver_ ? animationDriver_.get() :*/ nullptr), this);
@@ -477,7 +494,18 @@ void FabricUIManager::schedulerDidDispatchCommand(
477
494
  facebook::react::ShadowView const &shadowView,
478
495
  std::string const &commandName,
479
496
  folly::dynamic const &arg) {
480
- assert(false);
497
+ if (m_context.UIDispatcher().HasThreadAccess()) {
498
+ auto descriptor = m_registry.componentViewDescriptorWithTag(shadowView.tag);
499
+ descriptor.view->handleCommand(commandName, arg);
500
+ } else {
501
+ m_context.UIDispatcher().Post(
502
+ [wkThis = weak_from_this(), commandName, tag = shadowView.tag, args = folly::dynamic(arg)]() {
503
+ if (auto pThis = wkThis.lock()) {
504
+ auto descriptor = pThis->m_registry.componentViewDescriptorWithTag(tag);
505
+ descriptor.view->handleCommand(commandName, args);
506
+ }
507
+ });
508
+ }
481
509
  }
482
510
 
483
511
  void FabricUIManager::schedulerDidSetIsJSResponder(
@@ -0,0 +1,107 @@
1
+
2
+ // Copyright (c) Microsoft Corporation.
3
+ // Licensed under the MIT License.
4
+
5
+ #pragma once
6
+
7
+ #include "SliderComponentView.h"
8
+
9
+ #include <UI.Xaml.Controls.Primitives.h>
10
+ #include <Utils/ValueUtils.h>
11
+
12
+ #include <IReactContext.h>
13
+
14
+ #include <react/renderer/components/rnwcore/EventEmitters.h>
15
+
16
+ namespace Microsoft::ReactNative {
17
+
18
+ SliderComponentView::SliderComponentView(winrt::Microsoft::ReactNative::ReactContext const &reactContext)
19
+ : m_context(reactContext), m_element(xaml::Controls::Slider()) {
20
+ m_valueChangedRevoker = m_element.ValueChanged(winrt::auto_revoke, [this](auto sender, auto args) {
21
+ if (m_props->value != m_element.Value()) {
22
+ if (m_eventEmitter) {
23
+ auto emitter = std::static_pointer_cast<const facebook::react::SliderEventEmitter>(m_eventEmitter);
24
+ facebook::react::SliderEventEmitter::OnValueChange onValueChangeArgs;
25
+ onValueChangeArgs.value = m_element.Value();
26
+ emitter->onValueChange(onValueChangeArgs);
27
+ }
28
+ }
29
+ });
30
+
31
+ static auto const defaultProps = std::make_shared<facebook::react::SliderProps const>();
32
+ m_props = defaultProps;
33
+ }
34
+
35
+ std::vector<facebook::react::ComponentDescriptorProvider>
36
+ SliderComponentView::supplementalComponentDescriptorProviders() noexcept {
37
+ return {};
38
+ }
39
+
40
+ void SliderComponentView::mountChildComponentView(const IComponentView &childComponentView, uint32_t index) noexcept {
41
+ assert(false);
42
+ // m_element->Children().InsertAt(index, static_cast<const BaseComponentView &>(childComponentView).Element());
43
+ }
44
+
45
+ void SliderComponentView::unmountChildComponentView(const IComponentView &childComponentView, uint32_t index) noexcept {
46
+ assert(false);
47
+ // m_element->Children().RemoveAt(index);
48
+ }
49
+
50
+ void SliderComponentView::updateProps(
51
+ facebook::react::Props::Shared const &props,
52
+ facebook::react::Props::Shared const &oldProps) noexcept {
53
+ const auto &oldSliderProps = *std::static_pointer_cast<const facebook::react::SliderProps>(m_props);
54
+ const auto &newSliderProps = *std::static_pointer_cast<const facebook::react::SliderProps>(props);
55
+
56
+ if (oldSliderProps.value != newSliderProps.value) {
57
+ m_element.Value(newSliderProps.value);
58
+ }
59
+
60
+ if (oldSliderProps.maximumValue != newSliderProps.maximumValue) {
61
+ m_element.Maximum(newSliderProps.maximumValue);
62
+ }
63
+
64
+ if (oldSliderProps.minimumValue != newSliderProps.minimumValue) {
65
+ m_element.Minimum(newSliderProps.minimumValue);
66
+ }
67
+
68
+ if (oldSliderProps.disabled != newSliderProps.disabled) {
69
+ m_element.IsEnabled(!newSliderProps.disabled);
70
+ }
71
+
72
+ // TODO tint colors
73
+
74
+ m_props = std::static_pointer_cast<facebook::react::SliderProps const>(props);
75
+ }
76
+
77
+ void SliderComponentView::updateState(
78
+ facebook::react::State::Shared const &state,
79
+ facebook::react::State::Shared const &oldState) noexcept {}
80
+
81
+ void SliderComponentView::updateLayoutMetrics(
82
+ facebook::react::LayoutMetrics const &layoutMetrics,
83
+ facebook::react::LayoutMetrics const &oldLayoutMetrics) noexcept {
84
+ // Set Position & Size Properties
85
+
86
+ m_layoutMetrics = layoutMetrics;
87
+
88
+ winrt::Microsoft::ReactNative::ViewPanel::SetLeft(m_element, layoutMetrics.frame.origin.x);
89
+ winrt::Microsoft::ReactNative::ViewPanel::SetTop(m_element, layoutMetrics.frame.origin.y);
90
+
91
+ m_element.Width(layoutMetrics.frame.size.width);
92
+ m_element.Height(layoutMetrics.frame.size.height);
93
+ }
94
+
95
+ void SliderComponentView::finalizeUpdates(RNComponentViewUpdateMask updateMask) noexcept {}
96
+
97
+ void SliderComponentView::prepareForRecycle() noexcept {}
98
+ facebook::react::SharedProps SliderComponentView::props() noexcept {
99
+ assert(false);
100
+ return {};
101
+ }
102
+
103
+ const xaml::FrameworkElement SliderComponentView::Element() const noexcept {
104
+ return m_element;
105
+ }
106
+
107
+ } // namespace Microsoft::ReactNative
@@ -0,0 +1,51 @@
1
+
2
+ // Copyright (c) Microsoft Corporation.
3
+ // Licensed under the MIT License.
4
+
5
+ #pragma once
6
+
7
+ #include "ComponentView.h"
8
+
9
+ #include <Microsoft.ReactNative.Cxx/ReactContext.h>
10
+ #include <UI.Xaml.Controls.h>
11
+ #include <react/renderer/components/rnwcore/Props.h>
12
+ #include "ViewComponentView.h"
13
+
14
+ #pragma warning(push)
15
+ #pragma warning(disable : 4244 4305)
16
+ //#include <react/renderer/components/view/ViewProps.h>
17
+ #pragma warning(pop)
18
+
19
+ namespace Microsoft::ReactNative {
20
+
21
+ struct SliderComponentView : BaseComponentView {
22
+ using Super = BaseComponentView;
23
+ SliderComponentView(winrt::Microsoft::ReactNative::ReactContext const &reactContext);
24
+
25
+ std::vector<facebook::react::ComponentDescriptorProvider> supplementalComponentDescriptorProviders() noexcept
26
+ override;
27
+ void mountChildComponentView(const IComponentView &childComponentView, uint32_t index) noexcept override;
28
+ void unmountChildComponentView(const IComponentView &childComponentView, uint32_t index) noexcept override;
29
+ void updateProps(facebook::react::Props::Shared const &props, facebook::react::Props::Shared const &oldProps) noexcept
30
+ override;
31
+ void updateState(facebook::react::State::Shared const &state, facebook::react::State::Shared const &oldState) noexcept
32
+ override;
33
+ void updateLayoutMetrics(
34
+ facebook::react::LayoutMetrics const &layoutMetrics,
35
+ facebook::react::LayoutMetrics const &oldLayoutMetrics) noexcept override;
36
+ void finalizeUpdates(RNComponentViewUpdateMask updateMask) noexcept override;
37
+ void prepareForRecycle() noexcept override;
38
+ facebook::react::SharedProps props() noexcept override;
39
+
40
+ const xaml::FrameworkElement Element() const noexcept override;
41
+
42
+ private:
43
+ bool m_needsOnLoadStart{false};
44
+ std::shared_ptr<facebook::react::SliderProps const> m_props;
45
+ facebook::react::LayoutMetrics m_layoutMetrics;
46
+ xaml::Controls::Slider m_element;
47
+ xaml::Controls::Slider::ValueChanged_revoker m_valueChangedRevoker;
48
+ winrt::Microsoft::ReactNative::ReactContext m_context;
49
+ };
50
+
51
+ } // namespace Microsoft::ReactNative
@@ -0,0 +1,109 @@
1
+
2
+ // Copyright (c) Microsoft Corporation.
3
+ // Licensed under the MIT License.
4
+
5
+ #pragma once
6
+
7
+ #include "SwitchComponentView.h"
8
+
9
+ #include <Utils/ValueUtils.h>
10
+
11
+ #include <IReactContext.h>
12
+
13
+ #include <react/renderer/components/rnwcore/EventEmitters.h>
14
+
15
+ namespace Microsoft::ReactNative {
16
+
17
+ SwitchComponentView::SwitchComponentView(winrt::Microsoft::ReactNative::ReactContext const &reactContext)
18
+ : m_context(reactContext), m_element(xaml::Controls::ToggleSwitch()) {
19
+ m_element.OnContent(nullptr);
20
+ m_element.OffContent(nullptr);
21
+
22
+ m_toggledRevoker = m_element.Toggled(winrt::auto_revoke, [this](auto sender, auto args) {
23
+ if (m_props->value != m_element.IsOn()) {
24
+ if (m_eventEmitter) {
25
+ auto emitter = std::static_pointer_cast<const facebook::react::SwitchEventEmitter>(m_eventEmitter);
26
+ facebook::react::SwitchEventEmitter::OnChange onChangeArgs;
27
+ onChangeArgs.value = m_element.IsOn();
28
+ emitter->onChange(onChangeArgs);
29
+ }
30
+ }
31
+ });
32
+
33
+ static auto const defaultProps = std::make_shared<facebook::react::SwitchProps const>();
34
+ m_props = defaultProps;
35
+ }
36
+
37
+ void SwitchComponentView::handleCommand(std::string const &commandName, folly::dynamic const &arg) noexcept {
38
+ if (commandName == "setValue") {
39
+ m_element.IsOn(arg[0].asBool());
40
+ } else {
41
+ Super::handleCommand(commandName, arg);
42
+ }
43
+ }
44
+
45
+ std::vector<facebook::react::ComponentDescriptorProvider>
46
+ SwitchComponentView::supplementalComponentDescriptorProviders() noexcept {
47
+ return {};
48
+ }
49
+
50
+ void SwitchComponentView::mountChildComponentView(const IComponentView &childComponentView, uint32_t index) noexcept {
51
+ assert(false);
52
+ // m_element->Children().InsertAt(index, static_cast<const BaseComponentView &>(childComponentView).Element());
53
+ }
54
+
55
+ void SwitchComponentView::unmountChildComponentView(const IComponentView &childComponentView, uint32_t index) noexcept {
56
+ assert(false);
57
+ // m_element->Children().RemoveAt(index);
58
+ }
59
+
60
+ void SwitchComponentView::updateProps(
61
+ facebook::react::Props::Shared const &props,
62
+ facebook::react::Props::Shared const &oldProps) noexcept {
63
+ const auto &oldSwitchProps = *std::static_pointer_cast<const facebook::react::SwitchProps>(m_props);
64
+ const auto &newSwitchProps = *std::static_pointer_cast<const facebook::react::SwitchProps>(props);
65
+
66
+ if (oldSwitchProps.value != newSwitchProps.value) {
67
+ m_element.IsOn(newSwitchProps.value);
68
+ }
69
+
70
+ if (oldSwitchProps.disabled != newSwitchProps.disabled) {
71
+ m_element.IsEnabled(!newSwitchProps.disabled);
72
+ }
73
+
74
+ // TODO tint colors
75
+
76
+ m_props = std::static_pointer_cast<facebook::react::SwitchProps const>(props);
77
+ }
78
+
79
+ void SwitchComponentView::updateState(
80
+ facebook::react::State::Shared const &state,
81
+ facebook::react::State::Shared const &oldState) noexcept {}
82
+
83
+ void SwitchComponentView::updateLayoutMetrics(
84
+ facebook::react::LayoutMetrics const &layoutMetrics,
85
+ facebook::react::LayoutMetrics const &oldLayoutMetrics) noexcept {
86
+ // Set Position & Size Properties
87
+
88
+ m_layoutMetrics = layoutMetrics;
89
+
90
+ winrt::Microsoft::ReactNative::ViewPanel::SetLeft(m_element, layoutMetrics.frame.origin.x);
91
+ winrt::Microsoft::ReactNative::ViewPanel::SetTop(m_element, layoutMetrics.frame.origin.y);
92
+
93
+ m_element.Width(layoutMetrics.frame.size.width);
94
+ m_element.Height(layoutMetrics.frame.size.height);
95
+ }
96
+
97
+ void SwitchComponentView::finalizeUpdates(RNComponentViewUpdateMask updateMask) noexcept {}
98
+
99
+ void SwitchComponentView::prepareForRecycle() noexcept {}
100
+ facebook::react::SharedProps SwitchComponentView::props() noexcept {
101
+ assert(false);
102
+ return {};
103
+ }
104
+
105
+ const xaml::FrameworkElement SwitchComponentView::Element() const noexcept {
106
+ return m_element;
107
+ }
108
+
109
+ } // namespace Microsoft::ReactNative
@@ -0,0 +1,52 @@
1
+
2
+ // Copyright (c) Microsoft Corporation.
3
+ // Licensed under the MIT License.
4
+
5
+ #pragma once
6
+
7
+ #include "ComponentView.h"
8
+
9
+ #include <Microsoft.ReactNative.Cxx/ReactContext.h>
10
+ #include <UI.Xaml.Controls.h>
11
+ #include <react/renderer/components/rnwcore/Props.h>
12
+ #include "ViewComponentView.h"
13
+
14
+ #pragma warning(push)
15
+ #pragma warning(disable : 4244 4305)
16
+ //#include <react/renderer/components/view/ViewProps.h>
17
+ #pragma warning(pop)
18
+
19
+ namespace Microsoft::ReactNative {
20
+
21
+ struct SwitchComponentView : BaseComponentView {
22
+ using Super = BaseComponentView;
23
+ SwitchComponentView(winrt::Microsoft::ReactNative::ReactContext const &reactContext);
24
+
25
+ std::vector<facebook::react::ComponentDescriptorProvider> supplementalComponentDescriptorProviders() noexcept
26
+ override;
27
+ void mountChildComponentView(const IComponentView &childComponentView, uint32_t index) noexcept override;
28
+ void unmountChildComponentView(const IComponentView &childComponentView, uint32_t index) noexcept override;
29
+ void updateProps(facebook::react::Props::Shared const &props, facebook::react::Props::Shared const &oldProps) noexcept
30
+ override;
31
+ void updateState(facebook::react::State::Shared const &state, facebook::react::State::Shared const &oldState) noexcept
32
+ override;
33
+ void updateLayoutMetrics(
34
+ facebook::react::LayoutMetrics const &layoutMetrics,
35
+ facebook::react::LayoutMetrics const &oldLayoutMetrics) noexcept override;
36
+ void finalizeUpdates(RNComponentViewUpdateMask updateMask) noexcept override;
37
+ void prepareForRecycle() noexcept override;
38
+ facebook::react::SharedProps props() noexcept override;
39
+ void handleCommand(std::string const &commandName, folly::dynamic const &arg) noexcept override;
40
+
41
+ const xaml::FrameworkElement Element() const noexcept override;
42
+
43
+ private:
44
+ bool m_needsOnLoadStart{false};
45
+ std::shared_ptr<facebook::react::SwitchProps const> m_props;
46
+ facebook::react::LayoutMetrics m_layoutMetrics;
47
+ xaml::Controls::ToggleSwitch m_element;
48
+ xaml::Controls::ToggleSwitch::Toggled_revoker m_toggledRevoker;
49
+ winrt::Microsoft::ReactNative::ReactContext m_context;
50
+ };
51
+
52
+ } // namespace Microsoft::ReactNative
@@ -20,6 +20,10 @@ const facebook::react::SharedViewEventEmitter &BaseComponentView::GetEventEmitte
20
20
  return m_eventEmitter;
21
21
  }
22
22
 
23
+ void BaseComponentView::handleCommand(std::string const &commandName, folly::dynamic const &arg) noexcept {
24
+ assert(false); // Unhandled command
25
+ }
26
+
23
27
  ViewComponentView::ViewComponentView() {
24
28
  static auto const defaultProps = std::make_shared<facebook::react::ViewProps const>();
25
29
  m_props = defaultProps;
@@ -14,6 +14,7 @@ struct BaseComponentView : IComponentView {
14
14
  virtual const xaml::FrameworkElement Element() const noexcept = 0;
15
15
  void updateEventEmitter(facebook::react::EventEmitter::Shared const &eventEmitter) noexcept override;
16
16
  const facebook::react::SharedViewEventEmitter &GetEventEmitter() const noexcept;
17
+ void handleCommand(std::string const &commandName, folly::dynamic const &arg) noexcept override;
17
18
 
18
19
  protected:
19
20
  facebook::react::SharedViewEventEmitter m_eventEmitter;
@@ -0,0 +1,5 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT License.
3
+
4
+ // RN has some weird include directory redirections..this forwards the include to the right place
5
+ #include <react/components/rnwcore/EventEmitters.h>
@@ -0,0 +1,5 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT License.
3
+
4
+ // RN has some weird include directory redirections..this forwards the include to the right place
5
+ #include <react/components/rnwcore/Props.h>
@@ -0,0 +1,35 @@
1
+ /*
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ #include "SliderMeasurementsManager.h"
9
+
10
+ #include <react/renderer/core/conversions.h>
11
+ #include <winrt/Windows.Foundation.Collections.h>
12
+ #include <winrt/Windows.UI.Xaml.Interop.h>
13
+
14
+ namespace facebook::react {
15
+
16
+ Size SliderMeasurementsManager::measure(SurfaceId surfaceId, LayoutConstraints layoutConstraints) const {
17
+ if (!m_slider) {
18
+ m_slider = xaml::Controls::Slider();
19
+ xaml::Style sliderStyle;
20
+ xaml::Application::Current()
21
+ .Resources()
22
+ .TryLookup(winrt::box_value(winrt::xaml_typename<xaml::Controls::Slider>()))
23
+ .as(sliderStyle);
24
+ m_slider.Style(sliderStyle);
25
+ }
26
+
27
+ winrt::Windows::Foundation::Size availiableSize(
28
+ layoutConstraints.maximumSize.width, layoutConstraints.maximumSize.height);
29
+
30
+ m_slider.Measure(availiableSize);
31
+ auto size = m_slider.DesiredSize();
32
+ return {static_cast<float>(size.Width), static_cast<float>(size.Height)};
33
+ }
34
+
35
+ } // namespace facebook::react
@@ -0,0 +1,30 @@
1
+ #pragma once
2
+
3
+ #include <CppWinrtIncludes.h>
4
+ #include <UI.Xaml.Controls.h>
5
+ #include <react/renderer/core/ConcreteComponentDescriptor.h>
6
+ #include <react/renderer/core/LayoutConstraints.h>
7
+ #include <react/utils/ContextContainer.h>
8
+
9
+ namespace facebook::react {
10
+
11
+ /**
12
+ * Class that manages slider measurements across platforms.
13
+ * On iOS it is a noop, since the height is passed in from JS on iOS only.
14
+ */
15
+ class SliderMeasurementsManager {
16
+ public:
17
+ SliderMeasurementsManager(const ContextContainer::Shared &contextContainer) : m_contextContainer(contextContainer) {}
18
+
19
+ static inline bool shouldMeasureSlider() {
20
+ return true;
21
+ }
22
+
23
+ Size measure(SurfaceId surfaceId, LayoutConstraints layoutConstraints) const;
24
+
25
+ private:
26
+ ContextContainer::Shared m_contextContainer;
27
+ mutable xaml::Controls::Slider m_slider{nullptr};
28
+ };
29
+
30
+ } // namespace facebook::react