refactor: Trigger haptic feedback on tap down for immediate response

This commit is contained in:
cogwheel0
2025-10-14 22:35:27 +05:30
parent 762155500b
commit 146cbfb492

View File

@@ -64,23 +64,21 @@ class ConduitButton extends ConsumerWidget {
label: semanticLabel, label: semanticLabel,
button: true, button: true,
enabled: !isLoading && onPressed != null, enabled: !isLoading && onPressed != null,
child: GestureDetector(
// Trigger haptic feedback on tap down for immediate tactile response
onTapDown: (onPressed != null && !isLoading)
? (_) {
PlatformService.hapticFeedbackWithSettings(
type: isDestructive ? HapticType.warning : HapticType.light,
hapticEnabled: hapticEnabled,
);
}
: null,
child: SizedBox( child: SizedBox(
width: isFullWidth ? double.infinity : width, width: isFullWidth ? double.infinity : width,
height: isCompact ? TouchTarget.medium : TouchTarget.comfortable, height: isCompact ? TouchTarget.medium : TouchTarget.comfortable,
child: ElevatedButton( child: ElevatedButton(
onPressed: isLoading onPressed: isLoading ? null : onPressed,
? null
: () {
if (onPressed != null) {
PlatformService.hapticFeedbackWithSettings(
type: isDestructive
? HapticType.warning
: HapticType.light,
hapticEnabled: hapticEnabled,
);
onPressed!();
}
},
style: ElevatedButton.styleFrom( style: ElevatedButton.styleFrom(
backgroundColor: backgroundColor, backgroundColor: backgroundColor,
foregroundColor: textColor, foregroundColor: textColor,
@@ -102,7 +100,8 @@ class ConduitButton extends ConsumerWidget {
child: isLoading child: isLoading
? Semantics( ? Semantics(
label: label:
AppLocalizations.of(context)?.loadingContent ?? 'Loading', AppLocalizations.of(context)?.loadingContent ??
'Loading',
excludeSemantics: true, excludeSemantics: true,
child: SizedBox( child: SizedBox(
width: IconSize.small, width: IconSize.small,
@@ -122,7 +121,8 @@ class ConduitButton extends ConsumerWidget {
SizedBox(width: Spacing.iconSpacing), SizedBox(width: Spacing.iconSpacing),
], ],
Flexible( Flexible(
child: EnhancedAccessibilityService.createAccessibleText( child:
EnhancedAccessibilityService.createAccessibleText(
text, text,
style: AppTypography.standard.copyWith( style: AppTypography.standard.copyWith(
fontWeight: FontWeight.w600, fontWeight: FontWeight.w600,
@@ -135,6 +135,7 @@ class ConduitButton extends ConsumerWidget {
), ),
), ),
), ),
),
); );
} }
} }