added PullToRefreshController.isEnabled method, added iOS PullToRefreshController.isRefreshing missing method
This commit is contained in:
parent
e7804f1606
commit
c28355f11f
|
@ -14,6 +14,7 @@
|
|||
- Added `WebViewFeature.DOCUMENT_START_SCRIPT` Android feature support
|
||||
- Added `getRequestedWithHeaderMode`, `setRequestedWithHeaderMode` ServiceWorkerController methods
|
||||
- Added `ContentBlockerTrigger.ifFrameUrl` and `ContentBlockerTrigger.loadContext` properties
|
||||
- Added `PullToRefreshController.isEnabled` method
|
||||
- Updated `getMetaThemeColor` on iOS 15.0+
|
||||
- Deprecated `onLoadError` for `onReceivedError`. `onReceivedError` will be called also for subframes
|
||||
- Deprecated `onLoadHttpError` for `onReceivedError`. `onReceivedHttpError` will be called also for subframes
|
||||
|
|
|
@ -29,12 +29,20 @@ public class PullToRefreshChannelDelegate extends ChannelDelegateImpl {
|
|||
case "setEnabled":
|
||||
if (pullToRefreshView != null) {
|
||||
Boolean enabled = (Boolean) call.argument("enabled");
|
||||
pullToRefreshView.settings.enabled = enabled; // used by InAppWebView.onOverScrolled
|
||||
pullToRefreshView.setEnabled(enabled);
|
||||
result.success(true);
|
||||
} else {
|
||||
result.success(false);
|
||||
}
|
||||
break;
|
||||
case "isEnabled":
|
||||
if (pullToRefreshView != null) {
|
||||
result.success(pullToRefreshView.isEnabled());
|
||||
} else {
|
||||
result.success(false);
|
||||
}
|
||||
break;
|
||||
case "setRefreshing":
|
||||
if (pullToRefreshView != null) {
|
||||
Boolean refreshing = (Boolean) call.argument("refreshing");
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.pichillilorenzo.flutter_inappwebview.pull_to_refresh;
|
|||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
@ -13,6 +14,8 @@ import com.pichillilorenzo.flutter_inappwebview.InAppWebViewFlutterPlugin;
|
|||
import com.pichillilorenzo.flutter_inappwebview.types.Disposable;
|
||||
import com.pichillilorenzo.flutter_inappwebview.webview.in_app_webview.InAppWebView;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import io.flutter.plugin.common.MethodChannel;
|
||||
|
||||
public class PullToRefreshLayout extends SwipeRefreshLayout implements Disposable {
|
||||
|
|
|
@ -2966,6 +2966,14 @@ if(window.\(JAVASCRIPT_BRIDGE_NAME)[\(_callHandlerID)] != null) {
|
|||
}
|
||||
}
|
||||
|
||||
public func isPullToRefreshEnabled() -> Bool {
|
||||
if #available(iOS 10.0, *) {
|
||||
return scrollView.refreshControl != nil
|
||||
} else {
|
||||
return pullToRefreshControl?.superview != nil
|
||||
}
|
||||
}
|
||||
|
||||
public func createWebMessageChannel(completionHandler: ((WebMessageChannel) -> Void)? = nil) -> WebMessageChannel {
|
||||
let id = NSUUID().uuidString
|
||||
let webMessageChannel = WebMessageChannel(id: id)
|
||||
|
|
|
@ -32,6 +32,13 @@ public class PullToRefreshChannelDelegate : ChannelDelegate {
|
|||
result(false)
|
||||
}
|
||||
break
|
||||
case "isEnabled":
|
||||
if let pullToRefreshView = pullToRefreshControl {
|
||||
result(pullToRefreshView.delegate?.isPullToRefreshEnabled())
|
||||
} else {
|
||||
result(false)
|
||||
}
|
||||
break
|
||||
case "setRefreshing":
|
||||
if let pullToRefreshView = pullToRefreshControl {
|
||||
let refreshing = arguments!["refreshing"] as! Bool
|
||||
|
@ -45,6 +52,13 @@ public class PullToRefreshChannelDelegate : ChannelDelegate {
|
|||
result(false)
|
||||
}
|
||||
break
|
||||
case "isRefreshing":
|
||||
if let pullToRefreshView = pullToRefreshControl {
|
||||
result(pullToRefreshView.isRefreshing)
|
||||
} else {
|
||||
result(false)
|
||||
}
|
||||
break
|
||||
case "setColor":
|
||||
if let pullToRefreshView = pullToRefreshControl {
|
||||
let color = arguments!["color"] as! String
|
||||
|
|
|
@ -10,4 +10,5 @@ import Foundation
|
|||
public protocol PullToRefreshDelegate {
|
||||
func enablePullToRefresh()
|
||||
func disablePullToRefresh()
|
||||
func isPullToRefreshEnabled() -> Bool
|
||||
}
|
||||
|
|
|
@ -95,12 +95,26 @@ class PullToRefreshController {
|
|||
}
|
||||
|
||||
///Sets whether the pull-to-refresh feature is enabled or not.
|
||||
///
|
||||
///**Supported Platforms/Implementations**:
|
||||
///- Android native WebView ([Official API - SwipeRefreshLayout.setEnabled](https://developer.android.com/reference/androidx/swiperefreshlayout/widget/SwipeRefreshLayout#setEnabled(boolean)))
|
||||
///- iOS ([Official API - UIScrollView.refreshControl](https://developer.apple.com/documentation/uikit/uiscrollview/2127691-refreshcontrol))
|
||||
Future<void> setEnabled(bool enabled) async {
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
args.putIfAbsent('enabled', () => enabled);
|
||||
await _channel?.invokeMethod('setEnabled', args);
|
||||
}
|
||||
|
||||
///Returns `true` is pull-to-refresh feature is enabled, otherwise `false`.
|
||||
///
|
||||
///**Supported Platforms/Implementations**:
|
||||
///- Android native WebView ([Official API - View.isEnabled](https://developer.android.com/reference/android/view/View#isEnabled()))
|
||||
///- iOS ([Official API - UIScrollView.refreshControl](https://developer.apple.com/documentation/uikit/uiscrollview/2127691-refreshcontrol))
|
||||
Future<bool> isEnabled() async {
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
return await _channel?.invokeMethod('isEnabled', args);
|
||||
}
|
||||
|
||||
Future<void> _setRefreshing(bool refreshing) async {
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
args.putIfAbsent('refreshing', () => refreshing);
|
||||
|
@ -112,6 +126,10 @@ class PullToRefreshController {
|
|||
///Call this method when an external event source triggers a programmatic refresh of your scrolling view.
|
||||
///This method updates the state of the refresh control to reflect the in-progress refresh operation.
|
||||
///When the refresh operation ends, be sure to call the [endRefreshing] method to return the controller to its default state.
|
||||
///
|
||||
///**Supported Platforms/Implementations**:
|
||||
///- Android native WebView
|
||||
///- iOS
|
||||
Future<void> beginRefreshing() async {
|
||||
return await _setRefreshing(true);
|
||||
}
|
||||
|
@ -122,17 +140,29 @@ class PullToRefreshController {
|
|||
///to return the refresh control to its default state.
|
||||
///If the refresh control is at least partially visible, calling this method also hides it.
|
||||
///If animations are also enabled, the control is hidden using an animation.
|
||||
///
|
||||
///**Supported Platforms/Implementations**:
|
||||
///- Android native WebView
|
||||
///- iOS
|
||||
Future<void> endRefreshing() async {
|
||||
await _setRefreshing(false);
|
||||
}
|
||||
|
||||
///Returns whether a refresh operation has been triggered and is in progress.
|
||||
///
|
||||
///**Supported Platforms/Implementations**:
|
||||
///- Android native WebView ([Official API - SwipeRefreshLayout.isRefreshing](https://developer.android.com/reference/androidx/swiperefreshlayout/widget/SwipeRefreshLayout#isRefreshing()))
|
||||
///- iOS ([Official API - UIRefreshControl.isRefreshing](https://developer.apple.com/documentation/uikit/uirefreshcontrol/1624844-isrefreshing))
|
||||
Future<bool> isRefreshing() async {
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
return await _channel?.invokeMethod('isRefreshing', args);
|
||||
}
|
||||
|
||||
///Sets the color of the refresh control.
|
||||
///
|
||||
///**Supported Platforms/Implementations**:
|
||||
///- Android native WebView ([Official API - SwipeRefreshLayout.setColorSchemeColors](https://developer.android.com/reference/androidx/swiperefreshlayout/widget/SwipeRefreshLayout#setColorSchemeColors(int...)))
|
||||
///- iOS ([Official API - UIRefreshControl.tintColor](https://developer.apple.com/documentation/uikit/uirefreshcontrol/1624847-tintcolor))
|
||||
Future<void> setColor(Color color) async {
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
args.putIfAbsent('color', () => color.toHex());
|
||||
|
@ -140,6 +170,10 @@ class PullToRefreshController {
|
|||
}
|
||||
|
||||
///Sets the background color of the refresh control.
|
||||
///
|
||||
///**Supported Platforms/Implementations**:
|
||||
///- Android native WebView ([Official API - SwipeRefreshLayout.setProgressBackgroundColorSchemeColor](https://developer.android.com/reference/androidx/swiperefreshlayout/widget/SwipeRefreshLayout#setProgressBackgroundColorSchemeColor(int)))
|
||||
///- iOS ([Official API - UIView.backgroundColor](https://developer.apple.com/documentation/uikit/uiview/1622591-backgroundcolor))
|
||||
Future<void> setBackgroundColor(Color color) async {
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
args.putIfAbsent('color', () => color.toHex());
|
||||
|
@ -148,7 +182,8 @@ class PullToRefreshController {
|
|||
|
||||
///Set the distance to trigger a sync in dips.
|
||||
///
|
||||
///**NOTE**: Available only on Android.
|
||||
///**Supported Platforms/Implementations**:
|
||||
///- Android native WebView ([Official API - SwipeRefreshLayout.setDistanceToTriggerSync](https://developer.android.com/reference/androidx/swiperefreshlayout/widget/SwipeRefreshLayout#setDistanceToTriggerSync(int)))
|
||||
Future<void> setDistanceToTriggerSync(int distanceToTriggerSync) async {
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
args.putIfAbsent('distanceToTriggerSync', () => distanceToTriggerSync);
|
||||
|
@ -157,7 +192,8 @@ class PullToRefreshController {
|
|||
|
||||
///Sets the distance that the refresh indicator can be pulled beyond its resting position during a swipe gesture.
|
||||
///
|
||||
///**NOTE**: Available only on Android.
|
||||
///**Supported Platforms/Implementations**:
|
||||
///- Android native WebView ([Official API - SwipeRefreshLayout.setSlingshotDistance](https://developer.android.com/reference/androidx/swiperefreshlayout/widget/SwipeRefreshLayout#setSlingshotDistance(int)))
|
||||
Future<void> setSlingshotDistance(int slingshotDistance) async {
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
args.putIfAbsent('slingshotDistance', () => slingshotDistance);
|
||||
|
@ -166,7 +202,8 @@ class PullToRefreshController {
|
|||
|
||||
///Gets the default distance that the refresh indicator can be pulled beyond its resting position during a swipe gesture.
|
||||
///
|
||||
///**NOTE**: Available only on Android.
|
||||
///**Supported Platforms/Implementations**:
|
||||
///- Android native WebView ([Official API - SwipeRefreshLayout.DEFAULT_SLINGSHOT_DISTANCE](https://developer.android.com/reference/androidx/swiperefreshlayout/widget/SwipeRefreshLayout#DEFAULT_SLINGSHOT_DISTANCE()))
|
||||
Future<int> getDefaultSlingshotDistance() async {
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
return await _channel?.invokeMethod('getDefaultSlingshotDistance', args);
|
||||
|
@ -182,7 +219,8 @@ class PullToRefreshController {
|
|||
|
||||
///Sets the size of the refresh indicator. One of [PullToRefreshSize.DEFAULT], or [PullToRefreshSize.LARGE].
|
||||
///
|
||||
///**NOTE**: Available only on Android.
|
||||
///**Supported Platforms/Implementations**:
|
||||
///- Android native WebView ([Official API - SwipeRefreshLayout.setSize](https://developer.android.com/reference/androidx/swiperefreshlayout/widget/SwipeRefreshLayout#setSize(int)))
|
||||
Future<void> setIndicatorSize(PullToRefreshSize size) async {
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
args.putIfAbsent('size', () => size.toNativeValue());
|
||||
|
@ -199,7 +237,8 @@ class PullToRefreshController {
|
|||
|
||||
///Sets the styled title text to display in the refresh control.
|
||||
///
|
||||
///**NOTE**: Available only on iOS.
|
||||
///**Supported Platforms/Implementations**:
|
||||
///- iOS ([Official API - UIRefreshControl.attributedTitle](https://developer.apple.com/documentation/uikit/uirefreshcontrol/1624845-attributedtitle))
|
||||
Future<void> setStyledTitle(AttributedString attributedTitle) async {
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
args.putIfAbsent('attributedTitle', () => attributedTitle.toMap());
|
||||
|
|
Loading…
Reference in New Issue