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

Fix Emoji keyboard in certain cases #329

Merged
merged 23 commits into from
Feb 14, 2019
Merged

Fix Emoji keyboard in certain cases #329

merged 23 commits into from
Feb 14, 2019

Conversation

mario
Copy link
Collaborator

@mario mario commented Jan 24, 2019

This fixes an issue brought to my attention in #328 and a few other issues I've noticed with the Popup view.

@mario mario requested review from vanniktech and rubengees January 24, 2019 01:55
@mario mario force-pushed the fix-328 branch 2 times, most recently from 54eb9e0 to fad8606 Compare January 24, 2019 01:58
Copy link
Collaborator

@rubengees rubengees left a comment

Choose a reason for hiding this comment

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

I tested this in a real application and it doesn't work quite right in landscape. The popup is now way to large, as you can see in the screenshot. Note that I do not have set adjustResize.

Apart from that I added some questions, since I can't really follow the logic anymore...

@mario
Copy link
Collaborator Author

mario commented Jan 25, 2019

I'll investigate the sizing when NOT using adjustResize.

@mario
Copy link
Collaborator Author

mario commented Jan 25, 2019

Can you let me know the combination you use for activity + edittext (imeOptions) so I can try to debug as I can't really reproduce? (the emoji panel is the same size as keyboard for me)

@mario
Copy link
Collaborator Author

mario commented Jan 25, 2019

@rubengees when you get the time to answer, I'll take a look. Got another PR in the mean time :)

@rubengees
Copy link
Collaborator

On my Activity I have no special properties (so no adjustResize), the EmojiEditText is like this (simplified):

<com.vanniktech.emoji.EmojiEditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:inputType="textMultiLine|textCapSentences|textAutoCorrect"
    android:maxLines="5"
    android:scrollbars="vertical" />

@mario
Copy link
Collaborator Author

mario commented Jan 26, 2019

I now came up with a significantly better solution and have rebased the PR against master. Please test and reply accordingly - thanks!

@mario
Copy link
Collaborator Author

mario commented Jan 26, 2019

After this is merged, I'd appreciate a release as well so I can remove the commit from my build.gradle ;)

This, after all, should solve a lot of layout issues people faced in the past.

@mario
Copy link
Collaborator Author

mario commented Jan 27, 2019

After further testing, I can confirm (and be happy about it!) that the bug @rubengees reported is gone, so I have you folks will have the same results.

@vanniktech
Copy link
Owner

I'll test it out on Monday. Are there any further changes you want to see for 0.6.0?

@mario
Copy link
Collaborator Author

mario commented Jan 27, 2019

Ideally we'd at least have the ignored emojis fixed for 0.6, but yea...not something I can do much about :)

Do you folks have a slack channel/telegram group/signal group/whatever where we can talk more real-time btw?

@vanniktech
Copy link
Owner

Nah. Just GitHub. Maybe Ruben can help with the Emojis. Also what should we do about EmojiOne?

@mario
Copy link
Collaborator Author

mario commented Jan 27, 2019

I'd drop it if that's what the folks prefer.

@vanniktech
Copy link
Owner

Can we then also update the Emoji ordering @rubengees? I feel like when cutting a new release we should have all of the emojis in place.

@rubengees
Copy link
Collaborator

Regarding this PR - still does not work in landscape for me. The popup is not shown at all...

Maybe Ruben can help with the [ignored] Emojis.

I'll try to look into that 🙂

Can we then also update the Emoji ordering?

You mean the order in which the emojis are shown in the picker? If yes, I can't think of a way. The generator simply uses the ordering of our datasource.

@mario
Copy link
Collaborator Author

mario commented Jan 27, 2019

@rubengees can you talk the Sample app shipped in the repo (and this PR, in particular) to exhibit the behaviour you mentioned so I can properly debug? I've tried a few combinations and they all work as expected for me :(

@rubengees
Copy link
Collaborator

@mario Hmm it seems to have been an issue with my app, at least partially. I hide and show the input based on data that is loaded and also instantiated the popup only when it was first used (using Kotlin's lazy) and that seemed to have put the logic into an awkward state.

It works mostly now. But I have noticed this:


The first screenshot shows the landscape view without the picker opened. The second with it opened. As you can see, the "done" button is not accessible for the user anymore. I think the popup should only have the height of the keyboard in landscape also.

@mario
Copy link
Collaborator Author

mario commented Jan 27, 2019

So the suggestion is to instantiate the popup as soon as possible due to global layout listener in general. Let me investigate your issue now :)

@mario
Copy link
Collaborator Author

mario commented Jan 27, 2019

Nop, can't reproduce - can you send me a sample layout file? I just remove all the adjustResize and set the flagNoExtractUI and it works as expected :(

@rubengees
Copy link
Collaborator

I am currently on mobile only, but will try to put something together and investigate more thoroughly asap. My observations above were only quick findings.

@mario
Copy link
Collaborator Author

mario commented Jan 27, 2019 via email

@mario
Copy link
Collaborator Author

mario commented Jan 31, 2019

Sorry to bother, but any progress on getting me a way to reproduce or a fix @rubengees?

@rubengees
Copy link
Collaborator

