Skip to content

Commit

Permalink
Backspace onLongPress callback added
Browse files Browse the repository at this point in the history
  • Loading branch information
vedasjad committed Dec 15, 2023
1 parent 380cd4d commit 273e2ff
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions lib/src/default_emoji_picker_view.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:async';

import 'package:emoji_picker_flutter/emoji_picker_flutter.dart';
import 'package:emoji_picker_flutter/src/skin_tone_overlay.dart';
import 'package:flutter/material.dart';
Expand All @@ -15,6 +17,7 @@ class DefaultEmojiPickerView extends EmojiPickerBuilder {
class _DefaultEmojiPickerViewState extends State<DefaultEmojiPickerView>
with SingleTickerProviderStateMixin, SkinToneOverlayStateMixin {
final double _tabBarHeight = 46;
Timer? _onBackspacePressedCallbackTimer;

late PageController _pageController;
late TabController _tabController;
Expand Down Expand Up @@ -45,6 +48,7 @@ class _DefaultEmojiPickerViewState extends State<DefaultEmojiPickerView>
_pageController.dispose();
_tabController.dispose();
_scrollController.dispose();
_onBackspacePressedCallbackTimer?.cancel();
super.dispose();
}

Expand Down Expand Up @@ -112,15 +116,18 @@ class _DefaultEmojiPickerViewState extends State<DefaultEmojiPickerView>
if (widget.state.onBackspacePressed != null) {
return Material(
type: MaterialType.transparency,
child: IconButton(
child: GestureDetector(
onLongPressStart: (_) => _startOnBackspacePressedCallback(),
onLongPressEnd: (_) => _stopOnBackspacePressedCallback(),
child: IconButton(
padding: const EdgeInsets.only(bottom: 2),
icon: Icon(
Icons.backspace,
color: widget.config.backspaceColor,
),
onPressed: () {
widget.state.onBackspacePressed!();
}),
onPressed: () => widget.state.onBackspacePressed!(),
),
),
);
}
return const SizedBox.shrink();
Expand Down Expand Up @@ -203,4 +210,16 @@ class _DefaultEmojiPickerViewState extends State<DefaultEmojiPickerView>
widget.state.onEmojiSelected(category, emoji);
closeSkinToneOverlay();
}

void _startOnBackspacePressedCallback() {
const callbackInterval = Duration(milliseconds: 75);
_onBackspacePressedCallbackTimer =
Timer.periodic(callbackInterval, (timer) {
widget.state.onBackspacePressed!();
});
}

void _stopOnBackspacePressedCallback() {
_onBackspacePressedCallbackTimer?.cancel();
}
}

0 comments on commit 273e2ff

Please sign in to comment.