Skip to content

Commit

Permalink
Add emoji sticker panel (MixinNetwork#733)
Browse files Browse the repository at this point in the history
* add emoji sticker panel.

* keep emoji group selection

* refactor provider

* make emoji face as default selection

* improve scroll on Windows

* fix emoji clipped in smallest window size.

* fix analyze

* improve

* fix sticker page icon
  • Loading branch information
boyan01 authored Jul 18, 2022
1 parent 5ba09d0 commit 55dec05
Show file tree
Hide file tree
Showing 17 changed files with 421 additions and 33 deletions.
6 changes: 6 additions & 0 deletions assets/images/emoji_animal.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions assets/images/emoji_face.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions assets/images/emoji_flags.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions assets/images/emoji_food.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions assets/images/emoji_objects.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions assets/images/emoji_recent.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions assets/images/emoji_sports.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions assets/images/emoji_sticker.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions assets/images/emoji_symbol.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions assets/images/emoji_travel.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 27 additions & 0 deletions lib/account/account_key_value.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import '../utils/extension/extension.dart';
import '../utils/hive_key_values.dart';

class AccountKeyValue extends HiveKeyValue {
Expand All @@ -12,6 +13,7 @@ class AccountKeyValue extends HiveKeyValue {
static const _refreshStickerLastTime = 'refreshStickerLastTime';
static const _primarySessionId = 'primarySessionId';
static const _hasNewAlbum = 'hasNewAlbum';
static const _keyRecentUsedEmoji = 'recentUsedEmoji';

bool get hasSyncCircle =>
box.get(_hasSyncCircle, defaultValue: false) as bool;
Expand All @@ -32,4 +34,29 @@ class AccountKeyValue extends HiveKeyValue {
bool get hasNewAlbum => box.get(_hasNewAlbum, defaultValue: false) as bool;

set hasNewAlbum(bool value) => box.put(_hasNewAlbum, value);

List<String>? _recentUsedEmoji;

List<String> get recentUsedEmoji => _recentUsedEmoji ??=
(box.get(_keyRecentUsedEmoji, defaultValue: []) as List).cast<String>();

void onEmojiUsed(String emoji) {
if (recentUsedEmoji.firstOrNull == emoji) {
return;
}
recentUsedEmoji
..remove(emoji)
..insert(0, emoji);

while (recentUsedEmoji.length > 50) {
recentUsedEmoji.removeLast();
}
box.put(_keyRecentUsedEmoji, recentUsedEmoji);
}

@override
Future delete() {
_recentUsedEmoji = null;
return super.delete();
}
}
28 changes: 28 additions & 0 deletions lib/constants/resources.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 20 additions & 6 deletions lib/ui/home/chat/input_container.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import '../../../widgets/menu.dart';
import '../../../widgets/message/item/quote_message.dart';
import '../../../widgets/message/item/text/mention_builder.dart';
import '../../../widgets/sticker_page/bloc/cubit/sticker_albums_cubit.dart';
import '../../../widgets/sticker_page/emoji_page.dart';
import '../../../widgets/sticker_page/sticker_page.dart';
import '../../../widgets/toast.dart';
import '../bloc/conversation_cubit.dart';
Expand Down Expand Up @@ -222,7 +223,9 @@ class _InputContainer extends HookWidget {
_FileButton(actionColor: context.theme.icon),
const _ImagePickButton(),
const SizedBox(width: 6),
const _StickerButton(),
_StickerButton(
textEditingController: textEditingController,
),
const SizedBox(width: 16),
Expanded(
child: _SendTextField(
Expand Down Expand Up @@ -538,7 +541,11 @@ class _FileButton extends StatelessWidget {
}

class _StickerButton extends HookWidget {
const _StickerButton();
const _StickerButton({
required this.textEditingController,
});

final TextEditingController textEditingController;

@override
Widget build(BuildContext context) {
Expand All @@ -553,11 +560,18 @@ class _StickerButton extends HookWidget {
final tabLength =
useBlocStateConverter<StickerAlbumsCubit, List<StickerAlbum>, int>(
bloc: stickerAlbumsCubit,
converter: (state) => (state.length) + 3,
converter: (state) =>
(state.length) +
// no emoji page on Linux.
(Platform.isLinux ? 3 : 4),
);

return BlocProvider.value(
value: stickerAlbumsCubit,
return MultiProvider(
providers: [
BlocProvider.value(value: stickerAlbumsCubit),
BlocProvider(create: (context) => EmojiSelectedGroupIndexCubit()),
ChangeNotifierProvider.value(value: textEditingController),
],
child: DefaultTabController(
length: tabLength,
initialIndex: 1,
Expand Down Expand Up @@ -595,7 +609,7 @@ class _StickerButton extends HookWidget {
padding: const EdgeInsets.all(8),
child: Builder(
builder: (context) => StickerPage(
tabController: DefaultTabController.of(context),
tabController: DefaultTabController.of(context)!,
tabLength: tabLength,
),
),
Expand Down
Loading

0 comments on commit 55dec05

Please sign in to comment.