2019-10-16 20:03:47 +03:00
|
|
|
/*
|
2021-12-31 02:08:43 +03:00
|
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
2015-03-23 23:28:42 +03:00
|
|
|
*
|
2018-02-17 05:24:55 +03:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2015-03-23 23:28:42 +03:00
|
|
|
*/
|
2015-03-10 00:42:55 +03:00
|
|
|
|
|
|
|
#import "RCTSliderManager.h"
|
|
|
|
|
|
|
|
#import "RCTBridge.h"
|
2015-04-21 20:50:10 +03:00
|
|
|
#import "RCTSlider.h"
|
2015-03-26 12:58:06 +03:00
|
|
|
#import "UIView+React.h"
|
2015-03-10 00:42:55 +03:00
|
|
|
|
|
|
|
@implementation RCTSliderManager
|
|
|
|
|
2015-04-08 15:42:43 +03:00
|
|
|
RCT_EXPORT_MODULE()
|
|
|
|
|
2015-03-10 00:42:55 +03:00
|
|
|
- (UIView *)view
|
|
|
|
{
|
2015-08-17 17:35:34 +03:00
|
|
|
RCTSlider *slider = [RCTSlider new];
|
2020-03-09 08:58:01 +03:00
|
|
|
[slider addTarget:self action:@selector(sliderValueChanged:) forControlEvents:UIControlEventValueChanged];
|
|
|
|
[slider addTarget:self
|
|
|
|
action:@selector(sliderTouchEnd:)
|
|
|
|
forControlEvents:(UIControlEventTouchUpInside | UIControlEventTouchUpOutside | UIControlEventTouchCancel)];
|
2015-03-10 00:42:55 +03:00
|
|
|
return slider;
|
|
|
|
}
|
|
|
|
|
Added mechanism for directly mapping JS event handlers to blocks
Summary:
Currently, the system for mapping JS event handlers to blocks is quite clean on the JS side, but is clunky on the native side. The event property is passed as a boolean, which can then be checked by the native side, and if true, the native side is supposed to send an event via the event dispatcher.
This diff adds the facility to declare the property as a block instead. This means that the event side can simply call the block, and it will automatically send the event. Because the blocks for bubbling and direct events are named differently, we can also use this to generate the event registration data and get rid of the arrays of event names.
The name of the event is inferred from the property name, which means that the property for an event called "load" must be called `onLoad` or the mapping won't work. This can be optionally remapped to a different property name on the view itself if necessary, e.g.
RCT_REMAP_VIEW_PROPERTY(onLoad, loadEventBlock, RCTDirectEventBlock)
If you don't want to use this mechanism then for now it is still possible to declare the property as a BOOL instead and use the old mechanism (this approach is now deprecated however, and may eventually be removed altogether).
2015-09-02 15:58:10 +03:00
|
|
|
static void RCTSendSliderEvent(RCTSlider *sender, BOOL continuous)
|
2015-03-10 00:42:55 +03:00
|
|
|
{
|
2015-10-30 17:12:24 +03:00
|
|
|
float value = sender.value;
|
|
|
|
|
2020-03-09 08:58:01 +03:00
|
|
|
if (sender.step > 0 && sender.step <= (sender.maximumValue - sender.minimumValue)) {
|
2015-10-30 17:12:24 +03:00
|
|
|
value =
|
2020-03-09 08:58:01 +03:00
|
|
|
MAX(sender.minimumValue,
|
|
|
|
MIN(sender.maximumValue,
|
|
|
|
sender.minimumValue + round((sender.value - sender.minimumValue) / sender.step) * sender.step));
|
2015-10-30 17:12:24 +03:00
|
|
|
|
2015-10-30 19:12:10 +03:00
|
|
|
[sender setValue:value animated:YES];
|
2015-10-30 17:12:24 +03:00
|
|
|
}
|
|
|
|
|
2015-10-30 19:12:10 +03:00
|
|
|
if (continuous) {
|
|
|
|
if (sender.onValueChange && sender.lastValue != value) {
|
|
|
|
sender.onValueChange(@{
|
2020-03-09 08:58:01 +03:00
|
|
|
@"value" : @(value),
|
2015-10-30 19:12:10 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (sender.onSlidingComplete) {
|
|
|
|
sender.onSlidingComplete(@{
|
2020-03-09 08:58:01 +03:00
|
|
|
@"value" : @(value),
|
2015-10-30 19:12:10 +03:00
|
|
|
});
|
|
|
|
}
|
Added mechanism for directly mapping JS event handlers to blocks
Summary:
Currently, the system for mapping JS event handlers to blocks is quite clean on the JS side, but is clunky on the native side. The event property is passed as a boolean, which can then be checked by the native side, and if true, the native side is supposed to send an event via the event dispatcher.
This diff adds the facility to declare the property as a block instead. This means that the event side can simply call the block, and it will automatically send the event. Because the blocks for bubbling and direct events are named differently, we can also use this to generate the event registration data and get rid of the arrays of event names.
The name of the event is inferred from the property name, which means that the property for an event called "load" must be called `onLoad` or the mapping won't work. This can be optionally remapped to a different property name on the view itself if necessary, e.g.
RCT_REMAP_VIEW_PROPERTY(onLoad, loadEventBlock, RCTDirectEventBlock)
If you don't want to use this mechanism then for now it is still possible to declare the property as a BOOL instead and use the old mechanism (this approach is now deprecated however, and may eventually be removed altogether).
2015-09-02 15:58:10 +03:00
|
|
|
}
|
2015-10-30 17:12:24 +03:00
|
|
|
|
|
|
|
sender.lastValue = value;
|
2015-03-10 00:42:55 +03:00
|
|
|
}
|
|
|
|
|
Added mechanism for directly mapping JS event handlers to blocks
Summary:
Currently, the system for mapping JS event handlers to blocks is quite clean on the JS side, but is clunky on the native side. The event property is passed as a boolean, which can then be checked by the native side, and if true, the native side is supposed to send an event via the event dispatcher.
This diff adds the facility to declare the property as a block instead. This means that the event side can simply call the block, and it will automatically send the event. Because the blocks for bubbling and direct events are named differently, we can also use this to generate the event registration data and get rid of the arrays of event names.
The name of the event is inferred from the property name, which means that the property for an event called "load" must be called `onLoad` or the mapping won't work. This can be optionally remapped to a different property name on the view itself if necessary, e.g.
RCT_REMAP_VIEW_PROPERTY(onLoad, loadEventBlock, RCTDirectEventBlock)
If you don't want to use this mechanism then for now it is still possible to declare the property as a BOOL instead and use the old mechanism (this approach is now deprecated however, and may eventually be removed altogether).
2015-09-02 15:58:10 +03:00
|
|
|
- (void)sliderValueChanged:(RCTSlider *)sender
|
2015-03-10 00:42:55 +03:00
|
|
|
{
|
Added mechanism for directly mapping JS event handlers to blocks
Summary:
Currently, the system for mapping JS event handlers to blocks is quite clean on the JS side, but is clunky on the native side. The event property is passed as a boolean, which can then be checked by the native side, and if true, the native side is supposed to send an event via the event dispatcher.
This diff adds the facility to declare the property as a block instead. This means that the event side can simply call the block, and it will automatically send the event. Because the blocks for bubbling and direct events are named differently, we can also use this to generate the event registration data and get rid of the arrays of event names.
The name of the event is inferred from the property name, which means that the property for an event called "load" must be called `onLoad` or the mapping won't work. This can be optionally remapped to a different property name on the view itself if necessary, e.g.
RCT_REMAP_VIEW_PROPERTY(onLoad, loadEventBlock, RCTDirectEventBlock)
If you don't want to use this mechanism then for now it is still possible to declare the property as a BOOL instead and use the old mechanism (this approach is now deprecated however, and may eventually be removed altogether).
2015-09-02 15:58:10 +03:00
|
|
|
RCTSendSliderEvent(sender, YES);
|
2015-04-21 20:50:10 +03:00
|
|
|
}
|
2015-03-10 00:42:55 +03:00
|
|
|
|
Added mechanism for directly mapping JS event handlers to blocks
Summary:
Currently, the system for mapping JS event handlers to blocks is quite clean on the JS side, but is clunky on the native side. The event property is passed as a boolean, which can then be checked by the native side, and if true, the native side is supposed to send an event via the event dispatcher.
This diff adds the facility to declare the property as a block instead. This means that the event side can simply call the block, and it will automatically send the event. Because the blocks for bubbling and direct events are named differently, we can also use this to generate the event registration data and get rid of the arrays of event names.
The name of the event is inferred from the property name, which means that the property for an event called "load" must be called `onLoad` or the mapping won't work. This can be optionally remapped to a different property name on the view itself if necessary, e.g.
RCT_REMAP_VIEW_PROPERTY(onLoad, loadEventBlock, RCTDirectEventBlock)
If you don't want to use this mechanism then for now it is still possible to declare the property as a BOOL instead and use the old mechanism (this approach is now deprecated however, and may eventually be removed altogether).
2015-09-02 15:58:10 +03:00
|
|
|
- (void)sliderTouchEnd:(RCTSlider *)sender
|
2015-04-21 20:50:10 +03:00
|
|
|
{
|
Added mechanism for directly mapping JS event handlers to blocks
Summary:
Currently, the system for mapping JS event handlers to blocks is quite clean on the JS side, but is clunky on the native side. The event property is passed as a boolean, which can then be checked by the native side, and if true, the native side is supposed to send an event via the event dispatcher.
This diff adds the facility to declare the property as a block instead. This means that the event side can simply call the block, and it will automatically send the event. Because the blocks for bubbling and direct events are named differently, we can also use this to generate the event registration data and get rid of the arrays of event names.
The name of the event is inferred from the property name, which means that the property for an event called "load" must be called `onLoad` or the mapping won't work. This can be optionally remapped to a different property name on the view itself if necessary, e.g.
RCT_REMAP_VIEW_PROPERTY(onLoad, loadEventBlock, RCTDirectEventBlock)
If you don't want to use this mechanism then for now it is still possible to declare the property as a BOOL instead and use the old mechanism (this approach is now deprecated however, and may eventually be removed altogether).
2015-09-02 15:58:10 +03:00
|
|
|
RCTSendSliderEvent(sender, NO);
|
2015-03-10 00:42:55 +03:00
|
|
|
}
|
|
|
|
|
2015-03-26 07:29:28 +03:00
|
|
|
RCT_EXPORT_VIEW_PROPERTY(value, float);
|
2015-10-30 17:12:24 +03:00
|
|
|
RCT_EXPORT_VIEW_PROPERTY(step, float);
|
2015-11-17 19:43:13 +03:00
|
|
|
RCT_EXPORT_VIEW_PROPERTY(trackImage, UIImage);
|
2015-12-21 21:29:21 +03:00
|
|
|
RCT_EXPORT_VIEW_PROPERTY(minimumTrackImage, UIImage);
|
|
|
|
RCT_EXPORT_VIEW_PROPERTY(maximumTrackImage, UIImage);
|
2015-03-26 07:29:28 +03:00
|
|
|
RCT_EXPORT_VIEW_PROPERTY(minimumValue, float);
|
|
|
|
RCT_EXPORT_VIEW_PROPERTY(maximumValue, float);
|
2015-04-23 15:42:54 +03:00
|
|
|
RCT_EXPORT_VIEW_PROPERTY(minimumTrackTintColor, UIColor);
|
|
|
|
RCT_EXPORT_VIEW_PROPERTY(maximumTrackTintColor, UIColor);
|
2015-10-30 19:12:10 +03:00
|
|
|
RCT_EXPORT_VIEW_PROPERTY(onValueChange, RCTBubblingEventBlock);
|
2019-05-16 20:45:54 +03:00
|
|
|
RCT_EXPORT_VIEW_PROPERTY(onSlidingComplete, RCTDirectEventBlock);
|
2019-01-17 01:58:53 +03:00
|
|
|
RCT_EXPORT_VIEW_PROPERTY(thumbTintColor, UIColor);
|
2015-11-25 01:52:09 +03:00
|
|
|
RCT_EXPORT_VIEW_PROPERTY(thumbImage, UIImage);
|
2015-10-28 15:46:47 +03:00
|
|
|
RCT_CUSTOM_VIEW_PROPERTY(disabled, BOOL, RCTSlider)
|
|
|
|
{
|
|
|
|
if (json) {
|
|
|
|
view.enabled = !([RCTConvert BOOL:json]);
|
|
|
|
} else {
|
|
|
|
view.enabled = defaultView.enabled;
|
|
|
|
}
|
|
|
|
}
|
Fix NVC for RCTSlider
Summary:
## Android Failures
```
LOG SVC RCTSlider Invalid
LOG {
"missing": {
"directEventTypes": {
"topSlidingComplete": {
"registrationName": "onSlidingComplete"
}
}
},
"unexpected": {
"bubblingEventTypes": {
"paperValueChange": {
"phasedRegistrationNames": {
"captured": "onValueChangeCapture",
"bubbled": "onValueChange"
}
},
"topValueChange": {
"phasedRegistrationNames": {
"captured": "onValueChangeCapture",
"bubbled": "onValueChange"
}
}
},
"directEventTypes": {
"paperSlidingComplete": {
"registrationName": "onSlidingComplete"
}
},
"validAttributes": {
"disabled": true,
"maximumTrackImage": {
"process": "[Function resolveAssetSource]"
},
"minimumTrackImage": {
"process": "[Function resolveAssetSource]"
},
"thumbImage": {
"process": "[Function resolveAssetSource]"
},
"trackImage": {
"process": "[Function resolveAssetSource]"
}
}
},
"unequal": {}
}
```
## iOS Failures
```
LOG SVC RCTSlider Invalid
LOG {
"missing": {},
"unexpected": {
"bubblingEventTypes": {
"paperValueChange": {
"phasedRegistrationNames": {
"captured": "onValueChangeCapture",
"bubbled": "onValueChange"
}
}
},
"directEventTypes": {
"paperSlidingComplete": {
"registrationName": "onSlidingComplete"
}
},
"validAttributes": {
"enabled": true
}
},
"unequal": []
}
```
Reviewed By: yungsters
Differential Revision: D33409401
fbshipit-source-id: 519b6e35246e6671dbea1f374435d92937d96c1d
2022-01-15 03:29:10 +03:00
|
|
|
RCT_CUSTOM_VIEW_PROPERTY(enabled, BOOL, RCTSlider) {}
|
2015-03-10 00:42:55 +03:00
|
|
|
|
|
|
|
@end
|