add haptic feedback on copy (#3401)

* add haptic feedback on copy

* revert gradle
This commit is contained in:
malik1004x
2026-07-14 16:42:15 +03:00
committed by GitHub
parent 58e8afedca
commit 723ee479fc
4 changed files with 36 additions and 51 deletions
+2 -1
View File
@@ -1,4 +1,5 @@
org.gradle.jvmargs=-Xmx6144M
android.useAndroidX=true
android.enableJetifier=true
android.ndk.suppressMinSdkVersionError=21
android.ndk.suppressMinSdkVersionError=21
+6 -7
View File
@@ -271,6 +271,12 @@ class _NewReceivePageState extends State<NewReceivePage> {
largeQrMode: _largeQrMode,
showAccountsButton: widget.addressListViewModel.hasAddressList,
showLabelButton: widget.addressListViewModel.hasAddressList && !hasLabel,
copyData: widget.addressListViewModel.hasPayjoin
? null
: ClipboardData(
text: widget.addressListViewModel.displayAmount.isEmpty
? widget.addressListViewModel.uri.address
: widget.addressListViewModel.uri.toString()),
onCopyButtonPressed: () {
if (widget.addressListViewModel.hasPayjoin) {
showModalBottomSheet(
@@ -278,13 +284,6 @@ class _NewReceivePageState extends State<NewReceivePage> {
context: context,
builder: (context) =>
PayjoinCopyModal(uri: widget.addressListViewModel.uri));
} else {
Clipboard.setData(
ClipboardData(
text: widget.addressListViewModel.displayAmount.isEmpty
? widget.addressListViewModel.uri.address
: widget.addressListViewModel.uri.toString()),
);
}
},
onAmountButtonPressed: () {
+1
View File
@@ -30,6 +30,7 @@ class _CopyWrapperState extends State<CopyWrapper> {
void handleCopy() async {
if (widget.data == null) return;
ClipboardUtil.setSensitiveDataToClipboard(widget.data!, isSensitive: widget.isSensitive);
HapticFeedback.mediumImpact();
if (await shouldShowCopied()) {
setState(() => copied = true);
Future.delayed(widget.duration, () {
@@ -4,9 +4,12 @@ import 'package:cake_wallet/generated/i18n.dart';
import 'package:cake_wallet/new-ui/widgets/modern_button.dart';
import 'package:device_info_plus/device_info_plus.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:cake_wallet/new-ui/widgets/copy_wrapper.dart';
class ReceiveBottomButtons extends StatefulWidget {
final bool largeQrMode;
final ClipboardData? copyData;
final VoidCallback onCopyButtonPressed;
final VoidCallback onAmountButtonPressed;
final VoidCallback onLabelButtonPressed;
@@ -15,7 +18,6 @@ class ReceiveBottomButtons extends StatefulWidget {
final bool showAccountsButton;
const ReceiveBottomButtons({
super.key,
required this.largeQrMode,
required this.onCopyButtonPressed,
required this.onAccountsButtonPressed,
@@ -23,6 +25,8 @@ class ReceiveBottomButtons extends StatefulWidget {
required this.onLabelButtonPressed,
required this.showLabelButton,
required this.showAccountsButton,
required this.copyData,
super.key,
});
@override
@@ -30,17 +34,6 @@ class ReceiveBottomButtons extends StatefulWidget {
}
class _ReceiveBottomButtonsState extends State<ReceiveBottomButtons> {
bool copied = false;
void handleCopy() async {
widget.onCopyButtonPressed();
if (await shouldShowCopied()) {
setState(() => copied = true);
Future.delayed(const Duration(milliseconds: 1200), () {
if (mounted) setState(() => copied = false);
});
}
}
@override
Widget build(BuildContext context) {
@@ -63,19 +56,28 @@ class _ReceiveBottomButtonsState extends State<ReceiveBottomButtons> {
mainAxisAlignment: MainAxisAlignment.center,
spacing: 16,
children: [
AnimatedSwitcher(
duration: Duration(milliseconds: 200),
child: ModernButton.svg(
key: ValueKey(copied),
size: 60,
iconSize: 32,
svgPath: "assets/new-ui/copy.svg",
onPressed: handleCopy,
label: copied ? S.of(context).copied : S.of(context).copy,
iconColor: copied ? Theme.of(context).colorScheme.primary : Theme.of(context).colorScheme.surfaceContainer,
backgroundColor: copied ? Theme.of(context).colorScheme.surfaceContainerHighest : Theme.of(context).colorScheme.primary,
),
),
GestureDetector(
onTap: widget.copyData == null ? widget.onCopyButtonPressed : null,
child: IgnorePointer(
ignoring: widget.copyData == null,
child: CopyWrapper(
data: widget.copyData,
builder: (context, copied) => AnimatedSwitcher(
duration: Duration(milliseconds: 200),
child: IgnorePointer(
child: ModernButton.svg(
key: ValueKey(copied),
size: 60,
iconSize: 32,
svgPath: "assets/new-ui/copy.svg",
onPressed: () {},
label: copied ? S.of(context).copied : S.of(context).copy,
iconColor: copied ? Theme.of(context).colorScheme.primary : Theme.of(context).colorScheme.surfaceContainer,
backgroundColor: copied ? Theme.of(context).colorScheme.surfaceContainerHighest : Theme.of(context).colorScheme.primary,
),
),
),
),),),
ModernButton.svg(
size: 60,
iconSize: 32,
@@ -103,22 +105,4 @@ class _ReceiveBottomButtonsState extends State<ReceiveBottomButtons> {
),
);
}
// android 13 (sdk 33) added a built-in "text was copied to clipboard" ui element
// older android and iphone still needs an indicator though
Future<bool> shouldShowCopied() async {
if (!Platform.isAndroid) return true;
try {
final deviceInfo = DeviceInfoPlugin();
final androidInfo = await deviceInfo.androidInfo;
final sdk = androidInfo.version.sdkInt;
return sdk < 33;
} catch (_) {
return true;
}
}
}