addisonElliott / SegmentedButton

Segmented Control/Button with animation for Android API 16+
Apache License 2.0
148 stars 39 forks source link

Dragging finger past right edge of screen results in no callback #49

Closed benjamin-ict closed 3 years ago

benjamin-ict commented 3 years ago

When I drag the button to the right and continue with my finger past the edge of the screen, the SegmentedButtonGroup does not register that the position has been changed, and the visual aspect of the button will be stuck in the rightmost position. Dragging stops working in this case. Tapping any button in the group will cause it to work again.

Example layout:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <com.addisonelliott.segmentedbutton.SegmentedButtonGroup
        android:id="@+id/segmented_button_group"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginStart="30dp"
        android:layout_marginTop="20dp"
        android:layout_marginEnd="30dp"
        app:borderWidth="1dp"
        app:borderColor="@android:color/darker_gray"
        app:draggable="true"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:selectedBorderWidth="1dp"
        app:selectedBorderColor="@color/black">

        <com.addisonelliott.segmentedbutton.SegmentedButton
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:padding="8dp"
            app:text="Option 0"
            app:textSize="14sp" />

        <com.addisonelliott.segmentedbutton.SegmentedButton
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:padding="8dp"
            app:text="Option 1"
            app:textSize="14sp" />

    </com.addisonelliott.segmentedbutton.SegmentedButtonGroup>

</androidx.constraintlayout.widget.ConstraintLayout>

I used this Activity for testing in a new project:

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        SegmentedButtonGroup segmentedButtonGroup = findViewById(R.id.segmented_button_group);
        segmentedButtonGroup.setOnPositionChangedListener(position -> {
            Log.d("MainActivity", "pos=" + position);
            Snackbar.make(segmentedButtonGroup.getRootView(), "pos=" + position, Snackbar.LENGTH_SHORT).show();
        });
    }
}