material-components / material-components/material-components-android

[BottomSheetDialogFragment] RecyclerView items inside BottomSheetDialogFragment need double touch after fast scrolling

Open
#1,132 9 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug Widget: BottomSheet
Dominant language
Java
Stars
17.4k
Forks
3.2k
PR merge metrics
No merged PRs in 30d

Description

I have a `RecyclerView` inside `BottomSheetDialogFragment`. The `RecyclerView` items touch working normally when it's scrolling slowly.

But when the `RecyclerView` is scrolled fast and after the list stops (without touching), than touching on any item doesn't work on fast touch. It needs double touching.

See in the below example gif, when touching on `Andhra Pradesh` it's working fine. After slow scrolling, touching on `Haryana` also works fine. Then doing a fast scroll and touching on `Punjab` doesn't work on the first touch. Touching again it works.

[![RV GIF][1]][1]

Following is the code:
**OperatorListDialogFragment.java**
```java
package com.*;

import *;

public class OperatorListDialogFragment extends BottomSheetDialogFragment{

private static final String ARG_NAME = "item_name";
private static final String ARG_LOGO = "item_logo";
private Listener mListener;
private String header;
private Context mContext;

public static OperatorListDialogFragment newInstance(String[] name, int[] logo, String header) {
final OperatorListDialogFragment fragment = new OperatorListDialogFragment();
final Bundle args = new Bundle();
args.putStringArray(ARG_NAME, name);
args.putIntArray(ARG_LOGO, logo);
args.putString("header", header);
fragment.setArguments(args);
return fragment;
}

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_operator_list_dialog_list_dialog, container, false);
}

@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {

TextView headerTV = view.findViewById(R.id.title);
headerTV.setText(getArguments().getString("header"));

final RecyclerView recyclerView = view.findViewById(R.id.list);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
recyclerView.setAdapter(new OperatorAdapter(getArguments().getStringArray(ARG_NAME), getArguments().getIntArray(ARG_LOGO)));

view.findViewById(R.id.dismiss).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dismiss();
}
});
}

@Override
public void onAttach(Context context) {
super.onAttach(context);

mContext = context;

final Fragment parent = getParentFragment();
if (parent != null) {
mListener = (Listener) parent;
} else {
mListener = (Listener) context;
}
}

@Override
public void onDetach() {
mListener = null;
super.onDetach();
}

public interface Listener {
void onFilterSelected(String selected, String selectedQuery);
}

private class ViewHolder extends RecyclerView.ViewHolder {

final TextView text;
ImageView logo;

ViewHolder(LayoutInflater inflater, ViewGroup parent) {
// TODO: Customize the item layout
super(inflater.inflate(R.layout.fragment_operator_list_dialog_list_dialog_item, parent, false));
text = itemView.findViewById(R.id.tv_operator_name);
logo = itemView.findViewById(R.id.iv_recharge_provider_icon);
}
}

private class OperatorAdapter extends RecyclerView.Adapter {

private String[] mNames;
private int[] mLogos;

OperatorAdapter(String[] name, int[] logo) {
mNames = name;
mLogos = logo;
}

@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
return new ViewHolder(LayoutInflater.from(parent.getContext()), parent);
}

@Override
public void onBindViewHolder(final ViewHolder holder, final int position) {

holder.text.setText(mNames[position]);

holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.e("clicked", "" + position);
}
});
}

@Override
public int getItemCount() {
return mNames.length;
}
}
}
```

**dialog.xml**
```xml

```

**recycler_item.xml**
```xml

```

[1]: https://i.stack.imgur.com/zy3Nd.gif

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with OperatorListDialogFragment.java and the supplied dialog.xml and recycler_item.xml layouts, then reproduce the sequence of fast RecyclerView scrolling followed by a first tap inside BottomSheetDialogFragment. Trace touch handling between the RecyclerView item and bottom-sheet behavior; done means an item activates on the first tap after fast scrolling.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, java
Domain
mobile
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.