mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
refactor(ReactNative/Slider): moved iOS sources to internal (#35365)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/35365 # Changelog: [iOS][Removed] - removed iOS sources of Slider module Reviewed By: NickGerleman Differential Revision: D41069547 fbshipit-source-id: 8faf96701f69e19074fafac45b1c95b939c2b1ac
This commit is contained in:
committed by
Facebook GitHub Bot
parent
4c40014d43
commit
fee9510b2d
@@ -522,7 +522,6 @@ rn_apple_xplat_cxx_library(
|
||||
react_fabric_component_plugin_provider("ScrollView", "RCTScrollViewCls"),
|
||||
react_fabric_component_plugin_provider("PullToRefreshView", "RCTPullToRefreshViewCls"),
|
||||
react_fabric_component_plugin_provider("ActivityIndicatorView", "RCTActivityIndicatorViewCls"),
|
||||
react_fabric_component_plugin_provider("Slider", "RCTSliderCls"),
|
||||
react_fabric_component_plugin_provider("Switch", "RCTSwitchCls"),
|
||||
react_fabric_component_plugin_provider("UnimplementedNativeView", "RCTUnimplementedNativeViewCls"),
|
||||
react_fabric_component_plugin_provider("Paragraph", "RCTParagraphCls"),
|
||||
|
||||
@@ -34,7 +34,6 @@ Class<RCTComponentViewProtocol> RCTSafeAreaViewCls(void) __attribute__((used));
|
||||
Class<RCTComponentViewProtocol> RCTScrollViewCls(void) __attribute__((used));
|
||||
Class<RCTComponentViewProtocol> RCTPullToRefreshViewCls(void) __attribute__((used));
|
||||
Class<RCTComponentViewProtocol> RCTActivityIndicatorViewCls(void) __attribute__((used));
|
||||
Class<RCTComponentViewProtocol> RCTSliderCls(void) __attribute__((used));
|
||||
Class<RCTComponentViewProtocol> RCTSwitchCls(void) __attribute__((used));
|
||||
Class<RCTComponentViewProtocol> RCTUnimplementedNativeViewCls(void) __attribute__((used));
|
||||
Class<RCTComponentViewProtocol> RCTParagraphCls(void) __attribute__((used));
|
||||
|
||||
@@ -22,7 +22,6 @@ Class<RCTComponentViewProtocol> RCTFabricComponentsProvider(const char *name) {
|
||||
{"ScrollView", RCTScrollViewCls},
|
||||
{"PullToRefreshView", RCTPullToRefreshViewCls},
|
||||
{"ActivityIndicatorView", RCTActivityIndicatorViewCls},
|
||||
{"Slider", RCTSliderCls},
|
||||
{"Switch", RCTSwitchCls},
|
||||
{"UnimplementedNativeView", RCTUnimplementedNativeViewCls},
|
||||
{"Paragraph", RCTParagraphCls},
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
#import <React/RCTViewComponentView.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
/**
|
||||
* UIView class for root <Slider> component.
|
||||
*/
|
||||
@interface RCTSliderComponentView : RCTViewComponentView
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@@ -1,352 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#import "RCTSliderComponentView.h"
|
||||
|
||||
#import <React/RCTConversions.h>
|
||||
#import <React/RCTImageResponseDelegate.h>
|
||||
#import <React/RCTImageResponseObserverProxy.h>
|
||||
|
||||
#import <react/renderer/components/rncore/EventEmitters.h>
|
||||
#import <react/renderer/components/rncore/Props.h>
|
||||
#import <react/renderer/components/slider/SliderComponentDescriptor.h>
|
||||
|
||||
#import "RCTFabricComponentsPlugins.h"
|
||||
|
||||
using namespace facebook::react;
|
||||
|
||||
@interface RCTSliderComponentView () <RCTImageResponseDelegate>
|
||||
@end
|
||||
|
||||
@implementation RCTSliderComponentView {
|
||||
UISlider *_sliderView;
|
||||
float _previousValue;
|
||||
|
||||
UIImage *_trackImage;
|
||||
UIImage *_minimumTrackImage;
|
||||
UIImage *_maximumTrackImage;
|
||||
UIImage *_thumbImage;
|
||||
|
||||
ImageResponseObserverCoordinator const *_trackImageCoordinator;
|
||||
ImageResponseObserverCoordinator const *_minimumTrackImageCoordinator;
|
||||
ImageResponseObserverCoordinator const *_maximumTrackImageCoordinator;
|
||||
ImageResponseObserverCoordinator const *_thumbImageCoordinator;
|
||||
|
||||
RCTImageResponseObserverProxy _trackImageResponseObserverProxy;
|
||||
RCTImageResponseObserverProxy _minimumTrackImageResponseObserverProxy;
|
||||
RCTImageResponseObserverProxy _maximumTrackImageResponseObserverProxy;
|
||||
RCTImageResponseObserverProxy _thumbImageResponseObserverProxy;
|
||||
}
|
||||
|
||||
- (instancetype)initWithFrame:(CGRect)frame
|
||||
{
|
||||
if (self = [super initWithFrame:frame]) {
|
||||
static const auto defaultProps = std::make_shared<const SliderProps>();
|
||||
_props = defaultProps;
|
||||
|
||||
_sliderView = [[UISlider alloc] initWithFrame:self.bounds];
|
||||
|
||||
[_sliderView addTarget:self action:@selector(onChange:) forControlEvents:UIControlEventValueChanged];
|
||||
[_sliderView addTarget:self
|
||||
action:@selector(sliderTouchEnd:)
|
||||
forControlEvents:(UIControlEventTouchUpInside | UIControlEventTouchUpOutside | UIControlEventTouchCancel)];
|
||||
|
||||
_sliderView.value = (float)defaultProps->value;
|
||||
|
||||
_trackImageResponseObserverProxy = RCTImageResponseObserverProxy(self);
|
||||
_minimumTrackImageResponseObserverProxy = RCTImageResponseObserverProxy(self);
|
||||
_maximumTrackImageResponseObserverProxy = RCTImageResponseObserverProxy(self);
|
||||
_thumbImageResponseObserverProxy = RCTImageResponseObserverProxy(self);
|
||||
|
||||
self.contentView = _sliderView;
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
// Recycling still doesn't work 100% properly
|
||||
// TODO: T40099998 implement recycling properly for Fabric Slider component
|
||||
- (void)prepareForRecycle
|
||||
{
|
||||
[super prepareForRecycle];
|
||||
|
||||
self.trackImageCoordinator = nullptr;
|
||||
self.minimumTrackImageCoordinator = nullptr;
|
||||
self.maximumTrackImageCoordinator = nullptr;
|
||||
self.thumbImageCoordinator = nullptr;
|
||||
|
||||
// Tint colors will be taken care of when props are set again - we just
|
||||
// need to make sure that image properties are reset here
|
||||
[_sliderView setMinimumTrackImage:nil forState:UIControlStateNormal];
|
||||
[_sliderView setMaximumTrackImage:nil forState:UIControlStateNormal];
|
||||
|
||||
if (_thumbImage) {
|
||||
[_sliderView setThumbImage:nil forState:UIControlStateNormal];
|
||||
}
|
||||
|
||||
_trackImage = nil;
|
||||
_minimumTrackImage = nil;
|
||||
_maximumTrackImage = nil;
|
||||
_thumbImage = nil;
|
||||
|
||||
const auto &props = *std::static_pointer_cast<const SliderProps>(_props);
|
||||
_sliderView.value = (float)props.value;
|
||||
_previousValue = (float)props.value;
|
||||
}
|
||||
|
||||
#pragma mark - RCTComponentViewProtocol
|
||||
|
||||
+ (ComponentDescriptorProvider)componentDescriptorProvider
|
||||
{
|
||||
return concreteComponentDescriptorProvider<SliderComponentDescriptor>();
|
||||
}
|
||||
|
||||
- (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps
|
||||
{
|
||||
const auto &oldSliderProps = *std::static_pointer_cast<const SliderProps>(_props);
|
||||
const auto &newSliderProps = *std::static_pointer_cast<const SliderProps>(props);
|
||||
|
||||
// `minimumValue`
|
||||
if (oldSliderProps.minimumValue != newSliderProps.minimumValue) {
|
||||
_sliderView.minimumValue = (float)newSliderProps.minimumValue;
|
||||
}
|
||||
|
||||
// `maximumValue`
|
||||
if (oldSliderProps.maximumValue != newSliderProps.maximumValue) {
|
||||
_sliderView.maximumValue = (float)newSliderProps.maximumValue;
|
||||
}
|
||||
|
||||
// `value`
|
||||
if (oldSliderProps.value != newSliderProps.value) {
|
||||
_sliderView.value = (float)newSliderProps.value;
|
||||
_previousValue = (float)newSliderProps.value;
|
||||
}
|
||||
|
||||
// `disabled`
|
||||
if (oldSliderProps.disabled != newSliderProps.disabled) {
|
||||
_sliderView.enabled = !newSliderProps.disabled;
|
||||
}
|
||||
|
||||
// `thumbTintColor`
|
||||
if (oldSliderProps.thumbTintColor != newSliderProps.thumbTintColor) {
|
||||
_sliderView.thumbTintColor = RCTUIColorFromSharedColor(newSliderProps.thumbTintColor);
|
||||
}
|
||||
|
||||
// `minimumTrackTintColor`
|
||||
if (oldSliderProps.minimumTrackTintColor != newSliderProps.minimumTrackTintColor) {
|
||||
_sliderView.minimumTrackTintColor = RCTUIColorFromSharedColor(newSliderProps.minimumTrackTintColor);
|
||||
}
|
||||
|
||||
// `maximumTrackTintColor`
|
||||
if (oldSliderProps.maximumTrackTintColor != newSliderProps.maximumTrackTintColor) {
|
||||
_sliderView.maximumTrackTintColor = RCTUIColorFromSharedColor(newSliderProps.maximumTrackTintColor);
|
||||
}
|
||||
|
||||
[super updateProps:props oldProps:oldProps];
|
||||
}
|
||||
|
||||
- (void)updateState:(facebook::react::State::Shared const &)state
|
||||
oldState:(facebook::react::State::Shared const &)oldState
|
||||
{
|
||||
auto _state = std::static_pointer_cast<SliderShadowNode::ConcreteState const>(state);
|
||||
auto _oldState = std::static_pointer_cast<SliderShadowNode::ConcreteState const>(oldState);
|
||||
|
||||
auto data = _state->getData();
|
||||
|
||||
bool havePreviousData = _oldState != nullptr;
|
||||
|
||||
auto getCoordinator = [](ImageRequest const *request) -> ImageResponseObserverCoordinator const * {
|
||||
if (request) {
|
||||
return &request->getObserverCoordinator();
|
||||
} else {
|
||||
return nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
if (!havePreviousData || data.getTrackImageSource() != _oldState->getData().getTrackImageSource()) {
|
||||
self.trackImageCoordinator = getCoordinator(&data.getTrackImageRequest());
|
||||
}
|
||||
|
||||
if (!havePreviousData || data.getMinimumTrackImageSource() != _oldState->getData().getMinimumTrackImageSource()) {
|
||||
self.minimumTrackImageCoordinator = getCoordinator(&data.getMinimumTrackImageRequest());
|
||||
}
|
||||
|
||||
if (!havePreviousData || data.getMaximumTrackImageSource() != _oldState->getData().getMaximumTrackImageSource()) {
|
||||
self.maximumTrackImageCoordinator = getCoordinator(&data.getMaximumTrackImageRequest());
|
||||
}
|
||||
|
||||
if (!havePreviousData || data.getThumbImageSource() != _oldState->getData().getThumbImageSource()) {
|
||||
self.thumbImageCoordinator = getCoordinator(&data.getThumbImageRequest());
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setTrackImageCoordinator:(const ImageResponseObserverCoordinator *)coordinator
|
||||
{
|
||||
if (_trackImageCoordinator) {
|
||||
_trackImageCoordinator->removeObserver(_trackImageResponseObserverProxy);
|
||||
}
|
||||
_trackImageCoordinator = coordinator;
|
||||
if (_trackImageCoordinator) {
|
||||
_trackImageCoordinator->addObserver(_trackImageResponseObserverProxy);
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setMinimumTrackImageCoordinator:(const ImageResponseObserverCoordinator *)coordinator
|
||||
{
|
||||
if (_minimumTrackImageCoordinator) {
|
||||
_minimumTrackImageCoordinator->removeObserver(_minimumTrackImageResponseObserverProxy);
|
||||
}
|
||||
_minimumTrackImageCoordinator = coordinator;
|
||||
if (_minimumTrackImageCoordinator) {
|
||||
_minimumTrackImageCoordinator->addObserver(_minimumTrackImageResponseObserverProxy);
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setMaximumTrackImageCoordinator:(const ImageResponseObserverCoordinator *)coordinator
|
||||
{
|
||||
if (_maximumTrackImageCoordinator) {
|
||||
_maximumTrackImageCoordinator->removeObserver(_maximumTrackImageResponseObserverProxy);
|
||||
}
|
||||
_maximumTrackImageCoordinator = coordinator;
|
||||
if (_maximumTrackImageCoordinator) {
|
||||
_maximumTrackImageCoordinator->addObserver(_maximumTrackImageResponseObserverProxy);
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setThumbImageCoordinator:(const ImageResponseObserverCoordinator *)coordinator
|
||||
{
|
||||
if (_thumbImageCoordinator) {
|
||||
_thumbImageCoordinator->removeObserver(_thumbImageResponseObserverProxy);
|
||||
}
|
||||
_thumbImageCoordinator = coordinator;
|
||||
if (_thumbImageCoordinator) {
|
||||
_thumbImageCoordinator->addObserver(_thumbImageResponseObserverProxy);
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setTrackImage:(UIImage *)trackImage
|
||||
{
|
||||
if ([trackImage isEqual:_trackImage]) {
|
||||
return;
|
||||
}
|
||||
|
||||
_trackImage = trackImage;
|
||||
_minimumTrackImage = nil;
|
||||
_maximumTrackImage = nil;
|
||||
CGFloat width = trackImage.size.width / 2;
|
||||
UIImage *minimumTrackImage = [trackImage resizableImageWithCapInsets:(UIEdgeInsets){0, width, 0, width}
|
||||
resizingMode:UIImageResizingModeStretch];
|
||||
UIImage *maximumTrackImage = [trackImage resizableImageWithCapInsets:(UIEdgeInsets){0, width, 0, width}
|
||||
resizingMode:UIImageResizingModeStretch];
|
||||
[_sliderView setMinimumTrackImage:minimumTrackImage forState:UIControlStateNormal];
|
||||
[_sliderView setMaximumTrackImage:maximumTrackImage forState:UIControlStateNormal];
|
||||
}
|
||||
|
||||
- (void)setMinimumTrackImage:(UIImage *)minimumTrackImage
|
||||
{
|
||||
if ([minimumTrackImage isEqual:_minimumTrackImage] && _trackImage == nil) {
|
||||
return;
|
||||
}
|
||||
|
||||
_trackImage = nil;
|
||||
_minimumTrackImage = minimumTrackImage;
|
||||
_minimumTrackImage =
|
||||
[_minimumTrackImage resizableImageWithCapInsets:(UIEdgeInsets){0, _minimumTrackImage.size.width, 0, 0}
|
||||
resizingMode:UIImageResizingModeStretch];
|
||||
[_sliderView setMinimumTrackImage:_minimumTrackImage forState:UIControlStateNormal];
|
||||
}
|
||||
|
||||
- (void)setMaximumTrackImage:(UIImage *)maximumTrackImage
|
||||
{
|
||||
if ([maximumTrackImage isEqual:_maximumTrackImage] && _trackImage == nil) {
|
||||
return;
|
||||
}
|
||||
|
||||
_trackImage = nil;
|
||||
_maximumTrackImage = maximumTrackImage;
|
||||
_maximumTrackImage =
|
||||
[_maximumTrackImage resizableImageWithCapInsets:(UIEdgeInsets){0, 0, 0, _maximumTrackImage.size.width}
|
||||
resizingMode:UIImageResizingModeStretch];
|
||||
[_sliderView setMaximumTrackImage:_maximumTrackImage forState:UIControlStateNormal];
|
||||
}
|
||||
|
||||
- (void)setThumbImage:(UIImage *)thumbImage
|
||||
{
|
||||
if ([thumbImage isEqual:_thumbImage]) {
|
||||
return;
|
||||
}
|
||||
|
||||
_thumbImage = thumbImage;
|
||||
[_sliderView setThumbImage:thumbImage forState:UIControlStateNormal];
|
||||
}
|
||||
|
||||
- (void)onChange:(UISlider *)sender
|
||||
{
|
||||
[self onChange:sender withContinuous:YES];
|
||||
}
|
||||
|
||||
- (void)sliderTouchEnd:(UISlider *)sender
|
||||
{
|
||||
[self onChange:sender withContinuous:NO];
|
||||
}
|
||||
|
||||
- (void)onChange:(UISlider *)sender withContinuous:(BOOL)continuous
|
||||
{
|
||||
float value = sender.value;
|
||||
|
||||
const auto &props = *std::static_pointer_cast<const SliderProps>(_props);
|
||||
|
||||
if (props.step > 0 && props.step <= (props.maximumValue - props.minimumValue)) {
|
||||
value = (float)std::max(
|
||||
props.minimumValue,
|
||||
std::min(
|
||||
props.maximumValue, props.minimumValue + round((value - props.minimumValue) / props.step) * props.step));
|
||||
|
||||
[_sliderView setValue:value animated:YES];
|
||||
}
|
||||
|
||||
if (continuous && _previousValue != value) {
|
||||
std::dynamic_pointer_cast<const SliderEventEmitter>(_eventEmitter)
|
||||
->onValueChange(SliderEventEmitter::OnValueChange{.value = static_cast<Float>(value)});
|
||||
}
|
||||
if (!continuous) {
|
||||
std::dynamic_pointer_cast<const SliderEventEmitter>(_eventEmitter)
|
||||
->onSlidingComplete(SliderEventEmitter::OnSlidingComplete{.value = static_cast<Float>(value)});
|
||||
}
|
||||
|
||||
_previousValue = value;
|
||||
}
|
||||
|
||||
#pragma mark - RCTImageResponseDelegate
|
||||
|
||||
- (void)didReceiveImage:(UIImage *)image metadata:(id)metadata fromObserver:(void const *)observer
|
||||
{
|
||||
if (observer == &_trackImageResponseObserverProxy) {
|
||||
self.trackImage = image;
|
||||
} else if (observer == &_minimumTrackImageResponseObserverProxy) {
|
||||
self.minimumTrackImage = image;
|
||||
} else if (observer == &_maximumTrackImageResponseObserverProxy) {
|
||||
self.maximumTrackImage = image;
|
||||
} else if (observer == &_thumbImageResponseObserverProxy) {
|
||||
self.thumbImage = image;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)didReceiveProgress:(float)progress fromObserver:(void const *)observer
|
||||
{
|
||||
}
|
||||
|
||||
- (void)didReceiveFailureFromObserver:(void const *)observer
|
||||
{
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Class<RCTComponentViewProtocol> RCTSliderCls(void)
|
||||
{
|
||||
return RCTSliderComponentView.class;
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
#import <React/RCTComponent.h>
|
||||
|
||||
@interface RCTSlider : UISlider
|
||||
|
||||
@property (nonatomic, copy) RCTBubblingEventBlock onValueChange;
|
||||
@property (nonatomic, copy) RCTDirectEventBlock onSlidingComplete;
|
||||
|
||||
@property (nonatomic, assign) float step;
|
||||
@property (nonatomic, assign) float lastValue;
|
||||
|
||||
@property (nonatomic, strong) UIImage *trackImage;
|
||||
@property (nonatomic, strong) UIImage *minimumTrackImage;
|
||||
@property (nonatomic, strong) UIImage *maximumTrackImage;
|
||||
|
||||
@property (nonatomic, strong) UIImage *thumbImage;
|
||||
|
||||
@end
|
||||
@@ -1,104 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#import "RCTSlider.h"
|
||||
|
||||
@implementation RCTSlider {
|
||||
float _unclippedValue;
|
||||
}
|
||||
|
||||
- (void)setValue:(float)value
|
||||
{
|
||||
_unclippedValue = value;
|
||||
super.value = value;
|
||||
}
|
||||
|
||||
- (void)setMinimumValue:(float)minimumValue
|
||||
{
|
||||
super.minimumValue = minimumValue;
|
||||
super.value = _unclippedValue;
|
||||
}
|
||||
|
||||
- (void)setMaximumValue:(float)maximumValue
|
||||
{
|
||||
super.maximumValue = maximumValue;
|
||||
super.value = _unclippedValue;
|
||||
}
|
||||
|
||||
- (void)setTrackImage:(UIImage *)trackImage
|
||||
{
|
||||
if (trackImage != _trackImage) {
|
||||
_trackImage = trackImage;
|
||||
CGFloat width = trackImage.size.width / 2;
|
||||
UIImage *minimumTrackImage = [trackImage resizableImageWithCapInsets:(UIEdgeInsets){0, width, 0, width}
|
||||
resizingMode:UIImageResizingModeStretch];
|
||||
UIImage *maximumTrackImage = [trackImage resizableImageWithCapInsets:(UIEdgeInsets){0, width, 0, width}
|
||||
resizingMode:UIImageResizingModeStretch];
|
||||
[self setMinimumTrackImage:minimumTrackImage forState:UIControlStateNormal];
|
||||
[self setMaximumTrackImage:maximumTrackImage forState:UIControlStateNormal];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setMinimumTrackImage:(UIImage *)minimumTrackImage
|
||||
{
|
||||
_trackImage = nil;
|
||||
minimumTrackImage =
|
||||
[minimumTrackImage resizableImageWithCapInsets:(UIEdgeInsets){0, minimumTrackImage.size.width, 0, 0}
|
||||
resizingMode:UIImageResizingModeStretch];
|
||||
[self setMinimumTrackImage:minimumTrackImage forState:UIControlStateNormal];
|
||||
}
|
||||
|
||||
- (UIImage *)minimumTrackImage
|
||||
{
|
||||
return [self thumbImageForState:UIControlStateNormal];
|
||||
}
|
||||
|
||||
- (void)setMaximumTrackImage:(UIImage *)maximumTrackImage
|
||||
{
|
||||
_trackImage = nil;
|
||||
maximumTrackImage =
|
||||
[maximumTrackImage resizableImageWithCapInsets:(UIEdgeInsets){0, 0, 0, maximumTrackImage.size.width}
|
||||
resizingMode:UIImageResizingModeStretch];
|
||||
[self setMaximumTrackImage:maximumTrackImage forState:UIControlStateNormal];
|
||||
}
|
||||
|
||||
- (UIImage *)maximumTrackImage
|
||||
{
|
||||
return [self thumbImageForState:UIControlStateNormal];
|
||||
}
|
||||
|
||||
- (void)setThumbImage:(UIImage *)thumbImage
|
||||
{
|
||||
[self setThumbImage:thumbImage forState:UIControlStateNormal];
|
||||
}
|
||||
|
||||
- (UIImage *)thumbImage
|
||||
{
|
||||
return [self thumbImageForState:UIControlStateNormal];
|
||||
}
|
||||
|
||||
- (void)accessibilityIncrement
|
||||
{
|
||||
[super accessibilityIncrement];
|
||||
if (_onSlidingComplete) {
|
||||
_onSlidingComplete(@{
|
||||
@"value" : @(self.value),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
- (void)accessibilityDecrement
|
||||
{
|
||||
[super accessibilityDecrement];
|
||||
if (_onSlidingComplete) {
|
||||
_onSlidingComplete(@{
|
||||
@"value" : @(self.value),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -1,12 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#import <React/RCTViewManager.h>
|
||||
|
||||
@interface RCTSliderManager : RCTViewManager
|
||||
|
||||
@end
|
||||
@@ -1,91 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#import "RCTSliderManager.h"
|
||||
|
||||
#import "RCTBridge.h"
|
||||
#import "RCTSlider.h"
|
||||
#import "UIView+React.h"
|
||||
|
||||
@implementation RCTSliderManager
|
||||
|
||||
RCT_EXPORT_MODULE()
|
||||
|
||||
- (UIView *)view
|
||||
{
|
||||
RCTSlider *slider = [RCTSlider new];
|
||||
[slider addTarget:self action:@selector(sliderValueChanged:) forControlEvents:UIControlEventValueChanged];
|
||||
[slider addTarget:self
|
||||
action:@selector(sliderTouchEnd:)
|
||||
forControlEvents:(UIControlEventTouchUpInside | UIControlEventTouchUpOutside | UIControlEventTouchCancel)];
|
||||
return slider;
|
||||
}
|
||||
|
||||
static void RCTSendSliderEvent(RCTSlider *sender, BOOL continuous)
|
||||
{
|
||||
float value = sender.value;
|
||||
|
||||
if (sender.step > 0 && sender.step <= (sender.maximumValue - sender.minimumValue)) {
|
||||
value =
|
||||
MAX(sender.minimumValue,
|
||||
MIN(sender.maximumValue,
|
||||
sender.minimumValue + round((sender.value - sender.minimumValue) / sender.step) * sender.step));
|
||||
|
||||
[sender setValue:value animated:YES];
|
||||
}
|
||||
|
||||
if (continuous) {
|
||||
if (sender.onValueChange && sender.lastValue != value) {
|
||||
sender.onValueChange(@{
|
||||
@"value" : @(value),
|
||||
});
|
||||
}
|
||||
} else {
|
||||
if (sender.onSlidingComplete) {
|
||||
sender.onSlidingComplete(@{
|
||||
@"value" : @(value),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
sender.lastValue = value;
|
||||
}
|
||||
|
||||
- (void)sliderValueChanged:(RCTSlider *)sender
|
||||
{
|
||||
RCTSendSliderEvent(sender, YES);
|
||||
}
|
||||
|
||||
- (void)sliderTouchEnd:(RCTSlider *)sender
|
||||
{
|
||||
RCTSendSliderEvent(sender, NO);
|
||||
}
|
||||
|
||||
RCT_EXPORT_VIEW_PROPERTY(value, float);
|
||||
RCT_EXPORT_VIEW_PROPERTY(step, float);
|
||||
RCT_EXPORT_VIEW_PROPERTY(trackImage, UIImage);
|
||||
RCT_EXPORT_VIEW_PROPERTY(minimumTrackImage, UIImage);
|
||||
RCT_EXPORT_VIEW_PROPERTY(maximumTrackImage, UIImage);
|
||||
RCT_EXPORT_VIEW_PROPERTY(minimumValue, float);
|
||||
RCT_EXPORT_VIEW_PROPERTY(maximumValue, float);
|
||||
RCT_EXPORT_VIEW_PROPERTY(minimumTrackTintColor, UIColor);
|
||||
RCT_EXPORT_VIEW_PROPERTY(maximumTrackTintColor, UIColor);
|
||||
RCT_EXPORT_VIEW_PROPERTY(onValueChange, RCTBubblingEventBlock);
|
||||
RCT_EXPORT_VIEW_PROPERTY(onSlidingComplete, RCTDirectEventBlock);
|
||||
RCT_EXPORT_VIEW_PROPERTY(thumbTintColor, UIColor);
|
||||
RCT_EXPORT_VIEW_PROPERTY(thumbImage, UIImage);
|
||||
RCT_CUSTOM_VIEW_PROPERTY(disabled, BOOL, RCTSlider)
|
||||
{
|
||||
if (json) {
|
||||
view.enabled = !([RCTConvert BOOL:json]);
|
||||
} else {
|
||||
view.enabled = defaultView.enabled;
|
||||
}
|
||||
}
|
||||
RCT_CUSTOM_VIEW_PROPERTY(enabled, BOOL, RCTSlider) {}
|
||||
|
||||
@end
|
||||
@@ -174,16 +174,6 @@ Pod::Spec.new do |s|
|
||||
sss.pod_target_xcconfig = { "HEADER_SEARCH_PATHS" => "\"$(PODS_TARGET_SRCROOT)/ReactCommon\" \"$(PODS_ROOT)/RCT-Folly\"" }
|
||||
end
|
||||
|
||||
ss.subspec "slider" do |sss|
|
||||
sss.dependency folly_dep_name, folly_version
|
||||
sss.compiler_flags = folly_compiler_flags
|
||||
sss.source_files = "react/renderer/components/slider/**/*.{m,mm,cpp,h}"
|
||||
sss.exclude_files = "react/renderer/components/slider/tests/**/*",
|
||||
"react/renderer/components/slider/platform/android"
|
||||
sss.header_dir = "react/renderer/components/slider"
|
||||
sss.pod_target_xcconfig = { "HEADER_SEARCH_PATHS" => "\"$(PODS_TARGET_SRCROOT)/ReactCommon\" \"$(PODS_ROOT)/RCT-Folly\"" }
|
||||
end
|
||||
|
||||
ss.subspec "text" do |sss|
|
||||
sss.dependency folly_dep_name, folly_version
|
||||
sss.compiler_flags = folly_compiler_flags
|
||||
|
||||
@@ -372,7 +372,6 @@ PODS:
|
||||
- React-Fabric/components/root (= 1000.0.0)
|
||||
- React-Fabric/components/safeareaview (= 1000.0.0)
|
||||
- React-Fabric/components/scrollview (= 1000.0.0)
|
||||
- React-Fabric/components/slider (= 1000.0.0)
|
||||
- React-Fabric/components/text (= 1000.0.0)
|
||||
- React-Fabric/components/textinput (= 1000.0.0)
|
||||
- React-Fabric/components/unimplementedview (= 1000.0.0)
|
||||
@@ -445,14 +444,6 @@ PODS:
|
||||
- React-jsi (= 1000.0.0)
|
||||
- React-jsiexecutor (= 1000.0.0)
|
||||
- ReactCommon/turbomodule/core (= 1000.0.0)
|
||||
- React-Fabric/components/slider (1000.0.0):
|
||||
- RCT-Folly/Fabric (= 2021.07.22.00)
|
||||
- RCTRequired (= 1000.0.0)
|
||||
- RCTTypeSafety (= 1000.0.0)
|
||||
- React-graphics (= 1000.0.0)
|
||||
- React-jsi (= 1000.0.0)
|
||||
- React-jsiexecutor (= 1000.0.0)
|
||||
- ReactCommon/turbomodule/core (= 1000.0.0)
|
||||
- React-Fabric/components/text (1000.0.0):
|
||||
- RCT-Folly/Fabric (= 2021.07.22.00)
|
||||
- RCTRequired (= 1000.0.0)
|
||||
@@ -944,7 +935,7 @@ SPEC CHECKSUMS:
|
||||
FlipperKit: cbdee19bdd4e7f05472a66ce290f1b729ba3cb86
|
||||
fmt: ff9d55029c625d3757ed641535fd4a75fedc7ce9
|
||||
glog: 04b94705f318337d7ead9e6d17c019bd9b1f6b1b
|
||||
hermes-engine: 1b25fd843452b19b888d47a6022bc0623ede0f38
|
||||
hermes-engine: 41b1b184a76a464385ebd97d798f6ee2468ebbae
|
||||
libevent: 4049cae6c81cdb3654a443be001fb9bdceff7913
|
||||
OpenSSL-Universal: ebc357f1e6bc71fa463ccb2fe676756aff50e88c
|
||||
RCT-Folly: 424b8c9a7a0b9ab2886ffe9c3b041ef628fd4fb1
|
||||
@@ -956,7 +947,7 @@ SPEC CHECKSUMS:
|
||||
React-Core: 719bec4b41c93b1affb1e2c3a43956ec482ecb9f
|
||||
React-CoreModules: feaa45c54c58e1420981f6dd544c8b3d01200caa
|
||||
React-cxxreact: 97903bdac0fb53409663fd312e2183ae1dd730e5
|
||||
React-Fabric: 4d08ce0b0f15513b2724ae1000c2aaedf73ebc32
|
||||
React-Fabric: 62b9929a7345f941d8833630f37d9440b2dda438
|
||||
React-graphics: cb8a85648695c60f33a00d732b985f734d1470d8
|
||||
React-hermes: e35ea664b36773a2ce84c583febf1396080e59f7
|
||||
React-jsi: e4c75a1cf727c8761908ac2eeb1084e47ba88a26
|
||||
@@ -977,7 +968,7 @@ SPEC CHECKSUMS:
|
||||
React-RCTTest: 81ebfa8c2e1b0b482effe12485e6486dc0ff70d7
|
||||
React-RCTText: 4e5ae05b778a0ed2b22b012af025da5e1a1c4e54
|
||||
React-RCTVibration: ecfd04c1886a9c9a4e31a466c0fbcf6b36e92fde
|
||||
React-rncore: 08566b41339706758229f407c8907b2f7987f058
|
||||
React-rncore: 7fff654903b760e6fa14bb0141c92bf0861534f0
|
||||
React-runtimeexecutor: c7b2cd6babf6cc50340398bfbb7a9da13c93093f
|
||||
ReactCommon: a11d5523be510a2d75e50e435de607297072172a
|
||||
ScreenshotManager: 37152a3841a53f2de5c0013c58835b8738894553
|
||||
|
||||
Reference in New Issue
Block a user