Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better emoji height management #117

Merged
merged 5 commits into from
May 8, 2017
Merged

Better emoji height management #117

merged 5 commits into from
May 8, 2017

Conversation

rubengees
Copy link
Collaborator

@rubengees rubengees commented May 4, 2017

This would fix #116.
This change is not backwards-compatible.

Contents of this Pull Request

The EmojiSpan now automatically calculates it's size based on the line height of the TextView it resides in. This has the advantage that there is no "jumping" when typing and weird visuals as described in #116.
This removes the custom emojiSize attr; The user is expected to change text size by the normal methods (textAppearance or textSize)

Before After
device-2017-05-04-235135 device-2017-05-04-235323

If you look closely, you can see the "jump" at the left GIF.
(Sorry about the bad quality of the GIFs...)

Code changes to achieve this

  • The EmojiSpan now gets the lineHeight of the EmojiTextView or EmojiEditText passed as the size. The getSize method was overriden to make this work.
  • The custom emojiSize attr and all associated methods have been removed.
  • The adapter items now have their textAppearance set to TextAppearance.AppCompat.Large for showcasing how to change the size.

rubengees added 2 commits May 4, 2017 23:44
The EmojiSpan is now drawn with the exact line height of the TextView it is in. This avoids jumping lines when typing in an EditText or weird visuals when having a line with and one without emojis in a TextView.

Furthermore the custom attr "emojiSize" was removed, as it is now automatically calculated. To still be able to choose the size, the textAppearance of the TextView should be changed.

Another change is a large textAppearance for the adapter items, to showcase different heights.
@codecov
Copy link

codecov bot commented May 4, 2017

Codecov Report

Merging #117 into master will increase coverage by 0.56%.
The diff coverage is 0%.

@@            Coverage Diff             @@
##           master     #117      +/-   ##
==========================================
+ Coverage   23.93%   24.49%   +0.56%     
==========================================
  Files          19       19              
  Lines         656      641      -15     
  Branches       71       69       -2     
==========================================
  Hits          157      157              
+ Misses        486      471      -15     
  Partials       13       13

Copy link
Owner

@vanniktech vanniktech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it. This bit of moving up and down has always bothered me. About backwards compatible, that's not a problem since we're still PRE v1.

android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
xmlns:app="http://schemas.android.com/apk/res-auto"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you revert those changes?

android:textIsSelectable="true"
tools:text="my text"
/>
<com.vanniktech.emoji.EmojiTextView
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also here please revert the white space changes

android:layout_height="wrap_content"
android:textAppearance="@style/TextAppearance.AppCompat.Large"
android:textIsSelectable="true"
tools:text="my text"/>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also here revert the /> change

@@ -3,14 +3,13 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
android:orientation="vertical">
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

> should go on the same line

android:layout_height="wrap_content"
android:orientation="vertical"
tools:context=".MainDialog">
xmlns:app="http://schemas.android.com/apk/res-auto"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

@@ -39,8 +39,7 @@
android:layout_weight="1"
android:imeOptions="actionSend"
android:inputType="textCapSentences|textMultiLine"
android:maxLines="3"
app:emojiSize="26sp"/>
android:maxLines="3"/>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't know what to do about this one...

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup this one is okay. Sorry for the confusion

@@ -30,4 +31,9 @@

return drawable;
}

@Override public int getSize(final Paint paint, final CharSequence text, final int start,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why all of the parameters if all they do is just nothing?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well that's the signature of the base method, so we have to specify all of these parameters.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh okay, didn't see the @Override

@rubengees
Copy link
Collaborator Author

Everything done! I intuitively hit Strg + Alt + L after editing which always leads to such changes.

@@ -30,4 +31,9 @@

return drawable;
}

@Override public int getSize(final Paint paint, final CharSequence text, final int start,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this method can be just deleted right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, we need it to specify the size of the Span to the plattform.

@vanniktech
Copy link
Owner

@rubengees no worries about the formatting. There's still the getSize method which should be deleted, right?

@rubengees
Copy link
Collaborator Author

I tried it without the method just now and it did not work.

Copy link
Owner

@vanniktech vanniktech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for this one :)

@@ -30,4 +31,9 @@

return drawable;
}

@Override public int getSize(final Paint paint, final CharSequence text, final int start,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh okay, didn't see the @Override

@vanniktech vanniktech merged commit 79a690d into vanniktech:master May 8, 2017
@rubengees rubengees deleted the better-emoji-height branch May 8, 2017 15:00
vanniktech added a commit that referenced this pull request May 9, 2017
Better emoji height management (#117)

Adjust generator for emoji 5.0 (#118)

Update all emojis to emoji 5.0 (#119)

Merge branch 'master' into latest

More
vanniktech added a commit that referenced this pull request May 9, 2017
Better emoji height management (#117)

Adjust generator for emoji 5.0 (#118)

Update all emojis to emoji 5.0 (#119)

Merge branch 'master' into latest

More
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Line height issues
2 participants