@onekeyfe/react-native-segment-slider 3.0.95 → 3.0.98

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.
@@ -37,6 +37,7 @@ using namespace margelo::nitro::segmentslider::views;
37
37
 
38
38
  @implementation HybridSegmentSliderComponent {
39
39
  std::shared_ptr<HybridSegmentSliderSpecSwift> _hybridView;
40
+ BOOL _didDropView;
40
41
  }
41
42
 
42
43
  + (void) load {
@@ -50,6 +51,7 @@ using namespace margelo::nitro::segmentslider::views;
50
51
 
51
52
  - (instancetype) init {
52
53
  if (self = [super init]) {
54
+ _props = HybridSegmentSliderShadowNode::defaultSharedProps();
53
55
  std::shared_ptr<HybridSegmentSliderSpec> hybridView = SegmentSlider::SegmentSliderAutolinking::createSegmentSlider();
54
56
  _hybridView = std::dynamic_pointer_cast<HybridSegmentSliderSpecSwift>(hybridView);
55
57
  [self updateView];
@@ -69,135 +71,175 @@ using namespace margelo::nitro::segmentslider::views;
69
71
  [self setContentView:view];
70
72
  }
71
73
 
74
+ - (void) notifyOnDropView {
75
+ // A recycled component can later be invalidated. Notify only once per mount.
76
+ if (_didDropView) {
77
+ return;
78
+ }
79
+ SegmentSlider::HybridSegmentSliderSpec_cxx& swiftPart = _hybridView->getSwiftPart();
80
+ swiftPart.onDropView();
81
+ _didDropView = YES;
82
+ }
83
+
72
84
  - (void) updateProps:(const std::shared_ptr<const react::Props>&)props
73
85
  oldProps:(const std::shared_ptr<const react::Props>&)oldProps {
86
+ // A props update marks a newly mounted or still-active component.
87
+ _didDropView = NO;
88
+
74
89
  // 1. Downcast props
75
- const auto& newViewPropsConst = *std::static_pointer_cast<HybridSegmentSliderProps const>(props);
76
- auto& newViewProps = const_cast<HybridSegmentSliderProps&>(newViewPropsConst);
90
+ const auto& newViewProps = *std::static_pointer_cast<const HybridSegmentSliderProps>(props);
91
+ const auto* oldViewProps = static_cast<const HybridSegmentSliderProps*>(oldProps.get());
77
92
  SegmentSlider::HybridSegmentSliderSpec_cxx& swiftPart = _hybridView->getSwiftPart();
78
93
 
79
- // 2. Update each prop individually
80
- swiftPart.beforeUpdate();
81
-
82
- // defaultValue: number
83
- if (newViewProps.defaultValue.isDirty) {
84
- swiftPart.setDefaultValue(newViewProps.defaultValue.value);
85
- newViewProps.defaultValue.isDirty = false;
86
- }
87
- // min: number
88
- if (newViewProps.min.isDirty) {
89
- swiftPart.setMin(newViewProps.min.value);
90
- newViewProps.min.isDirty = false;
91
- }
92
- // max: number
93
- if (newViewProps.max.isDirty) {
94
- swiftPart.setMax(newViewProps.max.value);
95
- newViewProps.max.isDirty = false;
96
- }
97
- // segments: number
98
- if (newViewProps.segments.isDirty) {
99
- swiftPart.setSegments(newViewProps.segments.value);
100
- newViewProps.segments.isDirty = false;
101
- }
102
- // sliderHeight: number
103
- if (newViewProps.sliderHeight.isDirty) {
104
- swiftPart.setSliderHeight(newViewProps.sliderHeight.value);
105
- newViewProps.sliderHeight.isDirty = false;
106
- }
107
- // disabled: boolean
108
- if (newViewProps.disabled.isDirty) {
109
- swiftPart.setDisabled(newViewProps.disabled.value);
110
- newViewProps.disabled.isDirty = false;
111
- }
112
- // showBubble: boolean
113
- if (newViewProps.showBubble.isDirty) {
114
- swiftPart.setShowBubble(newViewProps.showBubble.value);
115
- newViewProps.showBubble.isDirty = false;
116
- }
117
- // centerOrigin: boolean
118
- if (newViewProps.centerOrigin.isDirty) {
119
- swiftPart.setCenterOrigin(newViewProps.centerOrigin.value);
120
- newViewProps.centerOrigin.isDirty = false;
121
- }
122
- // snapTapToSegment: boolean
123
- if (newViewProps.snapTapToSegment.isDirty) {
124
- swiftPart.setSnapTapToSegment(newViewProps.snapTapToSegment.value);
125
- newViewProps.snapTapToSegment.isDirty = false;
126
- }
127
- // fillColor: string
128
- if (newViewProps.fillColor.isDirty) {
129
- swiftPart.setFillColor(newViewProps.fillColor.value);
130
- newViewProps.fillColor.isDirty = false;
131
- }
132
- // trackColor: string
133
- if (newViewProps.trackColor.isDirty) {
134
- swiftPart.setTrackColor(newViewProps.trackColor.value);
135
- newViewProps.trackColor.isDirty = false;
136
- }
137
- // thumbColor: string
138
- if (newViewProps.thumbColor.isDirty) {
139
- swiftPart.setThumbColor(newViewProps.thumbColor.value);
140
- newViewProps.thumbColor.isDirty = false;
141
- }
142
- // thumbBorderColor: string
143
- if (newViewProps.thumbBorderColor.isDirty) {
144
- swiftPart.setThumbBorderColor(newViewProps.thumbBorderColor.value);
145
- newViewProps.thumbBorderColor.isDirty = false;
146
- }
147
- // markActiveColor: string
148
- if (newViewProps.markActiveColor.isDirty) {
149
- swiftPart.setMarkActiveColor(newViewProps.markActiveColor.value);
150
- newViewProps.markActiveColor.isDirty = false;
151
- }
152
- // markInactiveColor: string
153
- if (newViewProps.markInactiveColor.isDirty) {
154
- swiftPart.setMarkInactiveColor(newViewProps.markInactiveColor.value);
155
- newViewProps.markInactiveColor.isDirty = false;
156
- }
157
- // markBorderColor: string
158
- if (newViewProps.markBorderColor.isDirty) {
159
- swiftPart.setMarkBorderColor(newViewProps.markBorderColor.value);
160
- newViewProps.markBorderColor.isDirty = false;
161
- }
162
- // bubbleColor: string
163
- if (newViewProps.bubbleColor.isDirty) {
164
- swiftPart.setBubbleColor(newViewProps.bubbleColor.value);
165
- newViewProps.bubbleColor.isDirty = false;
166
- }
167
- // bubbleTextColor: string
168
- if (newViewProps.bubbleTextColor.isDirty) {
169
- swiftPart.setBubbleTextColor(newViewProps.bubbleTextColor.value);
170
- newViewProps.bubbleTextColor.isDirty = false;
171
- }
172
- // onChange: optional
173
- if (newViewProps.onChange.isDirty) {
174
- swiftPart.setOnChange(newViewProps.onChange.value);
175
- newViewProps.onChange.isDirty = false;
176
- }
177
- // onSlideStart: optional
178
- if (newViewProps.onSlideStart.isDirty) {
179
- swiftPart.setOnSlideStart(newViewProps.onSlideStart.value);
180
- newViewProps.onSlideStart.isDirty = false;
181
- }
182
- // onSlideComplete: optional
183
- if (newViewProps.onSlideComplete.isDirty) {
184
- swiftPart.setOnSlideComplete(newViewProps.onSlideComplete.value);
185
- newViewProps.onSlideComplete.isDirty = false;
186
- }
94
+ // 2. Update only props that differ from the previous Props snapshot.
95
+ const bool hasTransactionPropChanges = oldViewProps == nullptr
96
+ ? newViewProps.hasAnyProvidedProps()
97
+ : !newViewProps.hasSameProps(*oldViewProps);
98
+ if (hasTransactionPropChanges) {
99
+ swiftPart.beforeUpdate();
187
100
 
188
- swiftPart.afterUpdate();
101
+ // defaultValue: number
102
+ if (oldViewProps == nullptr
103
+ ? newViewProps.defaultValue.isProvided()
104
+ : !newViewProps.defaultValue.hasSameValue(oldViewProps->defaultValue)) {
105
+ swiftPart.setDefaultValue(newViewProps.defaultValue.get());
106
+ }
107
+ // min: number
108
+ if (oldViewProps == nullptr
109
+ ? newViewProps.min.isProvided()
110
+ : !newViewProps.min.hasSameValue(oldViewProps->min)) {
111
+ swiftPart.setMin(newViewProps.min.get());
112
+ }
113
+ // max: number
114
+ if (oldViewProps == nullptr
115
+ ? newViewProps.max.isProvided()
116
+ : !newViewProps.max.hasSameValue(oldViewProps->max)) {
117
+ swiftPart.setMax(newViewProps.max.get());
118
+ }
119
+ // segments: number
120
+ if (oldViewProps == nullptr
121
+ ? newViewProps.segments.isProvided()
122
+ : !newViewProps.segments.hasSameValue(oldViewProps->segments)) {
123
+ swiftPart.setSegments(newViewProps.segments.get());
124
+ }
125
+ // sliderHeight: number
126
+ if (oldViewProps == nullptr
127
+ ? newViewProps.sliderHeight.isProvided()
128
+ : !newViewProps.sliderHeight.hasSameValue(oldViewProps->sliderHeight)) {
129
+ swiftPart.setSliderHeight(newViewProps.sliderHeight.get());
130
+ }
131
+ // disabled: boolean
132
+ if (oldViewProps == nullptr
133
+ ? newViewProps.disabled.isProvided()
134
+ : !newViewProps.disabled.hasSameValue(oldViewProps->disabled)) {
135
+ swiftPart.setDisabled(newViewProps.disabled.get());
136
+ }
137
+ // showBubble: boolean
138
+ if (oldViewProps == nullptr
139
+ ? newViewProps.showBubble.isProvided()
140
+ : !newViewProps.showBubble.hasSameValue(oldViewProps->showBubble)) {
141
+ swiftPart.setShowBubble(newViewProps.showBubble.get());
142
+ }
143
+ // centerOrigin: boolean
144
+ if (oldViewProps == nullptr
145
+ ? newViewProps.centerOrigin.isProvided()
146
+ : !newViewProps.centerOrigin.hasSameValue(oldViewProps->centerOrigin)) {
147
+ swiftPart.setCenterOrigin(newViewProps.centerOrigin.get());
148
+ }
149
+ // snapTapToSegment: boolean
150
+ if (oldViewProps == nullptr
151
+ ? newViewProps.snapTapToSegment.isProvided()
152
+ : !newViewProps.snapTapToSegment.hasSameValue(oldViewProps->snapTapToSegment)) {
153
+ swiftPart.setSnapTapToSegment(newViewProps.snapTapToSegment.get());
154
+ }
155
+ // fillColor: string
156
+ if (oldViewProps == nullptr
157
+ ? newViewProps.fillColor.isProvided()
158
+ : !newViewProps.fillColor.hasSameValue(oldViewProps->fillColor)) {
159
+ swiftPart.setFillColor(newViewProps.fillColor.get());
160
+ }
161
+ // trackColor: string
162
+ if (oldViewProps == nullptr
163
+ ? newViewProps.trackColor.isProvided()
164
+ : !newViewProps.trackColor.hasSameValue(oldViewProps->trackColor)) {
165
+ swiftPart.setTrackColor(newViewProps.trackColor.get());
166
+ }
167
+ // thumbColor: string
168
+ if (oldViewProps == nullptr
169
+ ? newViewProps.thumbColor.isProvided()
170
+ : !newViewProps.thumbColor.hasSameValue(oldViewProps->thumbColor)) {
171
+ swiftPart.setThumbColor(newViewProps.thumbColor.get());
172
+ }
173
+ // thumbBorderColor: string
174
+ if (oldViewProps == nullptr
175
+ ? newViewProps.thumbBorderColor.isProvided()
176
+ : !newViewProps.thumbBorderColor.hasSameValue(oldViewProps->thumbBorderColor)) {
177
+ swiftPart.setThumbBorderColor(newViewProps.thumbBorderColor.get());
178
+ }
179
+ // markActiveColor: string
180
+ if (oldViewProps == nullptr
181
+ ? newViewProps.markActiveColor.isProvided()
182
+ : !newViewProps.markActiveColor.hasSameValue(oldViewProps->markActiveColor)) {
183
+ swiftPart.setMarkActiveColor(newViewProps.markActiveColor.get());
184
+ }
185
+ // markInactiveColor: string
186
+ if (oldViewProps == nullptr
187
+ ? newViewProps.markInactiveColor.isProvided()
188
+ : !newViewProps.markInactiveColor.hasSameValue(oldViewProps->markInactiveColor)) {
189
+ swiftPart.setMarkInactiveColor(newViewProps.markInactiveColor.get());
190
+ }
191
+ // markBorderColor: string
192
+ if (oldViewProps == nullptr
193
+ ? newViewProps.markBorderColor.isProvided()
194
+ : !newViewProps.markBorderColor.hasSameValue(oldViewProps->markBorderColor)) {
195
+ swiftPart.setMarkBorderColor(newViewProps.markBorderColor.get());
196
+ }
197
+ // bubbleColor: string
198
+ if (oldViewProps == nullptr
199
+ ? newViewProps.bubbleColor.isProvided()
200
+ : !newViewProps.bubbleColor.hasSameValue(oldViewProps->bubbleColor)) {
201
+ swiftPart.setBubbleColor(newViewProps.bubbleColor.get());
202
+ }
203
+ // bubbleTextColor: string
204
+ if (oldViewProps == nullptr
205
+ ? newViewProps.bubbleTextColor.isProvided()
206
+ : !newViewProps.bubbleTextColor.hasSameValue(oldViewProps->bubbleTextColor)) {
207
+ swiftPart.setBubbleTextColor(newViewProps.bubbleTextColor.get());
208
+ }
209
+ // onChange: optional
210
+ if (oldViewProps == nullptr
211
+ ? newViewProps.onChange.isProvided()
212
+ : !newViewProps.onChange.hasSameValue(oldViewProps->onChange)) {
213
+ swiftPart.setOnChange(newViewProps.onChange.get());
214
+ }
215
+ // onSlideStart: optional
216
+ if (oldViewProps == nullptr
217
+ ? newViewProps.onSlideStart.isProvided()
218
+ : !newViewProps.onSlideStart.hasSameValue(oldViewProps->onSlideStart)) {
219
+ swiftPart.setOnSlideStart(newViewProps.onSlideStart.get());
220
+ }
221
+ // onSlideComplete: optional
222
+ if (oldViewProps == nullptr
223
+ ? newViewProps.onSlideComplete.isProvided()
224
+ : !newViewProps.onSlideComplete.hasSameValue(oldViewProps->onSlideComplete)) {
225
+ swiftPart.setOnSlideComplete(newViewProps.onSlideComplete.get());
226
+ }
189
227
 
190
- // 3. Update hybridRef if it changed
191
- if (newViewProps.hybridRef.isDirty) {
192
- // hybridRef changed - call it with new this
193
- const auto& maybeFunc = newViewProps.hybridRef.value;
194
- if (maybeFunc.has_value()) {
195
- maybeFunc.value()(_hybridView);
228
+ // Update hybridRef if it changed
229
+ if (oldViewProps == nullptr
230
+ ? newViewProps.hybridRef.isProvided()
231
+ : !newViewProps.hybridRef.hasSameValue(oldViewProps->hybridRef)) {
232
+ // hybridRef changed - call it with new this
233
+ const auto& maybeFunc = newViewProps.hybridRef.get();
234
+ if (maybeFunc.has_value()) {
235
+ maybeFunc.value()(_hybridView);
236
+ }
196
237
  }
197
- newViewProps.hybridRef.isDirty = false;
238
+
239
+ swiftPart.afterUpdate();
198
240
  }
199
241
 
200
- // 4. Continue in base class
242
+ // 3. Continue in base class
201
243
  [super updateProps:props oldProps:oldProps];
202
244
  }
203
245
 
@@ -206,6 +248,7 @@ using namespace margelo::nitro::segmentslider::views;
206
248
  }
207
249
 
208
250
  - (void)prepareForRecycle {
251
+ [self notifyOnDropView];
209
252
  [super prepareForRecycle];
210
253
  SegmentSlider::HybridSegmentSliderSpec_cxx& swiftPart = _hybridView->getSwiftPart();
211
254
  swiftPart.maybePrepareForRecycle();
@@ -213,8 +256,7 @@ using namespace margelo::nitro::segmentslider::views;
213
256
 
214
257
  #ifdef ENABLE_RCT_COMPONENT_VIEW_INVALIDATE
215
258
  - (void)invalidate {
216
- SegmentSlider::HybridSegmentSliderSpec_cxx& swiftPart = _hybridView->getSwiftPart();
217
- swiftPart.onDropView();
259
+ [self notifyOnDropView];
218
260
  [super invalidate];
219
261
  }
220
262
  #endif
@@ -7,245 +7,41 @@
7
7
 
8
8
  #include "HybridSegmentSliderComponent.hpp"
9
9
 
10
- #include <string>
11
- #include <exception>
12
- #include <utility>
13
- #include <NitroModules/NitroDefines.hpp>
14
- #include <NitroModules/JSIConverter.hpp>
15
- #include <NitroModules/PropNameIDCache.hpp>
16
- #include <react/renderer/core/RawValue.h>
17
- #include <react/renderer/core/ShadowNode.h>
18
- #include <react/renderer/core/ComponentDescriptor.h>
19
- #include <react/renderer/components/view/ViewProps.h>
10
+ #include <NitroModules/NitroHash.hpp>
11
+ #include <NitroModules/ReactProp.hpp>
20
12
 
21
13
  namespace margelo::nitro::segmentslider::views {
22
14
 
15
+ using namespace facebook;
16
+
23
17
  extern const char HybridSegmentSliderComponentName[] = "SegmentSlider";
24
18
 
25
19
  HybridSegmentSliderProps::HybridSegmentSliderProps(const react::PropsParserContext& context,
26
20
  const HybridSegmentSliderProps& sourceProps,
27
21
  const react::RawProps& rawProps):
28
22
  react::ViewProps(context, sourceProps, rawProps, filterObjectKeys),
29
- defaultValue([&]() -> CachedProp<double> {
30
- try {
31
- const react::RawValue* rawValue = rawProps.at("defaultValue", nullptr, nullptr);
32
- if (rawValue == nullptr) return sourceProps.defaultValue;
33
- const auto& [runtime, value] = (std::pair<jsi::Runtime*, jsi::Value>)*rawValue;
34
- return CachedProp<double>::fromRawValue(*runtime, value, sourceProps.defaultValue);
35
- } catch (const std::exception& exc) {
36
- throw std::runtime_error(std::string("SegmentSlider.defaultValue: ") + exc.what());
37
- }
38
- }()),
39
- min([&]() -> CachedProp<double> {
40
- try {
41
- const react::RawValue* rawValue = rawProps.at("min", nullptr, nullptr);
42
- if (rawValue == nullptr) return sourceProps.min;
43
- const auto& [runtime, value] = (std::pair<jsi::Runtime*, jsi::Value>)*rawValue;
44
- return CachedProp<double>::fromRawValue(*runtime, value, sourceProps.min);
45
- } catch (const std::exception& exc) {
46
- throw std::runtime_error(std::string("SegmentSlider.min: ") + exc.what());
47
- }
48
- }()),
49
- max([&]() -> CachedProp<double> {
50
- try {
51
- const react::RawValue* rawValue = rawProps.at("max", nullptr, nullptr);
52
- if (rawValue == nullptr) return sourceProps.max;
53
- const auto& [runtime, value] = (std::pair<jsi::Runtime*, jsi::Value>)*rawValue;
54
- return CachedProp<double>::fromRawValue(*runtime, value, sourceProps.max);
55
- } catch (const std::exception& exc) {
56
- throw std::runtime_error(std::string("SegmentSlider.max: ") + exc.what());
57
- }
58
- }()),
59
- segments([&]() -> CachedProp<double> {
60
- try {
61
- const react::RawValue* rawValue = rawProps.at("segments", nullptr, nullptr);
62
- if (rawValue == nullptr) return sourceProps.segments;
63
- const auto& [runtime, value] = (std::pair<jsi::Runtime*, jsi::Value>)*rawValue;
64
- return CachedProp<double>::fromRawValue(*runtime, value, sourceProps.segments);
65
- } catch (const std::exception& exc) {
66
- throw std::runtime_error(std::string("SegmentSlider.segments: ") + exc.what());
67
- }
68
- }()),
69
- sliderHeight([&]() -> CachedProp<double> {
70
- try {
71
- const react::RawValue* rawValue = rawProps.at("sliderHeight", nullptr, nullptr);
72
- if (rawValue == nullptr) return sourceProps.sliderHeight;
73
- const auto& [runtime, value] = (std::pair<jsi::Runtime*, jsi::Value>)*rawValue;
74
- return CachedProp<double>::fromRawValue(*runtime, value, sourceProps.sliderHeight);
75
- } catch (const std::exception& exc) {
76
- throw std::runtime_error(std::string("SegmentSlider.sliderHeight: ") + exc.what());
77
- }
78
- }()),
79
- disabled([&]() -> CachedProp<bool> {
80
- try {
81
- const react::RawValue* rawValue = rawProps.at("disabled", nullptr, nullptr);
82
- if (rawValue == nullptr) return sourceProps.disabled;
83
- const auto& [runtime, value] = (std::pair<jsi::Runtime*, jsi::Value>)*rawValue;
84
- return CachedProp<bool>::fromRawValue(*runtime, value, sourceProps.disabled);
85
- } catch (const std::exception& exc) {
86
- throw std::runtime_error(std::string("SegmentSlider.disabled: ") + exc.what());
87
- }
88
- }()),
89
- showBubble([&]() -> CachedProp<bool> {
90
- try {
91
- const react::RawValue* rawValue = rawProps.at("showBubble", nullptr, nullptr);
92
- if (rawValue == nullptr) return sourceProps.showBubble;
93
- const auto& [runtime, value] = (std::pair<jsi::Runtime*, jsi::Value>)*rawValue;
94
- return CachedProp<bool>::fromRawValue(*runtime, value, sourceProps.showBubble);
95
- } catch (const std::exception& exc) {
96
- throw std::runtime_error(std::string("SegmentSlider.showBubble: ") + exc.what());
97
- }
98
- }()),
99
- centerOrigin([&]() -> CachedProp<bool> {
100
- try {
101
- const react::RawValue* rawValue = rawProps.at("centerOrigin", nullptr, nullptr);
102
- if (rawValue == nullptr) return sourceProps.centerOrigin;
103
- const auto& [runtime, value] = (std::pair<jsi::Runtime*, jsi::Value>)*rawValue;
104
- return CachedProp<bool>::fromRawValue(*runtime, value, sourceProps.centerOrigin);
105
- } catch (const std::exception& exc) {
106
- throw std::runtime_error(std::string("SegmentSlider.centerOrigin: ") + exc.what());
107
- }
108
- }()),
109
- snapTapToSegment([&]() -> CachedProp<bool> {
110
- try {
111
- const react::RawValue* rawValue = rawProps.at("snapTapToSegment", nullptr, nullptr);
112
- if (rawValue == nullptr) return sourceProps.snapTapToSegment;
113
- const auto& [runtime, value] = (std::pair<jsi::Runtime*, jsi::Value>)*rawValue;
114
- return CachedProp<bool>::fromRawValue(*runtime, value, sourceProps.snapTapToSegment);
115
- } catch (const std::exception& exc) {
116
- throw std::runtime_error(std::string("SegmentSlider.snapTapToSegment: ") + exc.what());
117
- }
118
- }()),
119
- fillColor([&]() -> CachedProp<std::string> {
120
- try {
121
- const react::RawValue* rawValue = rawProps.at("fillColor", nullptr, nullptr);
122
- if (rawValue == nullptr) return sourceProps.fillColor;
123
- const auto& [runtime, value] = (std::pair<jsi::Runtime*, jsi::Value>)*rawValue;
124
- return CachedProp<std::string>::fromRawValue(*runtime, value, sourceProps.fillColor);
125
- } catch (const std::exception& exc) {
126
- throw std::runtime_error(std::string("SegmentSlider.fillColor: ") + exc.what());
127
- }
128
- }()),
129
- trackColor([&]() -> CachedProp<std::string> {
130
- try {
131
- const react::RawValue* rawValue = rawProps.at("trackColor", nullptr, nullptr);
132
- if (rawValue == nullptr) return sourceProps.trackColor;
133
- const auto& [runtime, value] = (std::pair<jsi::Runtime*, jsi::Value>)*rawValue;
134
- return CachedProp<std::string>::fromRawValue(*runtime, value, sourceProps.trackColor);
135
- } catch (const std::exception& exc) {
136
- throw std::runtime_error(std::string("SegmentSlider.trackColor: ") + exc.what());
137
- }
138
- }()),
139
- thumbColor([&]() -> CachedProp<std::string> {
140
- try {
141
- const react::RawValue* rawValue = rawProps.at("thumbColor", nullptr, nullptr);
142
- if (rawValue == nullptr) return sourceProps.thumbColor;
143
- const auto& [runtime, value] = (std::pair<jsi::Runtime*, jsi::Value>)*rawValue;
144
- return CachedProp<std::string>::fromRawValue(*runtime, value, sourceProps.thumbColor);
145
- } catch (const std::exception& exc) {
146
- throw std::runtime_error(std::string("SegmentSlider.thumbColor: ") + exc.what());
147
- }
148
- }()),
149
- thumbBorderColor([&]() -> CachedProp<std::string> {
150
- try {
151
- const react::RawValue* rawValue = rawProps.at("thumbBorderColor", nullptr, nullptr);
152
- if (rawValue == nullptr) return sourceProps.thumbBorderColor;
153
- const auto& [runtime, value] = (std::pair<jsi::Runtime*, jsi::Value>)*rawValue;
154
- return CachedProp<std::string>::fromRawValue(*runtime, value, sourceProps.thumbBorderColor);
155
- } catch (const std::exception& exc) {
156
- throw std::runtime_error(std::string("SegmentSlider.thumbBorderColor: ") + exc.what());
157
- }
158
- }()),
159
- markActiveColor([&]() -> CachedProp<std::string> {
160
- try {
161
- const react::RawValue* rawValue = rawProps.at("markActiveColor", nullptr, nullptr);
162
- if (rawValue == nullptr) return sourceProps.markActiveColor;
163
- const auto& [runtime, value] = (std::pair<jsi::Runtime*, jsi::Value>)*rawValue;
164
- return CachedProp<std::string>::fromRawValue(*runtime, value, sourceProps.markActiveColor);
165
- } catch (const std::exception& exc) {
166
- throw std::runtime_error(std::string("SegmentSlider.markActiveColor: ") + exc.what());
167
- }
168
- }()),
169
- markInactiveColor([&]() -> CachedProp<std::string> {
170
- try {
171
- const react::RawValue* rawValue = rawProps.at("markInactiveColor", nullptr, nullptr);
172
- if (rawValue == nullptr) return sourceProps.markInactiveColor;
173
- const auto& [runtime, value] = (std::pair<jsi::Runtime*, jsi::Value>)*rawValue;
174
- return CachedProp<std::string>::fromRawValue(*runtime, value, sourceProps.markInactiveColor);
175
- } catch (const std::exception& exc) {
176
- throw std::runtime_error(std::string("SegmentSlider.markInactiveColor: ") + exc.what());
177
- }
178
- }()),
179
- markBorderColor([&]() -> CachedProp<std::string> {
180
- try {
181
- const react::RawValue* rawValue = rawProps.at("markBorderColor", nullptr, nullptr);
182
- if (rawValue == nullptr) return sourceProps.markBorderColor;
183
- const auto& [runtime, value] = (std::pair<jsi::Runtime*, jsi::Value>)*rawValue;
184
- return CachedProp<std::string>::fromRawValue(*runtime, value, sourceProps.markBorderColor);
185
- } catch (const std::exception& exc) {
186
- throw std::runtime_error(std::string("SegmentSlider.markBorderColor: ") + exc.what());
187
- }
188
- }()),
189
- bubbleColor([&]() -> CachedProp<std::string> {
190
- try {
191
- const react::RawValue* rawValue = rawProps.at("bubbleColor", nullptr, nullptr);
192
- if (rawValue == nullptr) return sourceProps.bubbleColor;
193
- const auto& [runtime, value] = (std::pair<jsi::Runtime*, jsi::Value>)*rawValue;
194
- return CachedProp<std::string>::fromRawValue(*runtime, value, sourceProps.bubbleColor);
195
- } catch (const std::exception& exc) {
196
- throw std::runtime_error(std::string("SegmentSlider.bubbleColor: ") + exc.what());
197
- }
198
- }()),
199
- bubbleTextColor([&]() -> CachedProp<std::string> {
200
- try {
201
- const react::RawValue* rawValue = rawProps.at("bubbleTextColor", nullptr, nullptr);
202
- if (rawValue == nullptr) return sourceProps.bubbleTextColor;
203
- const auto& [runtime, value] = (std::pair<jsi::Runtime*, jsi::Value>)*rawValue;
204
- return CachedProp<std::string>::fromRawValue(*runtime, value, sourceProps.bubbleTextColor);
205
- } catch (const std::exception& exc) {
206
- throw std::runtime_error(std::string("SegmentSlider.bubbleTextColor: ") + exc.what());
207
- }
208
- }()),
209
- onChange([&]() -> CachedProp<std::optional<std::function<void(double /* value */)>>> {
210
- try {
211
- const react::RawValue* rawValue = rawProps.at("onChange", nullptr, nullptr);
212
- if (rawValue == nullptr) return sourceProps.onChange;
213
- const auto& [runtime, value] = (std::pair<jsi::Runtime*, jsi::Value>)*rawValue;
214
- return CachedProp<std::optional<std::function<void(double /* value */)>>>::fromRawValue(*runtime, value.asObject(*runtime).getProperty(*runtime, PropNameIDCache::get(*runtime, "f")), sourceProps.onChange);
215
- } catch (const std::exception& exc) {
216
- throw std::runtime_error(std::string("SegmentSlider.onChange: ") + exc.what());
217
- }
218
- }()),
219
- onSlideStart([&]() -> CachedProp<std::optional<std::function<void()>>> {
220
- try {
221
- const react::RawValue* rawValue = rawProps.at("onSlideStart", nullptr, nullptr);
222
- if (rawValue == nullptr) return sourceProps.onSlideStart;
223
- const auto& [runtime, value] = (std::pair<jsi::Runtime*, jsi::Value>)*rawValue;
224
- return CachedProp<std::optional<std::function<void()>>>::fromRawValue(*runtime, value.asObject(*runtime).getProperty(*runtime, PropNameIDCache::get(*runtime, "f")), sourceProps.onSlideStart);
225
- } catch (const std::exception& exc) {
226
- throw std::runtime_error(std::string("SegmentSlider.onSlideStart: ") + exc.what());
227
- }
228
- }()),
229
- onSlideComplete([&]() -> CachedProp<std::optional<std::function<void()>>> {
230
- try {
231
- const react::RawValue* rawValue = rawProps.at("onSlideComplete", nullptr, nullptr);
232
- if (rawValue == nullptr) return sourceProps.onSlideComplete;
233
- const auto& [runtime, value] = (std::pair<jsi::Runtime*, jsi::Value>)*rawValue;
234
- return CachedProp<std::optional<std::function<void()>>>::fromRawValue(*runtime, value.asObject(*runtime).getProperty(*runtime, PropNameIDCache::get(*runtime, "f")), sourceProps.onSlideComplete);
235
- } catch (const std::exception& exc) {
236
- throw std::runtime_error(std::string("SegmentSlider.onSlideComplete: ") + exc.what());
237
- }
238
- }()),
239
- hybridRef([&]() -> CachedProp<std::optional<std::function<void(const std::shared_ptr<HybridSegmentSliderSpec>& /* ref */)>>> {
240
- try {
241
- const react::RawValue* rawValue = rawProps.at("hybridRef", nullptr, nullptr);
242
- if (rawValue == nullptr) return sourceProps.hybridRef;
243
- const auto& [runtime, value] = (std::pair<jsi::Runtime*, jsi::Value>)*rawValue;
244
- return CachedProp<std::optional<std::function<void(const std::shared_ptr<HybridSegmentSliderSpec>& /* ref */)>>>::fromRawValue(*runtime, value.asObject(*runtime).getProperty(*runtime, PropNameIDCache::get(*runtime, "f")), sourceProps.hybridRef);
245
- } catch (const std::exception& exc) {
246
- throw std::runtime_error(std::string("SegmentSlider.hybridRef: ") + exc.what());
247
- }
248
- }()) { }
23
+ defaultValue(nitro::ReactProp<double>::fromRawValue("SegmentSlider", "defaultValue", rawProps, sourceProps.defaultValue)),
24
+ min(nitro::ReactProp<double>::fromRawValue("SegmentSlider", "min", rawProps, sourceProps.min)),
25
+ max(nitro::ReactProp<double>::fromRawValue("SegmentSlider", "max", rawProps, sourceProps.max)),
26
+ segments(nitro::ReactProp<double>::fromRawValue("SegmentSlider", "segments", rawProps, sourceProps.segments)),
27
+ sliderHeight(nitro::ReactProp<double>::fromRawValue("SegmentSlider", "sliderHeight", rawProps, sourceProps.sliderHeight)),
28
+ disabled(nitro::ReactProp<bool>::fromRawValue("SegmentSlider", "disabled", rawProps, sourceProps.disabled)),
29
+ showBubble(nitro::ReactProp<bool>::fromRawValue("SegmentSlider", "showBubble", rawProps, sourceProps.showBubble)),
30
+ centerOrigin(nitro::ReactProp<bool>::fromRawValue("SegmentSlider", "centerOrigin", rawProps, sourceProps.centerOrigin)),
31
+ snapTapToSegment(nitro::ReactProp<bool>::fromRawValue("SegmentSlider", "snapTapToSegment", rawProps, sourceProps.snapTapToSegment)),
32
+ fillColor(nitro::ReactProp<std::string>::fromRawValue("SegmentSlider", "fillColor", rawProps, sourceProps.fillColor)),
33
+ trackColor(nitro::ReactProp<std::string>::fromRawValue("SegmentSlider", "trackColor", rawProps, sourceProps.trackColor)),
34
+ thumbColor(nitro::ReactProp<std::string>::fromRawValue("SegmentSlider", "thumbColor", rawProps, sourceProps.thumbColor)),
35
+ thumbBorderColor(nitro::ReactProp<std::string>::fromRawValue("SegmentSlider", "thumbBorderColor", rawProps, sourceProps.thumbBorderColor)),
36
+ markActiveColor(nitro::ReactProp<std::string>::fromRawValue("SegmentSlider", "markActiveColor", rawProps, sourceProps.markActiveColor)),
37
+ markInactiveColor(nitro::ReactProp<std::string>::fromRawValue("SegmentSlider", "markInactiveColor", rawProps, sourceProps.markInactiveColor)),
38
+ markBorderColor(nitro::ReactProp<std::string>::fromRawValue("SegmentSlider", "markBorderColor", rawProps, sourceProps.markBorderColor)),
39
+ bubbleColor(nitro::ReactProp<std::string>::fromRawValue("SegmentSlider", "bubbleColor", rawProps, sourceProps.bubbleColor)),
40
+ bubbleTextColor(nitro::ReactProp<std::string>::fromRawValue("SegmentSlider", "bubbleTextColor", rawProps, sourceProps.bubbleTextColor)),
41
+ onChange(nitro::ReactProp<std::optional<std::function<void(double /* value */)>>>::fromRawValue("SegmentSlider", "onChange", rawProps, sourceProps.onChange)),
42
+ onSlideStart(nitro::ReactProp<std::optional<std::function<void()>>>::fromRawValue("SegmentSlider", "onSlideStart", rawProps, sourceProps.onSlideStart)),
43
+ onSlideComplete(nitro::ReactProp<std::optional<std::function<void()>>>::fromRawValue("SegmentSlider", "onSlideComplete", rawProps, sourceProps.onSlideComplete)),
44
+ hybridRef(nitro::ReactProp<std::optional<std::function<void(const std::shared_ptr<HybridSegmentSliderSpec>& /* ref */)>>>::fromRawValue("SegmentSlider", "hybridRef", rawProps, sourceProps.hybridRef)) { }
249
45
 
250
46
  bool HybridSegmentSliderProps::filterObjectKeys(const std::string& propName) {
251
47
  switch (hashString(propName)) {
@@ -275,29 +71,4 @@ namespace margelo::nitro::segmentslider::views {
275
71
  }
276
72
  }
277
73
 
278
- HybridSegmentSliderComponentDescriptor::HybridSegmentSliderComponentDescriptor(const react::ComponentDescriptorParameters& parameters)
279
- : ConcreteComponentDescriptor(parameters,
280
- react::RawPropsParser()) {}
281
-
282
- std::shared_ptr<const react::Props> HybridSegmentSliderComponentDescriptor::cloneProps(const react::PropsParserContext& context,
283
- const std::shared_ptr<const react::Props>& props,
284
- react::RawProps rawProps) const {
285
- // 1. Prepare raw props parser
286
- rawProps.parse(rawPropsParser_);
287
- // 2. Copy props with Nitro's cached copy constructor
288
- return HybridSegmentSliderShadowNode::Props(context, /* & */ rawProps, props);
289
- }
290
-
291
- #ifdef ANDROID
292
- void HybridSegmentSliderComponentDescriptor::adopt(react::ShadowNode& shadowNode) const {
293
- // This is called immediately after `ShadowNode` is created, cloned or in progress.
294
- // On Android, we need to wrap props in our state, which gets routed through Java and later unwrapped in JNI/C++.
295
- auto& concreteShadowNode = static_cast<HybridSegmentSliderShadowNode&>(shadowNode);
296
- const std::shared_ptr<const HybridSegmentSliderProps>& constProps = concreteShadowNode.getConcreteSharedProps();
297
- const std::shared_ptr<HybridSegmentSliderProps>& props = std::const_pointer_cast<HybridSegmentSliderProps>(constProps);
298
- HybridSegmentSliderState state{props};
299
- concreteShadowNode.setStateData(std::move(state));
300
- }
301
- #endif
302
-
303
74
  } // namespace margelo::nitro::segmentslider::views