Skip to content

Commit

Permalink
Fix RecentLimit (#139)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fintasys authored Jun 7, 2023
1 parent 3618170 commit 9581823
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 75 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.6.1
- Fix issue with RecentsLimit not working
- Add example for dynamic emoji columns based on screen width (thx to @timmaffett)

## 1.6.0
- Breaking Change: Fix behavior of recent tab, choose behavior (None, Recent, Popular) with `recentTabBehavior`. `showRecentsTab` was removed.
- Fix typo in ReadMe (thx @nathanbacon)
Expand Down
77 changes: 36 additions & 41 deletions example/lib/main-custom-font.dart
Original file line number Diff line number Diff line change
Expand Up @@ -191,47 +191,42 @@ class _MyAppState extends State<MyApp> {
},
onBackspacePressed: _onBackspacePressed,
config: Config(
columns: 7,
// Issue: https://github.com/flutter/flutter/issues/28894
emojiSizeMax: 32 *
(!foundation.kIsWeb && Platform.isIOS ? 1.30 : 1.0),
verticalSpacing: 0,
horizontalSpacing: 0,
gridPadding: EdgeInsets.zero,
initCategory: Category.RECENT,
bgColor: const Color(0xFFF2F2F2),
indicatorColor: Colors.blue,
iconColor: Colors.grey,
iconColorSelected: Colors.blue,
backspaceColor: Colors.blue,
skinToneDialogBgColor: Colors.white,
skinToneIndicatorColor: Colors.grey,
enableSkinTones: false,
recentTabBehavior: RecentTabBehavior.RECENT,
recentsLimit: 28,
replaceEmojiOnLimitExceed: false,
noRecents: const Text(
'No Recents',
style: TextStyle(fontSize: 20, color: Colors.black26),
textAlign: TextAlign.center,
),
loadingIndicator:
const Center(child: CircularProgressIndicator()),
tabIndicatorAnimDuration: kTabScrollDuration,
categoryIcons: const CategoryIcons(),
buttonMode: ButtonMode.MATERIAL,
checkPlatformCompatibility: false,
emojiTextStyle:
GoogleFonts.notoEmoji(color: Colors.black),
// or TextStyle(fontFamily: 'NotoColorEmoji',
// color: Colors.blueAccent)

// just for example: using only first 10 emojis
// from each category:
emojiSet: defaultEmojiSet
.map((e) =>
e.copyWith(emoji: e.emoji.take(10).toList()))
.toList()),
columns: 7,
// Issue: https://github.com/flutter/flutter/issues/28894
emojiSizeMax: 32 *
(!foundation.kIsWeb && Platform.isIOS ? 1.30 : 1.0),
verticalSpacing: 0,
horizontalSpacing: 0,
gridPadding: EdgeInsets.zero,
initCategory: Category.RECENT,
bgColor: const Color(0xFFF2F2F2),
indicatorColor: Colors.blue,
iconColor: Colors.grey,
iconColorSelected: Colors.blue,
backspaceColor: Colors.blue,
skinToneDialogBgColor: Colors.white,
skinToneIndicatorColor: Colors.grey,
enableSkinTones: false,
recentTabBehavior: RecentTabBehavior.RECENT,
recentsLimit: 28,
replaceEmojiOnLimitExceed: false,
noRecents: const Text(
'No Recents',
style: TextStyle(fontSize: 20, color: Colors.black26),
textAlign: TextAlign.center,
),
loadingIndicator:
const Center(child: CircularProgressIndicator()),
tabIndicatorAnimDuration: kTabScrollDuration,
categoryIcons: const CategoryIcons(),
buttonMode: ButtonMode.MATERIAL,
checkPlatformCompatibility: false,
emojiTextStyle: GoogleFonts.notoColorEmoji(),
// or for single colored Emoji use:
// GoogleFonts.notoEmoji(color: Colors.black),
// or TextStyle(fontFamily: 'NotoColorEmoji',
// color: Colors.blueAccent)),
),
)),
),
],
Expand Down
2 changes: 1 addition & 1 deletion example/lib/main-dynamic-columns.dart
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class _MyAppState extends State<MyApp> {
skinToneDialogBgColor: Colors.white,
skinToneIndicatorColor: Colors.grey,
enableSkinTones: true,
showRecentsTab: true,
recentTabBehavior: RecentTabBehavior.RECENT,
recentsLimit: 28,
replaceEmojiOnLimitExceed: false,
noRecents: const Text(
Expand Down
28 changes: 14 additions & 14 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ packages:
dependency: transitive
description:
name: characters
sha256: e6a326c8af69605aec75ed6c187d06b349707a27fbff8222ca9cc2cff167975c
sha256: "04a925763edad70e8443c99234dc3328f442e811f1d8fd1a72f1c8ad0f69a605"
url: "https://pub.dev"
source: hosted
version: "1.2.1"
version: "1.3.0"
collection:
dependency: transitive
description:
name: collection
sha256: cfc915e6923fe5ce6e153b0723c753045de46de1b4d63771530504004a45fae0
sha256: "4a07be6cb69c84d677a6c3096fcf960cc3285a8330b4603e0d463d15d9bd934c"
url: "https://pub.dev"
source: hosted
version: "1.17.0"
version: "1.17.1"
crypto:
dependency: transitive
description:
Expand All @@ -39,7 +39,7 @@ packages:
path: ".."
relative: true
source: path
version: "1.6.0"
version: "1.6.1"
ffi:
dependency: transitive
description:
Expand Down Expand Up @@ -70,18 +70,18 @@ packages:
dependency: "direct main"
description:
name: google_fonts
sha256: "8f099045e2f2a30e4d4d0a35f40c6bc941a8f2ca0e10ad9d214ee9edd3f37483"
sha256: "2776c66b3e97c6cdd58d1bd3281548b074b64f1fd5c8f82391f7456e38849567"
url: "https://pub.dev"
source: hosted
version: "3.0.1"
version: "4.0.5"
http:
dependency: transitive
description:
name: http
sha256: "2ed163531e071c2c6b7c659635112f24cb64ecbebf6af46b550d536c0b1aa112"
sha256: "4c3f04bfb64d3efd508d06b41b825542f08122d30bda4933fb95c069d22a4fa3"
url: "https://pub.dev"
source: hosted
version: "0.13.4"
version: "1.0.0"
http_parser:
dependency: transitive
description:
Expand All @@ -94,10 +94,10 @@ packages:
dependency: transitive
description:
name: js
sha256: "5528c2f391ededb7775ec1daa69e65a2d61276f7552de2b5f7b8d34ee9fd4ab7"
sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3
url: "https://pub.dev"
source: hosted
version: "0.6.5"
version: "0.6.7"
material_color_utilities:
dependency: transitive
description:
Expand All @@ -110,10 +110,10 @@ packages:
dependency: transitive
description:
name: meta
sha256: "6c268b42ed578a53088d834796959e4a1814b5e9e164f147f580a386e5decf42"
sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3"
url: "https://pub.dev"
source: hosted
version: "1.8.0"
version: "1.9.1"
path:
dependency: transitive
description:
Expand Down Expand Up @@ -328,5 +328,5 @@ packages:
source: hosted
version: "0.2.0"
sdks:
dart: ">=2.17.0 <3.0.0"
dart: ">=3.0.0 <4.0.0"
flutter: ">=3.0.0"
2 changes: 1 addition & 1 deletion example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ dependencies:
flutter:
sdk: flutter

google_fonts: ^3.0.1
google_fonts: ^4.0.4
emoji_picker_flutter:
path: ../

Expand Down
20 changes: 12 additions & 8 deletions lib/src/emoji_picker_internal_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import 'package:flutter/services.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'recent_emoji.dart';

/// Initial value for RecentEmoji
const initVal = 1;

/// Helper class that provides internal usage
class EmojiPickerInternalUtils {
// Establish communication with native
Expand Down Expand Up @@ -63,14 +66,12 @@ class EmojiPickerInternalUtils {
recentEmoji.removeAt(recentEmojiIndex);
}
// Add it first position
recentEmoji.insert(0, RecentEmoji(emoji, 0));
recentEmoji.insert(0, RecentEmoji(emoji, initVal));

// Limit entries to recentsLimit
if (recentEmoji.length == config.recentsLimit &&
config.replaceEmojiOnLimitExceed) {
recentEmoji =
recentEmoji.sublist(0, min(config.recentsLimit, recentEmoji.length));
}
recentEmoji =
recentEmoji.sublist(0, min(config.recentsLimit, recentEmoji.length));

// save locally
final prefs = await SharedPreferences.getInstance();
prefs.setString('recent', jsonEncode(recentEmoji));
Expand All @@ -95,15 +96,18 @@ class EmojiPickerInternalUtils {
} else if (recentEmoji.length == config.recentsLimit &&
config.replaceEmojiOnLimitExceed) {
// Replace latest emoji with the fresh one
recentEmoji[recentEmoji.length - 1] = RecentEmoji(emoji, 1);
recentEmoji[recentEmoji.length - 1] = RecentEmoji(emoji, initVal);
} else {
recentEmoji.add(RecentEmoji(emoji, 1));
recentEmoji.add(RecentEmoji(emoji, initVal));
}

// Sort by counter desc
recentEmoji.sort((a, b) => b.counter - a.counter);

// Limit entries to recentsLimit
recentEmoji =
recentEmoji.sublist(0, min(config.recentsLimit, recentEmoji.length));

// save locally
final prefs = await SharedPreferences.getInstance();
prefs.setString('recent', jsonEncode(recentEmoji));
Expand Down
18 changes: 9 additions & 9 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,18 @@ packages:
dependency: transitive
description:
name: characters
sha256: e6a326c8af69605aec75ed6c187d06b349707a27fbff8222ca9cc2cff167975c
sha256: "04a925763edad70e8443c99234dc3328f442e811f1d8fd1a72f1c8ad0f69a605"
url: "https://pub.dev"
source: hosted
version: "1.2.1"
version: "1.3.0"
collection:
dependency: transitive
description:
name: collection
sha256: cfc915e6923fe5ce6e153b0723c753045de46de1b4d63771530504004a45fae0
sha256: "4a07be6cb69c84d677a6c3096fcf960cc3285a8330b4603e0d463d15d9bd934c"
url: "https://pub.dev"
source: hosted
version: "1.17.0"
version: "1.17.1"
convert:
dependency: transitive
description:
Expand Down Expand Up @@ -151,10 +151,10 @@ packages:
dependency: transitive
description:
name: js
sha256: "5528c2f391ededb7775ec1daa69e65a2d61276f7552de2b5f7b8d34ee9fd4ab7"
sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3
url: "https://pub.dev"
source: hosted
version: "0.6.5"
version: "0.6.7"
logging:
dependency: transitive
description:
Expand Down Expand Up @@ -183,10 +183,10 @@ packages:
dependency: transitive
description:
name: meta
sha256: "6c268b42ed578a53088d834796959e4a1814b5e9e164f147f580a386e5decf42"
sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3"
url: "https://pub.dev"
source: hosted
version: "1.8.0"
version: "1.9.1"
mime:
dependency: transitive
description:
Expand Down Expand Up @@ -529,5 +529,5 @@ packages:
source: hosted
version: "3.1.2"
sdks:
dart: ">=2.19.0 <3.0.0"
dart: ">=3.0.0-0 <4.0.0"
flutter: ">=3.3.0"
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: emoji_picker_flutter
description: A Flutter package that provides an Emoji picker widget with 1500+ emojis in 8 categories.
version: 1.6.0
version: 1.6.1
homepage: https://github.com/Fintasys/emoji_picker_flutter

environment:
Expand Down

0 comments on commit 9581823

Please sign in to comment.