Sorry, not yet. I'm currently busy with work, but have not forgotten about it!

@rubengees
Copy link
Collaborator

rubengees commented Feb 3, 2019

I have investigated further and the problems with the popup not showing were all linked to problems with my app, sorry for the confusion... Maybe we should add a disclaimer to the README, that the popup needs to be instantiated as early as possible, to avoid others to make the same mistake?

Apart from that, only the problem with the popup being above the "done" button is left for me. I can reproduce that without any modifications to the sample or the library. It happens on my real phone (OnePlus 5T, Android 9.0 stock) and also on an default Android Studio emulator (Pixel 2, Android 9.0).

@vanniktech
Copy link
Owner

Maybe we should add a disclaimer to the README, that the popup needs to be instantiated as early as possible, to avoid others to make the same mistake?

Feel free to create a PR with that.

@mario mario force-pushed the fix-328 branch 2 times, most recently from fb61127 to ac1d9ed Compare February 12, 2019 22:49
@mario
Copy link
Collaborator Author

mario commented Feb 12, 2019

There were two separate leaks that I've hopefully fixed correctly - and hopefully the build turns green this time.

Signed-off-by: Mario Danic <[email protected]>
Signed-off-by: Mario Danic <[email protected]>
@mario
Copy link
Collaborator Author

mario commented Feb 13, 2019

Tadadadadada .... it's green! :D

@mario
Copy link
Collaborator Author

mario commented Feb 13, 2019

Flow (Assuming we just started)

  • Click the emoji toggle button
  • Check if the EditText we're using has a noExtractUI flag and we're in a landscape orientation
  • If we are, store the original IME options, set the flag on the editText and restart input so the changes would get picked up by the keyboard right away

We do this because the global layout doesn't get into effect with fullscreen EditText since the keyboard is in another process and in a different layout.

We set the receiver to know what happens when we try to show the keyboard, and toggle the keyboard. If a keyboard is already shown, it'll show the Emoji popup.

  • Now that we basically have a regular keyboard and views, we can measure keyboard height using two alternatives:

  • hidden method to get keyboard height

  • magic calculations as a fallback in case reflection fails (even though the fallback also uses reflection to a degree)

  • on dismiss, we basically have to do three things:

    • clear the emoji receiver so we don't leak
    • check if we changed the original imeOptions of the editText and if so, restore them
    • cancel autofillManager so we don't leak EmojiSpans

Let me know if I failed to explain something properly and I'll happily do it.

@mario mario modified the milestones: 0.7.0, 0.6.0 Feb 13, 2019
if (SDK_INT >= O) {
AutofillManager autofillManager = context.getSystemService(AutofillManager.class);
if (autofillManager != null) {
autofillManager.cancel();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Great! I sometimes saw this leak in my app, but always thought that was an Android SDK one.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

:) It's almost like magic! :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm pretty sure this is the only available open source lib these days that handles keyboard absolutely correctly btw, which is a great accomplishment - thanks to both @rubengees and @vanniktech for pushing when things didn't work as they were supposed to!

vanniktech
vanniktech previously approved these changes Feb 14, 2019
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.

Feel free to merge once @rubengees approves. The changes can also be done in a follow up.

final Method visibleHeightMethod = inputMethodManagerClass.getDeclaredMethod("getInputMethodWindowVisibleHeight");
visibleHeightMethod.setAccessible(true);
return (int) visibleHeightMethod.invoke(imm);
} catch (NoSuchMethodException exception) {
Copy link
Owner

Choose a reason for hiding this comment

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

nit: can be grouped together

Copy link
Collaborator

Choose a reason for hiding this comment

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

No they can't, tried that and the IDE complained, because this gets compiled to catch an exception only available on Java 8 if I recall correctly. Catching generic Exception should also not be done since it hides RuntimeExceptions on which we want to crash.

}
} catch (NoSuchFieldException noSuchFieldException) {
Log.w(TAG, noSuchFieldException.getLocalizedMessage());
} catch (IllegalAccessException illegalAccessException) {
Copy link
Owner

Choose a reason for hiding this comment

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

same

@vanniktech vanniktech changed the title Fix #328 Fix Emoji keyboard in certain cases Feb 14, 2019
@mario
Copy link
Collaborator Author

mario commented Feb 14, 2019

@rubengees can we merge? After that, @vanniktech can make a release.

Signed-off-by: Mario Danic <[email protected]>
@rubengees
Copy link
Collaborator

I'll make a last test soon, then I'll approve, thanks for the explanation!

Copy link
Collaborator

@rubengees rubengees left a comment

Choose a reason for hiding this comment

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

Works great! No leaks and can't find any issues anymore, great job @mario!

@vanniktech
Copy link
Owner

Thanks @mario really appreciate the effort you put into this! Feel free to merge!

@mario mario merged commit 70c58cf into master Feb 14, 2019
@mario mario deleted the fix-328 branch February 14, 2019 21:53
@mario
Copy link
Collaborator Author

mario commented Feb 14, 2019

Please make a release now, thanks! :)

@vanniktech
Copy link
Owner

Will do first thing in the morning tomorrow

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.

3 participants