Flipboard / bottomsheet

Android component which presents a dismissible view from the bottom of the screen
BSD 3-Clause "New" or "Revised" License
4.52k stars 596 forks source link

Bug: touch event get wrong after folding soft keyborad #100

Open ghost opened 8 years ago

ghost commented 8 years ago

Step 1: open bottom sheet and expanded it to top. There is a recyclerView which contains EditText items in bottom sheet; Step 2: click any EditText then soft keyboard shows; Step 3: fold the soft keyboard. And now bottom sheet keeps peeked state. Step 4: click top item of recyclerView, the bug is bottom sheet auto hides. Even if I touch the item at bottom position, the bottom sheet doesn't work normally.

After reading source code, I think the problem happens here:(BottomSheetLayout.class line 669)

sheetViewOnLayoutChangeListener = new OnLayoutChangeListener() {
            @Override
            public void onLayoutChange(View sheetView, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
                int newSheetViewHeight = sheetView.getMeasuredHeight();
                if (state != State.HIDDEN && newSheetViewHeight < currentSheetViewHeight) {
                    // The sheet can no longer be in the expanded state if it has shrunk
                    if (state == State.EXPANDED) {
                        setState(State.PEEKED);
                    }
                    setSheetTranslation(newSheetViewHeight);
                }
                currentSheetViewHeight = newSheetViewHeight;
            }
        };

When soft keyboard is fold, the code "setSheetTranslation(newSheetViewHeight);" isn't execute. This makes onTouchEvent works abnormally.

lFaustus commented 8 years ago

I am also facing this problem

lFaustus commented 8 years ago

sir try to comment setSheetTranslation(newSheetViewHeight) that's what I did. Everytime the softkeyboard pops up setSheetTranslation(newSheetViewHeight) is executed. So far I have not experienced other bugs and it fixes the aforementioned problem. Just post if ever there's a new bug you might encounter after commenting it.

AndroidDeveloperLB commented 8 years ago

@lFaustus What is the purpose of this entire onLayoutChange code for the library?

mohanadmohie commented 8 years ago

I am facing a similar problem with an EditText in the sheet's layout. After closing the soft keyboard (pressing the back button), the sheet appears to be EXPANDED but it actually is in the PEEKED state; it's just that the graphical interface is not updated with the sheet's actual position after dismissing the soft keyboard. If I manually drag the sheet to change its state, it shows a little jump in the translation then acts normal again.

AndroidDeveloperLB commented 8 years ago

It seems Google has provided a new BottomSheet component as part of their libraries: http://android-developers.blogspot.co.il/2016/02/android-support-library-232.html I wonder how good it works, if it has all important features and if it doesn't have issues.

mohanadmohie commented 8 years ago

Thanks for the heads-up @AndroidDeveloperLB, I'll give it a look.

AndroidDeveloperLB commented 8 years ago

@mohanadmohie You're welcomed. I can't find any samples though.

ZacSweers commented 8 years ago

This is in fact a bug and has something to do with activity windowSoftInputMode modes. PRs welcome on this, but haven't had time to look at this

meierjan commented 8 years ago

Same issue here. This is a serious bug if you are working with any kind of text input/soft keyboard.

What is the use-case for that made you add it?

if (state != State.HIDDEN && newSheetViewHeight < currentSheetViewHeight) {
  // The sheet can no longer be in the expanded state if it has shrunk
  if (state == State.EXPANDED) {
    setState(State.PEEKED);
  }
  setSheetTranslation(newSheetViewHeight);
}

Can you give me some input?

lFaustus commented 8 years ago

@meierjan sir did u try to set the input method to adjustpan? adjustpan fixed the problem

meierjan commented 8 years ago

@lFaustus thanks for the hint but this is not desired in my case

edTheGuy00 commented 7 years ago

This still seems to be an issue

Founder005 commented 6 years ago

same problem, contains EditText items in bottomsheet I have an idea:

//screenHeight
private int screenHeight = 0;
//The height of the bottomsheet sliding up
private int keyHeight = 0;

screenHeight = this.getWindowManager().getDefaultDisplay().getHeight();
//if keyHeight is 1 / 3 of screenHeight ,we think it pop-ups
keyHeight = screenHeight / 3;

bottomsheet.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {

            @Override
            public void onLayoutChange(View v, int left, int top, int right,
                                       int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {

                //The height of the sliding up more than one-third of the screen,we think it pop-ups
                if (oldBottom != 0 && bottom != 0 && (oldBottom - bottom > keyHeight)) {
                    Log.d("keyboard ","showing");
                } else if (oldBottom != 0 && bottom != 0 && (bottom - oldBottom > keyHeight)) {
                    Log.d("keyboard ","dismiss");
                    //return PEEK state
                    bottomsheet.peekSheet();
                }
            }

 });

hope a better idea