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

Improve Popup logic #97

Merged
merged 8 commits into from
Mar 8, 2017
Merged

Improve Popup logic #97

merged 8 commits into from
Mar 8, 2017

Conversation

rubengees
Copy link
Collaborator

This would address some of the points in #96 and fix #26.

Contents of this Pull Request

The internal popup logic has been improved in several ways:

  • Support for dialogs and other places apart from a normal Activity.
  • Better behaviour of variant popups. If the user opens one and clicks outside of it, the event is not delegated, but only the popup is closed.
  • Better keyboard height detection
  • Fixes for identification if the keyboard is open or not. Previously, when one opened the picker, clicked the toggle item and closed the keyboard by pressing the back button, two clicks were required to open the popup again, as the EmojiPopup had a wrong state concerning isKeyboardOpen.
  • The onEmojiPopupShownListener is only shown, after the popup is really shown. Previously it was called, when we started opening the keyboard, which could lead to a wrong state if it was not shown (If a hardware keyboard is present for example).

Code changes to achive this

  • The height of the current rootView is calculated from the DecorView.
  • Better places for setting and removing the global layout listener were chosen.
  • The popup is always shown at the bottom of the screen, following the advice in shows above keyboard in dialog box #26.
  • popupWindow.setFocusable(true) is now called on the variant popup. popupWindow.setInputMethodMode(PopupWindow.INPUT_METHOD_NOT_NEEDED) was the key to make that work without weird side effects.
  • Adjusted location calculation for the variant popup, to make it work in dialogs.

I have added a simple Dialog to the sample for showcasing and testing.

Things concerning backwards compability

  • The popup now closes itself when the keyboard is closed. Thus, a call to emojiPopup.dismiss(); in onKeyboardClose is not necessary anymore.
  • We require the Context of the rootView to be an Activity now. We need that as we want to access the Window for better height calculation.

final int fixedOffsetX = actualLocation.x > x ? x - differenceX : x + differenceX;
final int fixedOffsetY = actualLocation.y > y ? y - differenceY : y + differenceY;

popupWindow.update(fixedOffsetX, fixedOffsetY, DONT_UPDATE_FLAG, DONT_UPDATE_FLAG);
Copy link
Collaborator Author

@rubengees rubengees Feb 25, 2017

Choose a reason for hiding this comment

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

This might look weird, but is needed for dialogs. I have not found a way to calculate the offset properly, so we "fix" it here if it differs from the wanted location.

@codecov-io
Copy link

codecov-io commented Feb 25, 2017

Codecov Report

Merging #97 into master will decrease coverage by -1%.
The diff coverage is 0%.

@@           Coverage Diff           @@
##           master      #97   +/-   ##
=======================================
- Coverage   24.96%   23.96%   -1%     
=======================================
  Files          19       19           
  Lines         629      655   +26     
  Branches       67       71    +4     
=======================================
  Hits          157      157           
- Misses        459      485   +26     
  Partials       13       13

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 852ca0c...d8a6c8d. Read the comment docs.

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.

Codewise it does look okay, although this does not work anymore in my simulator (Genymotion).

@rubengees
Copy link
Collaborator Author

I assume that happens because of the hardware keyboard, Genymotion uses.
Did it work before (It shouldn't...)?

@vanniktech
Copy link
Owner

Yup before it worked perfectly. Also I have the soft keyboard activated and it shows up.

@rubengees
Copy link
Collaborator Author

Okay, I'll investigate. On which API Level does it happen?

@vanniktech
Copy link
Owner

Genymotion Google Nexus 5X 7.0.0 API 24

@rubengees
Copy link
Collaborator Author

rubengees commented Mar 1, 2017

Fixed in bf2fc8b. This seemed to be a bug on APIs greater than 20. We now "fix" the location, exactly like the variant popup.

Furthermore I made the Context to Activity cast from the rootView more safe (The support lib does it in the same way) .

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.

Sorry I haven't gotten around this any earlier. So far this looks good. I'll test it with a few other devices soon and then merge it if there are no issues.

@@ -62,6 +63,20 @@ static int screenHeight(@NonNull final Activity context) {
return result;
}

static Activity contextToActivity(@NonNull final Context context) {
Copy link
Owner

Choose a reason for hiding this comment

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

method name: asActivity

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. I tested it on 10+ devices and found no problems.

@vanniktech vanniktech merged commit 678e14f into vanniktech:master Mar 8, 2017
@rubengees rubengees deleted the popup-logic branch March 8, 2017 13:57
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.

shows above keyboard in dialog box
3 participants