Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/oppia-1667-fix-hori…
Browse files Browse the repository at this point in the history
…zontal-scroll' into release-7-4-9
  • Loading branch information
alexlittle committed Aug 26, 2024
2 parents d6c638f + ffa79ee commit 0c0cf37
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.digitalcampus.oppia.utils.ui;

import android.content.Context;
import android.util.AttributeSet;
import android.webkit.WebView;

public class ExtendedWebView extends WebView {
public ExtendedWebView(Context context) {
super(context);
}

public ExtendedWebView(Context context, AttributeSet attrs) {
super(context, attrs);
}

public boolean canScrollHor(int direction) {
final int offset = computeHorizontalScrollOffset();
final int range = computeHorizontalScrollRange() - computeHorizontalScrollExtent();
if (range == 0) return false;
if (direction < 0) {
return offset > 0;
} else {
return offset < range - 1;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.digitalcampus.oppia.utils.ui;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;

import androidx.viewpager.widget.ViewPager;

public class WebViewPager extends ViewPager {
public WebViewPager(Context context, AttributeSet attrs) {
super(context, attrs);
}

@Override
protected boolean canScroll(View v, boolean checkV, int dx, int x, int y) {
if (v instanceof ExtendedWebView) {
return ((ExtendedWebView) v).canScrollHor(-dx);
} else {
return super.canScroll(v, checkV, dx, x, y);
}
}
}
4 changes: 2 additions & 2 deletions app/src/main/res/layout/activity_course.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
android:layout_width="match_parent"
android:layout_height="match_parent">

<androidx.viewpager.widget.ViewPager
<org.digitalcampus.oppia.utils.ui.WebViewPager
android:id="@+id/activity_widget_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"></androidx.viewpager.widget.ViewPager>
app:layout_behavior="@string/appbar_scrolling_view_behavior" />

<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appbar"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/fragment_webview.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
<org.digitalcampus.oppia.utils.ui.ExtendedWebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/webview_oppia"
android:layout_width="match_parent"
android:layout_height="match_parent"
Expand Down

0 comments on commit 0c0cf37

Please sign in to comment.