Skip to content

Commit

Permalink
Fix for ShellRoute issue (#161)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fintasys authored Oct 29, 2023
1 parent 14ad8de commit b7b039d
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 8 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.3

- Added new Config parameter `customSkinColorOverlayHorizontalOffset` to fix issue with SkinColorOverlay in ShellRoute or other horizontal adjustments

## 1.6.2

- remove nullability from `OverlayState`
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ See the [demo](https://github.com/Fintasys/emoji_picker_flutter/blob/master/exam
| checkPlatformCompatibility | Whether to filter out glyphs that platform cannot render with the default font (Android). | true |
| emojiSet | Custom emoji set, can be built based on `defaultEmojiSet` provided by the library. | null |
| emojiTextStyle | Text style to apply to individual emoji icons. Can be used to define custom emoji font either with GoogleFonts library or bundled with the app. | null |
| customSkinColorOverlayHorizontalOffset | Custom horizontal offset for SkinColor Overlay. Try to assign `0.0` when overlay is not at the correct position | null |

## Backspace-Button
You can add a Backspace-Button to the end category list by adding the callback method `onBackspacePressed: () { }` to the EmojiPicker-Widget. This will make it easier for your user to remove an added Emoji without showing the keyboard. Check out the example for more details about usage. Set it to null to hide the Backspace-Button.
Expand Down
14 changes: 12 additions & 2 deletions lib/src/config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class Config {
this.checkPlatformCompatibility = true,
this.emojiSet,
this.emojiTextStyle,
this.customSkinColorOverlayHorizontalOffset,
});

/// Number of emojis per row
Expand Down Expand Up @@ -126,6 +127,12 @@ class Config {
/// being filtered out.
final TextStyle? emojiTextStyle;

/// Customize skin color overlay horizontal offset in case of ShellRoute or
/// other cases, when EmojiPicker is not aligned to the left border of the
/// screen.
/// Reference: https://github.com/Fintasys/emoji_picker_flutter/issues/148
final double? customSkinColorOverlayHorizontalOffset;

/// Get Emoji size based on properties and screen width
double getEmojiSize(double width) {
final maxSize = width / columns;
Expand Down Expand Up @@ -185,7 +192,9 @@ class Config {
other.replaceEmojiOnLimitExceed == replaceEmojiOnLimitExceed &&
other.checkPlatformCompatibility == checkPlatformCompatibility &&
other.emojiSet == emojiSet &&
other.emojiTextStyle == emojiTextStyle;
other.emojiTextStyle == emojiTextStyle &&
other.customSkinColorOverlayHorizontalOffset ==
customSkinColorOverlayHorizontalOffset;
}

@override
Expand Down Expand Up @@ -214,5 +223,6 @@ class Config {
replaceEmojiOnLimitExceed.hashCode ^
checkPlatformCompatibility.hashCode ^
(emojiSet?.hashCode ?? 0) ^
(emojiTextStyle?.hashCode ?? 0);
(emojiTextStyle?.hashCode ?? 0) ^
(customSkinColorOverlayHorizontalOffset?.hashCode ?? 0);
}
25 changes: 20 additions & 5 deletions lib/src/skin_tone_overlay.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,15 @@ mixin SkinToneOverlayStateMixin<T extends StatefulWidget> on State<T> {
.map((skinTone) => utils.applySkinTone(emoji, skinTone))
.toList();

final positionRect = _calculateEmojiPosition(context, index, config.columns,
skinToneCount, scrollControllerOffset, tabBarHeight);
final positionRect = _calculateEmojiPosition(
context,
index,
config.columns,
skinToneCount,
scrollControllerOffset,
tabBarHeight,
config.customSkinColorOverlayHorizontalOffset,
);

_overlay = OverlayEntry(
builder: (context) => Positioned(
Expand Down Expand Up @@ -95,8 +102,15 @@ mixin SkinToneOverlayStateMixin<T extends StatefulWidget> on State<T> {
),
);

Rect _calculateEmojiPosition(BuildContext context, int index, int columns,
int skinToneCount, double scrollControllerOffset, double tabBarHeight) {
Rect _calculateEmojiPosition(
BuildContext context,
int index,
int columns,
int skinToneCount,
double scrollControllerOffset,
double tabBarHeight,
double? customSkinColorOverlayHorizontalOffset,
) {
// Calculate position of emoji in the grid
final row = index ~/ columns;
final column = index % columns;
Expand All @@ -107,7 +121,8 @@ mixin SkinToneOverlayStateMixin<T extends StatefulWidget> on State<T> {
final topOffset = emojiSpace;
final leftOffset =
_getLeftOffset(emojiSpace, column, skinToneCount, columns);
final left = offset.dx + column * emojiSpace + leftOffset;
final dx = customSkinColorOverlayHorizontalOffset ?? offset.dx;
final left = dx + column * emojiSpace + leftOffset;
final top = tabBarHeight +
offset.dy +
row * emojiSpace -
Expand Down
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.2
version: 1.6.3
homepage: https://github.com/Fintasys/emoji_picker_flutter

environment:
Expand Down

0 comments on commit b7b039d

Please sign in to comment.