@@ -116,9 +116,10 @@ - (instancetype)initWithText:(NSString *)text {
116116- (void )_roundedButtonCommonInit TOROUNDEDBUTTON_OBJC_DIRECT {
117117 // Default properties (Make sure they're not overriding IB)
118118 _tappedTextAlpha = (_tappedTextAlpha > FLT_EPSILON) ?: 1 .0f ;
119- _tapAnimationDuration = (_tapAnimationDuration > FLT_EPSILON) ?: 0 .4f ;
119+ _tapDownAnimationDuration = (_tapDownAnimationDuration > FLT_EPSILON) ?: 0 .1f ;
120+ _tapUpAnimationDuration = (_tapUpAnimationDuration > FLT_EPSILON) ?: 0 .4f ;
120121 _tappedButtonScale = (_tappedButtonScale > FLT_EPSILON) ?: 0 .97f ;
121- _tappedTintColorBrightnessOffset = !TORoundedButtonFloatIsZero (_tappedTintColorBrightnessOffset) ?: - 0 . 15f ;
122+ _tappedTintColorBrightnessOffset = !TORoundedButtonFloatIsZero (_tappedTintColorBrightnessOffset) ?: 0 . 25f ;
122123 _contentInset = (UIEdgeInsets){15.0 , 15.0 , 15.0 , 15.0 };
123124 _blurStyle = UIBlurEffectStyleDark;
124125 _impactStyle = TORoundedButtonImpactStyleMedium;
@@ -257,7 +258,11 @@ - (void)tintColorDidChange {
257258- (void )traitCollectionDidChange : (UITraitCollection *)previousTraitCollection {
258259 [super traitCollectionDidChange: previousTraitCollection];
259260 [self setNeedsLayout ];
260- [self _updateTappedTintColorForTintColor ];
261+ if (@available (iOS 13.0 , *)) {
262+ if ([previousTraitCollection hasDifferentColorAppearanceComparedToTraitCollection: self .traitCollection]) {
263+ [self _updateTappedTintColorForTintColor ];
264+ }
265+ }
261266}
262267
263268#pragma mark - View Layout -
@@ -385,7 +390,7 @@ - (void)_didDragInside {
385390
386391- (void )_performTapAnimation : (void (^)(void ))animations
387392 completion : (void (^_Nullable)(BOOL finished))completion TOROUNDEDBUTTON_OBJC_DIRECT {
388- [UIView animateWithDuration: _tapAnimationDuration
393+ [UIView animateWithDuration: _isTapped ? _tapDownAnimationDuration : _tapUpAnimationDuration
389394 delay: 0 .0f
390395 usingSpringWithDamping: 1 .0f
391396 initialSpringVelocity: 0 .5f
@@ -656,7 +661,6 @@ - (void)_updateTappedTintColorForTintColor TOROUNDEDBUTTON_OBJC_DIRECT {
656661 if (@available (iOS 13.0 , *)) {
657662 tintColor = [tintColor resolvedColorWithTraitCollection: self .traitCollection];
658663 }
659-
660664 _tappedTintColor = [self _brightnessAdjustedColorWithColor: tintColor
661665 amount: _tappedTintColorBrightnessOffset];
662666}
@@ -669,13 +673,63 @@ - (UIColor *)_labelBackgroundColor TOROUNDEDBUTTON_OBJC_DIRECT {
669673}
670674
671675- (UIColor *)_brightnessAdjustedColorWithColor : (UIColor *)color amount : (CGFloat)amount TOROUNDEDBUTTON_OBJC_DIRECT {
672- if (!color) { return nil ; }
676+ // Clamp provided value just in case
677+ amount = fmaxf (0.0 , fminf (amount, 1.0 ));
678+
679+ CGFloat h = 0 , s = 0 , b = 0 , a = 0 ;
680+ if (![color getHue: &h saturation: &s brightness: &b alpha: &a]) { return color; }
681+
682+ // Zones:
683+ // - RED - 0.0 / 1.0
684+ // - GREEN - 0.33
685+ // - BLUE - 0.66
686+ BOOL isRed = (h < 0 .05f || h > 0 .95f );
687+ BOOL isGreen = (h > 0 .25f && h < 0 .45f );
688+ BOOL isBlue = (h > 0 .55f && h < 0 .75f );
689+
690+ CGFloat hueShift = 0 .0f ;
691+ CGFloat satBoost = 0 .0f ;
692+ CGFloat brightnessAdd = 0 .0f ;
693+
694+ if (isRed) {
695+ // systemRed - nudge toward orange/yellow, slightly brighter, modest sat
696+ hueShift = 0 .08f * amount; // towards yellow
697+ satBoost = 0 .10f * amount;
698+ brightnessAdd = 0 .18f * amount;
699+ }
700+ else if (isGreen) {
701+ // systemGreen - nudge toward yellow-green, clearly brighter + more vivid
702+ hueShift = -0 .08f * amount; // toward yellow-green
703+ satBoost = 0 .25f * amount; // push harder here
704+ brightnessAdd = 0 .22f * amount; // stronger lift so it’s clearly changed
705+ }
706+ else if (isBlue) {
707+ // systemBlue - nudge toward cyan, bright + vivid
708+ hueShift = -0 .06f * amount; // toward cyan
709+ satBoost = 0 .18f * amount;
710+ brightnessAdd = 0 .18f * amount;
711+ }
712+ else {
713+ // Everything else: mild generic brighten + hue wobble
714+ hueShift = -0 .03f * amount;
715+ satBoost = 0 .15f * amount;
716+ brightnessAdd = 0 .18f * amount;
717+ }
718+
719+ // Apply hue shift with wrapping
720+ CGFloat newH = h + hueShift;
721+ if (newH < 0 .0f ) { newH += 1 .0f ; }
722+ if (newH > 1 .0f ) { newH -= 1 .0f ; }
723+
724+ // Brighten: constant bump + small relative lift if not already maxed
725+ CGFloat newB = b + brightnessAdd + (1 .0f - b) * 0 .2f * amount;
726+ newB = fminf (newB, 1 .0f );
727+
728+ // Saturation boost, clamped
729+ CGFloat newS = s + satBoost;
730+ newS = fminf (newS, 1 .0f );
673731
674- CGFloat h, s, b, a;
675- if (![color getHue: &h saturation: &s brightness: &b alpha: &a]) { return nil ; }
676- b += amount;
677- b = MAX (b, 0 .0f ); b = MIN (b, 1 .0f );
678- return [UIColor colorWithHue: h saturation: s brightness: b alpha: a];
732+ return [UIColor colorWithHue: newH saturation: newS brightness: newB alpha: a];
679733}
680734
681735@end
0 commit comments