Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions React/Base/RCTUIKit.h
Original file line number Diff line number Diff line change
Expand Up @@ -476,11 +476,21 @@ NS_INLINE CGRect CGRectValue(NSValue *value)
// RCTUISlider

#if !TARGET_OS_OSX // [TODO(macOS GH#774)
#define RCTUISlider UISlider
typedef UISlider RCTUISlider;
#else
@interface RCTUISlider : NSSlider

@property (nonatomic, readonly) BOOL pressed;
@property (nonatomic, assign) float value;
@property (nonatomic, assign) float minimumValue;
@property (nonatomic, assign) float maximumValue;
@property (nonatomic, strong) NSColor *minimumTrackTintColor;
@property (nonatomic, strong) NSColor *maximumTrackTintColor;

- (void)setValue:(float)value animated:(BOOL)animated;

@end
#endif // ]TODO(macOS GH#774)n
#endif // ]TODO(macOS GH#774)

// RCTUILabel

Expand Down
13 changes: 12 additions & 1 deletion React/Base/macOS/RCTUIKit.m
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,6 @@ - (void)setAlwaysBounceVertical:(BOOL)alwaysBounceVertical
self.verticalScrollElasticity = alwaysBounceVertical ? NSScrollElasticityAllowed : NSScrollElasticityNone;
}


@end

BOOL RCTUIViewSetClipsToBounds(RCTPlatformView *view)
Expand Down Expand Up @@ -591,6 +590,18 @@ - (NSRect)constrainBoundsRect:(NSRect)proposedBounds

@end

// RCTUISlider

@implementation RCTUISlider {} // [TODO(macOS GH#774)

- (void)setValue:(float)value animated:(__unused BOOL)animated
{
self.animator.floatValue = value;
}

@end // ]TODO(macOS GH#774)


// RCTUILabel

@implementation RCTUILabel {} // [TODO(macOS GH#774)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,12 @@ - (instancetype)initWithFrame:(CGRect)frame

_sliderView = [[RCTUISlider alloc] initWithFrame:self.bounds]; // TODO(macOS GH#774)

#if !TARGET_OS_OSX // TODO(macOS GH#774)
[_sliderView addTarget:self action:@selector(onChange:) forControlEvents:UIControlEventValueChanged];
[_sliderView addTarget:self
action:@selector(sliderTouchEnd:)
forControlEvents:(UIControlEventTouchUpInside | UIControlEventTouchUpOutside | UIControlEventTouchCancel)];
#endif // TODO(macOS GH#774)

_sliderView.value = (float)defaultProps->value;

Expand All @@ -79,6 +81,7 @@ - (void)prepareForRecycle
self.maximumTrackImageCoordinator = nullptr;
self.thumbImageCoordinator = nullptr;

#if !TARGET_OS_OSX // TODO(macOS GH#774)
// 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];
Expand All @@ -87,6 +90,7 @@ - (void)prepareForRecycle
if (_thumbImage) {
[_sliderView setThumbImage:nil forState:UIControlStateNormal];
}
#endif // TODO(macOS GH#774)

_trackImage = nil;
_minimumTrackImage = nil;
Expand Down Expand Up @@ -131,10 +135,12 @@ - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &
_sliderView.enabled = !newSliderProps.disabled;
}

#if !TARGET_OS_OSX // TODO(macOS GH#774)
// `thumbTintColor`
if (oldSliderProps.thumbTintColor != newSliderProps.thumbTintColor) {
_sliderView.thumbTintColor = RCTUIColorFromSharedColor(newSliderProps.thumbTintColor);
}
#endif // TODO(macOS GH#774)

// `minimumTrackTintColor`
if (oldSliderProps.minimumTrackTintColor != newSliderProps.minimumTrackTintColor) {
Expand Down Expand Up @@ -237,13 +243,15 @@ - (void)setTrackImage:(UIImage *)trackImage
_trackImage = trackImage;
_minimumTrackImage = nil;
_maximumTrackImage = nil;
#if !TARGET_OS_OSX // TODO(macOS GH#774)
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];
#endif // TODO(macOS GH#774)
}

- (void)setMinimumTrackImage:(UIImage *)minimumTrackImage
Expand All @@ -254,10 +262,12 @@ - (void)setMinimumTrackImage:(UIImage *)minimumTrackImage

_trackImage = nil;
_minimumTrackImage = minimumTrackImage;
#if !TARGET_OS_OSX // TODO(macOS GH#774)
_minimumTrackImage =
[_minimumTrackImage resizableImageWithCapInsets:(UIEdgeInsets){0, _minimumTrackImage.size.width, 0, 0}
resizingMode:UIImageResizingModeStretch];
[_sliderView setMinimumTrackImage:_minimumTrackImage forState:UIControlStateNormal];
#endif // TODO(macOS GH#774)
}

- (void)setMaximumTrackImage:(UIImage *)maximumTrackImage
Expand All @@ -268,10 +278,12 @@ - (void)setMaximumTrackImage:(UIImage *)maximumTrackImage

_trackImage = nil;
_maximumTrackImage = maximumTrackImage;
#if !TARGET_OS_OSX // TODO(macOS GH#774)
_maximumTrackImage =
[_maximumTrackImage resizableImageWithCapInsets:(UIEdgeInsets){0, 0, 0, _maximumTrackImage.size.width}
resizingMode:UIImageResizingModeStretch];
[_sliderView setMaximumTrackImage:_maximumTrackImage forState:UIControlStateNormal];
#endif // TODO(macOS GH#774)
}

- (void)setThumbImage:(UIImage *)thumbImage
Expand All @@ -281,7 +293,9 @@ - (void)setThumbImage:(UIImage *)thumbImage
}

_thumbImage = thumbImage;
#if !TARGET_OS_OSX // TODO(macOS GH#774)
[_sliderView setThumbImage:thumbImage forState:UIControlStateNormal];
#endif // TODO(macOS GH#774)
}

- (void)onChange:(RCTUISlider *)sender // TODO(macOS GH#774)
Expand Down