fix: swipe refresh layout abnormal refreshing with nested webview

This commit is contained in:
hyb1996 2017-10-26 19:42:39 +08:00
parent bc29c578e6
commit 2aa2d074a8
4 changed files with 19 additions and 15 deletions

1
.gitignore vendored
View File

@ -5,6 +5,7 @@
/.idea/libraries
.DS_Store
/build
/release
/captures
.externalNativeBuild
*.apk

View File

@ -9,8 +9,8 @@ android {
applicationId "com.stardust.scriptdroid"
minSdkVersion 17
targetSdkVersion 23
versionCode 213
versionName "3.0.0 Alpha14"
versionCode 214
versionName "3.0.0 Alpha15"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
ndk {

View File

@ -40,13 +40,14 @@ import io.reactivex.android.schedulers.AndroidSchedulers;
* Created by Stardust on 2017/8/22.
*/
public class EWebView extends SwipeRefreshLayout implements SwipeRefreshLayout.OnRefreshListener, OnActivityResultDelegate {
public class EWebView extends FrameLayout implements SwipeRefreshLayout.OnRefreshListener, OnActivityResultDelegate {
private static final List<String> IMAGE_TYPES = Arrays.asList("png", "jpg", "bmp");
private static final int CHOOSE_IMAGE = 42222;
private WebView mWebView;
private ProgressBar mProgressBar;
private SwipeRefreshLayout mSwipeRefreshLayout;
public EWebView(Context context) {
super(context);
@ -62,8 +63,9 @@ public class EWebView extends SwipeRefreshLayout implements SwipeRefreshLayout.O
private void init() {
inflate(getContext(), R.layout.ewebview, this);
mWebView = (WebView) findViewById(R.id.web_view);
mSwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_refresh_layout);
mProgressBar = (ProgressBar) findViewById(R.id.progress_bar);
setOnRefreshListener(this);
mSwipeRefreshLayout.setOnRefreshListener(this);
setUpWebView();
}
@ -97,7 +99,7 @@ public class EWebView extends SwipeRefreshLayout implements SwipeRefreshLayout.O
mWebView.reload();
Observable.timer(2, TimeUnit.SECONDS)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(t -> setRefreshing(false));
.subscribe(t -> mSwipeRefreshLayout.setRefreshing(false));
}
@ -189,7 +191,7 @@ public class EWebView extends SwipeRefreshLayout implements SwipeRefreshLayout.O
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
mProgressBar.setVisibility(GONE);
setRefreshing(false);
mSwipeRefreshLayout.setRefreshing(false);
}
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)

View File

@ -1,11 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/swipe_refresh_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipe_refresh_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
@ -13,13 +14,13 @@
android:id="@+id/web_view"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</android.support.v4.widget.SwipeRefreshLayout>
<ProgressBar
android:id="@+id/progress_bar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="2dp"
android:visibility="gone"/>
</FrameLayout>
<ProgressBar
android:id="@+id/progress_bar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="2dp"
android:visibility="gone"/>
</merge>