Skip to content

Commit 44f5cc1

Browse files
committed
fix setStackFromEnd
1 parent a35abb1 commit 44f5cc1

File tree

3 files changed

+24
-9
lines changed

3 files changed

+24
-9
lines changed

android/chatinput/src/main/java/cn/jiguang/imui/chatinput/ChatInputView.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ public void run() {
318318
mLastClickId = view.getId();
319319
// mMenuContainer.requestLayout();
320320
}
321-
Log.w(TAG, "viewId: " + view.getId() + "-showType:" + showType);
321+
// Log.w(TAG, "viewId: " + view.getId() + "-showType:" + showType);
322322
}
323323
};
324324
private IEmoticonSelectedListener emoticonSelectedListener = new IEmoticonSelectedListener() {
@@ -638,7 +638,7 @@ public void onGlobalLayout() {
638638
mWindow.getDecorView().getWindowVisibleDisplayFrame(r);
639639
int screenHeight = mWindow.getDecorView().getRootView().getHeight();
640640
int height = screenHeight - r.bottom + mChatInputContainer.getHeight();
641-
Log.d(TAG, "Keyboard Size: " + px2dip(height) + "-showType:" + showType);
641+
// Log.d(TAG, "Keyboard Size: " + px2dip(height) + "-showType:" + showType);
642642
if (inputHeight == height) {
643643
return;
644644
}

android/messagelist/src/main/java/cn/jiguang/imui/messages/MsgListAdapter.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -390,12 +390,7 @@ public void addToStart(List<MESSAGE> messages, boolean scrollToBottom) {
390390
if (scrollToBottom) {
391391
mLayoutManager.scrollToPosition(0);
392392
}
393-
if (mLayoutManager.canScrollVertically()) {
394-
mLayoutManager.setStackFromEnd(false);
395-
} else {
396-
mLayoutManager.requestLayout();
397-
}
398-
Log.w("MsgListAdapter", "canScrollVertically:" + mLayoutManager.canScrollVertically());
393+
mLayoutManager.requestLayout();
399394
}
400395
}
401396

android/messagelist/src/main/java/cn/jiguang/imui/messages/ScrollMoreListener.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class ScrollMoreListener extends RecyclerView.OnScrollListener {
1313
private int mCurrentPage = 0;
1414
private int mPreviousTotalItemCount = 0;
1515
private boolean mLoading = false;
16-
private int visibleThreshold = 20;
16+
private int visibleThreshold = 5;
1717
private int scrollThreshold = 3;
1818
private boolean autoScroll = true;
1919

@@ -39,6 +39,26 @@ private int getLastVisibleItem(int[] lastVisibleItemPositions) {
3939

4040
@Override
4141
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
42+
if (mLayoutManager instanceof LinearLayoutManager) {
43+
LinearLayoutManager ll = (LinearLayoutManager) mLayoutManager;
44+
if (ll.getStackFromEnd()) {
45+
if (ll.getChildCount() < mLayoutManager.getItemCount()) {
46+
try {
47+
ll.setStackFromEnd(false);
48+
} catch (Exception e) {
49+
e.printStackTrace();
50+
}
51+
}
52+
}else {
53+
if (ll.getChildCount() >= mLayoutManager.getItemCount()) {
54+
try {
55+
ll.setStackFromEnd(true);
56+
} catch (Exception e) {
57+
e.printStackTrace();
58+
}
59+
}
60+
}
61+
}
4262
if (mListener != null) {
4363
int lastVisibleItemPosition = 0;
4464
int firstVisibleItemPosition = 0;

0 commit comments

Comments
 (0)