Skip to content

Commit

Permalink
Internal change.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 663080530
  • Loading branch information
Nobody authored and material-automation committed Aug 14, 2024
1 parent b1164e6 commit eb0edee
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
8 changes: 8 additions & 0 deletions components/Slider/src/MDCSlider.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@
static inline UIColor *MDCThumbTrackDefaultColor(void) { return MDCPalette.bluePalette.tint500; }

@interface MDCSlider () <MDCThumbTrackDelegate>
#if !TARGET_OS_VISION
@property(nonnull, nonatomic, strong)
UIImpactFeedbackGenerator *feedbackGenerator API_AVAILABLE(ios(10.0));
#endif
@property(nonatomic) CGFloat previousValue;
@end

Expand Down Expand Up @@ -119,8 +121,10 @@ - (void)commonMDCSliderInit {
_mdc_overrideBaseElevation = -1;

_hapticsEnabled = YES;
#if !TARGET_OS_VISION
self.feedbackGenerator =
[[UIImpactFeedbackGenerator alloc] initWithStyle:UIImpactFeedbackStyleLight];
#endif
_shouldEnableHapticsForAllDiscreteValues = NO;

_previousValue = -CGFLOAT_MAX;
Expand Down Expand Up @@ -706,6 +710,7 @@ - (BOOL)accessibilityActivate {
- (void)thumbTrackValueChanged:(__unused MDCThumbTrack *)thumbTrack {
[self sendActionsForControlEvents:UIControlEventValueChanged];
UIAccessibilityPostNotification(UIAccessibilityAnnouncementNotification, self.accessibilityValue);
#if !TARGET_OS_VISION
if (self.hapticsEnabled && _previousValue != _thumbTrack.value) {
BOOL valueCrossesAboveAnchor = (_previousValue < _thumbTrack.filledTrackAnchorValue &&
_thumbTrack.filledTrackAnchorValue <= _thumbTrack.value);
Expand All @@ -719,11 +724,14 @@ - (void)thumbTrackValueChanged:(__unused MDCThumbTrack *)thumbTrack {
[self.feedbackGenerator impactOccurred];
}
}
#endif
self.previousValue = _thumbTrack.value;
}

- (void)thumbTrackTouchDown:(__unused MDCThumbTrack *)thumbTrack {
#if !TARGET_OS_VISION
[self.feedbackGenerator prepare];
#endif
[self sendActionsForControlEvents:UIControlEventTouchDown];
}

Expand Down
8 changes: 7 additions & 1 deletion components/private/ThumbTrack/src/MDCThumbView.m
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,13 @@ - (instancetype)initWithFrame:(CGRect)frame {
if (self) {
// TODO: Remove once MDCShadowLayer is rasterized by default.
self.layer.shouldRasterize = YES;
self.layer.rasterizationScale = [UIScreen mainScreen].scale;
if (@available(iOS 13.0, *)) {
self.layer.rasterizationScale = UITraitCollection.currentTraitCollection.displayScale;
} else {
#if !TARGET_OS_VISION
self.layer.rasterizationScale = UIScreen.mainScreen.scale;
#endif
}

_shadowColor = UIColor.blackColor;
_shapeGenerator = [[MDCRectangleShapeGenerator alloc] init];
Expand Down

0 comments on commit eb0edee

Please sign in to comment.