Skip to content

Commit

Permalink
example improvements, workaround ios issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Fintasys committed Jan 7, 2024
1 parent 8117edb commit e8b0ea7
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 12 deletions.
2 changes: 1 addition & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class MyAppState extends State<MyApp> {
emojiSizeMax: 28 *
(foundation.defaultTargetPlatform ==
TargetPlatform.iOS
? 1.30
? 1.2
: 1.0),
),
swapCategoryAndBottomBar: false,
Expand Down
4 changes: 2 additions & 2 deletions example/lib/main_custom_font.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class MyAppState extends State<MyApp> {
);

// 2. Use EmojiTextEditingController
_controller = EmojiTextEditingController(emojiStyle: _textStyle);
_controller = EmojiTextEditingController(emojiTextStyle: _textStyle);
super.initState();
}

Expand Down Expand Up @@ -129,7 +129,7 @@ class MyAppState extends State<MyApp> {
emojiSizeMax: _fontSize *
(foundation.defaultTargetPlatform ==
TargetPlatform.iOS
? 1.30
? 1.2
: 1.0),
),
swapCategoryAndBottomBar: false,
Expand Down
14 changes: 8 additions & 6 deletions example/lib/main_whatsapp.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:emoji_picker_flutter/emoji_picker_flutter.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:flutter/foundation.dart' as foundation;

const accentColor = Color(0xFF4BA586);
const accentColorDark = Color(0xFF377E6A);
Expand All @@ -26,18 +27,20 @@ class MyAppState extends State<MyApp> {
late final ScrollController _scrollController;
late final FocusNode _focusNode;
late final TextStyle _textStyle;
final bool isApple = [TargetPlatform.iOS, TargetPlatform.macOS]
.contains(foundation.defaultTargetPlatform);
bool _emojiShowing = false;
final _fontSize = 24.0;

@override
void initState() {
final fontSize = 24 * (isApple ? 1.2 : 1.0);
// Define Custom Emoji Font & Text Style
_textStyle = emojiTextStyle.copyWith(
fontFamily: GoogleFonts.notoColorEmoji().fontFamily,
fontSize: _fontSize,
fontFamily: isApple ? null : GoogleFonts.notoColorEmoji().fontFamily,
fontSize: fontSize,
);

_controller = EmojiTextEditingController(emojiStyle: _textStyle);
_controller = EmojiTextEditingController(emojiTextStyle: _textStyle);
_scrollController = ScrollController();
_focusNode = FocusNode();

Expand Down Expand Up @@ -179,8 +182,7 @@ class MyAppState extends State<MyApp> {
height: 256,
checkPlatformCompatibility: true,
emojiTextStyle: _textStyle,
emojiViewConfig: EmojiViewConfig(
emojiSizeMax: _fontSize,
emojiViewConfig: const EmojiViewConfig(
backgroundColor: Colors.white,
),
swapCategoryAndBottomBar: true,
Expand Down
6 changes: 3 additions & 3 deletions lib/src/emoji_text_editing_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ const delimiter = '|';
/// a particular style to emoji characters.
class EmojiTextEditingController extends TextEditingController {
/// Constructor, requres emojiStyle, since otherwise this class has no effect
EmojiTextEditingController({String? text, required this.emojiStyle})
EmojiTextEditingController({String? text, required this.emojiTextStyle})
: super(text: text) {
final utils = EmojiPickerUtils();
_regex = utils.getEmojiRegex();
}

/// The style used for the emoji characters
final TextStyle emojiStyle;
final TextStyle emojiTextStyle;

/// Cached Regex for emoji
late final RegExp _regex;
Expand Down Expand Up @@ -46,7 +46,7 @@ class EmojiTextEditingController extends TextEditingController {
_addTextSpan(
textSpanChildren,
textPart,
style?.merge(emojiStyle),
style?.merge(emojiTextStyle),
);

return '';
Expand Down
1 change: 1 addition & 0 deletions lib/src/emoji_text_style.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:flutter/material.dart';

/// Emoji text style providing commonly available fallback fonts
final emojiTextStyle = const TextStyle(
inherit: true,
// Commonly available fallback fonts.
fontFamilyFallback: [
// iOS and MacOs.
Expand Down

0 comments on commit e8b0ea7

Please sign in to comment.