Skip to content

Commit

Permalink
Fix scrolling in description tab
Browse files Browse the repository at this point in the history
  • Loading branch information
Stypox committed Jan 23, 2021
1 parent 9a65f02 commit 08501e5
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package org.schabi.newpipe.fragments.detail;

import android.content.Context;
import android.graphics.Rect;
import android.util.AttributeSet;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.widget.NestedScrollView;

/**
* The behaviour of this scroll view is exactly equal to that of {@link NestedScrollView} except
* that it does not scroll automatically to give focus to views (unwanted since everything would
* move around when clicking on links, see #5453).
*/
public class DescriptionNestedScrollView extends NestedScrollView {

public DescriptionNestedScrollView(@NonNull final Context context) {
super(context);
}

public DescriptionNestedScrollView(@NonNull final Context context,
@Nullable final AttributeSet attrs) {
super(context, attrs);
}

public DescriptionNestedScrollView(@NonNull final Context context,
@Nullable final AttributeSet attrs,
final int defStyleAttr) {
super(context, attrs, defStyleAttr);
}

@Override
protected int computeScrollDeltaToGetChildRectOnScreen(final Rect rect) {
// Override this to return always 0 so that the description scroll view is not scrolled
// around when the user presses on a link
return 0;
}

@Override
public void scrollTo(final int x, final int y) {
// Override this to prevent any scrolling
}

@Override
public void scrollBy(final int x, final int y) {
// Override this to prevent any scrolling
}
}
18 changes: 8 additions & 10 deletions app/src/main/res/layout/fragment_description.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
<org.schabi.newpipe.fragments.detail.DescriptionNestedScrollView 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:orientation="vertical"
android:scrollbars="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_height="wrap_content"
android:orientation="vertical"
android:scrollbars="vertical">

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
Expand All @@ -15,9 +15,8 @@
android:id="@+id/detail_upload_date_view"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginHorizontal="16dp"
android:layout_marginTop="6dp"
android:layout_marginEnd="16dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="@dimen/video_item_detail_upload_date_text_size"
android:textStyle="bold"
Expand All @@ -29,11 +28,10 @@

<TextView
android:id="@+id/detail_description_view"
android:layout_width="match_parent"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginHorizontal="16dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textIsSelectable="true"
Expand All @@ -45,4 +43,4 @@
app:layout_constraintVertical_bias="0.0"
tools:text="Description Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed a ultricies ex. Integer sit amet sodales risus. Duis non mi et urna pretium bibendum." />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>
</org.schabi.newpipe.fragments.detail.DescriptionNestedScrollView>

0 comments on commit 08501e5

Please sign in to comment.