updated deprecated custom tabs builder method, added shareState android option for ChromeSafariBrowser
This commit is contained in:
parent
621d524dd6
commit
c61019058c
@ -5,6 +5,7 @@
|
||||
- Updated Flutter environment: sdk to `>=2.14.0 <3.0.0` and flutter version to `>=2.5.0`
|
||||
- Added `singleInstance` option for Android `ChromeSafariBrowser` implementation
|
||||
- Added `onDownloadStartRequest` event and deprecated old `onDownloadStart` event
|
||||
- Added `shareState` Android option for `ChromeSafariBrowser` class
|
||||
- Fixed missing `onZoomScaleChanged` call for `InAppBrowser` class
|
||||
- Fixed `requestImageRef` method always `null` on iOS
|
||||
- Fixed "applicationNameForUserAgent is not work in ios" [#525](https://github.com/pichillilorenzo/flutter_inappwebview/issues/525)
|
||||
|
@ -8,6 +8,7 @@ import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.browser.customtabs.CustomTabColorSchemeParams;
|
||||
import androidx.browser.customtabs.CustomTabsCallback;
|
||||
import androidx.browser.customtabs.CustomTabsIntent;
|
||||
import androidx.browser.customtabs.CustomTabsService;
|
||||
@ -149,17 +150,22 @@ public class ChromeCustomTabsActivity extends Activity implements MethodChannel.
|
||||
}
|
||||
|
||||
private void prepareCustomTabs(List<HashMap<String, Object>> menuItemList) {
|
||||
if (options.addDefaultShareMenuItem)
|
||||
builder.addDefaultShareMenuItem();
|
||||
if (options.addDefaultShareMenuItem != null) {
|
||||
builder.setShareState(options.addDefaultShareMenuItem ?
|
||||
CustomTabsIntent.SHARE_STATE_ON : CustomTabsIntent.SHARE_STATE_OFF);
|
||||
} else {
|
||||
builder.setShareState(options.shareState);
|
||||
}
|
||||
|
||||
if (options.toolbarBackgroundColor != null && !options.toolbarBackgroundColor.isEmpty())
|
||||
builder.setToolbarColor(Color.parseColor(options.toolbarBackgroundColor));
|
||||
if (options.toolbarBackgroundColor != null && !options.toolbarBackgroundColor.isEmpty()) {
|
||||
CustomTabColorSchemeParams.Builder defaultColorSchemeBuilder = new CustomTabColorSchemeParams.Builder();
|
||||
builder.setDefaultColorSchemeParams(defaultColorSchemeBuilder
|
||||
.setToolbarColor(Color.parseColor(options.toolbarBackgroundColor))
|
||||
.build());
|
||||
}
|
||||
|
||||
builder.setShowTitle(options.showTitle);
|
||||
|
||||
if (options.enableUrlBarHiding)
|
||||
builder.enableUrlBarHiding();
|
||||
|
||||
builder.setUrlBarHidingEnabled(options.enableUrlBarHiding);
|
||||
builder.setInstantAppsEnabled(options.instantAppsEnabled);
|
||||
|
||||
for (HashMap<String, Object> menuItem : menuItemList) {
|
||||
|
@ -3,6 +3,7 @@ package com.pichillilorenzo.flutter_inappwebview.chrome_custom_tabs;
|
||||
import android.content.Intent;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.browser.customtabs.CustomTabsIntent;
|
||||
|
||||
import com.pichillilorenzo.flutter_inappwebview.Options;
|
||||
|
||||
@ -13,7 +14,9 @@ public class ChromeCustomTabsOptions implements Options<ChromeCustomTabsActivity
|
||||
|
||||
final static String LOG_TAG = "ChromeCustomTabsOptions";
|
||||
|
||||
public Boolean addDefaultShareMenuItem = true;
|
||||
@Deprecated
|
||||
public Boolean addDefaultShareMenuItem;
|
||||
public Integer shareState = CustomTabsIntent.SHARE_STATE_DEFAULT;
|
||||
public Boolean showTitle = true;
|
||||
@Nullable
|
||||
public String toolbarBackgroundColor;
|
||||
@ -21,6 +24,8 @@ public class ChromeCustomTabsOptions implements Options<ChromeCustomTabsActivity
|
||||
public Boolean instantAppsEnabled = false;
|
||||
public String packageName;
|
||||
public Boolean keepAliveEnabled = false;
|
||||
public Boolean singleInstance = false;
|
||||
public Boolean noHistory = false;
|
||||
|
||||
@Override
|
||||
public ChromeCustomTabsOptions parse(Map<String, Object> options) {
|
||||
@ -33,25 +38,34 @@ public class ChromeCustomTabsOptions implements Options<ChromeCustomTabsActivity
|
||||
|
||||
switch (key) {
|
||||
case "addDefaultShareMenuItem":
|
||||
addDefaultShareMenuItem = (boolean) value;
|
||||
addDefaultShareMenuItem = (Boolean) value;
|
||||
break;
|
||||
case "shareState":
|
||||
shareState = (Integer) value;
|
||||
break;
|
||||
case "showTitle":
|
||||
showTitle = (boolean) value;
|
||||
showTitle = (Boolean) value;
|
||||
break;
|
||||
case "toolbarBackgroundColor":
|
||||
toolbarBackgroundColor = (String) value;
|
||||
break;
|
||||
case "enableUrlBarHiding":
|
||||
enableUrlBarHiding = (boolean) value;
|
||||
enableUrlBarHiding = (Boolean) value;
|
||||
break;
|
||||
case "instantAppsEnabled":
|
||||
instantAppsEnabled = (boolean) value;
|
||||
instantAppsEnabled = (Boolean) value;
|
||||
break;
|
||||
case "packageName":
|
||||
packageName = (String) value;
|
||||
break;
|
||||
case "keepAliveEnabled":
|
||||
keepAliveEnabled = (boolean) value;
|
||||
keepAliveEnabled = (Boolean) value;
|
||||
break;
|
||||
case "singleInstance":
|
||||
singleInstance = (Boolean) value;
|
||||
break;
|
||||
case "noHistory":
|
||||
noHistory = (Boolean) value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -69,6 +83,8 @@ public class ChromeCustomTabsOptions implements Options<ChromeCustomTabsActivity
|
||||
options.put("instantAppsEnabled", instantAppsEnabled);
|
||||
options.put("packageName", packageName);
|
||||
options.put("keepAliveEnabled", keepAliveEnabled);
|
||||
options.put("singleInstance", singleInstance);
|
||||
options.put("noHistory", noHistory);
|
||||
return options;
|
||||
}
|
||||
|
||||
|
@ -5140,9 +5140,9 @@ setTimeout(function() {
|
||||
final InAppWebViewController controller =
|
||||
await controllerCompleter.future;
|
||||
await pageLoaded.future;
|
||||
var originUrl = (await controller.android.getOriginalUrl())?.toString();
|
||||
var originUrl = (await controller.getOriginalUrl())?.toString();
|
||||
expect(originUrl, 'https://github.com/flutter');
|
||||
}, skip: !Platform.isAndroid);
|
||||
});
|
||||
|
||||
testWidgets('pageDown/pageUp', (WidgetTester tester) async {
|
||||
final Completer controllerCompleter =
|
||||
|
@ -66,7 +66,7 @@ class _ChromeSafariBrowserExampleScreenState
|
||||
url: Uri.parse("https://flutter.dev/"),
|
||||
options: ChromeSafariBrowserClassOptions(
|
||||
android: AndroidChromeCustomTabsOptions(
|
||||
addDefaultShareMenuItem: false,
|
||||
shareState: CustomTabsShareState.SHARE_STATE_OFF,
|
||||
singleInstance: false,
|
||||
keepAliveEnabled: true),
|
||||
ios: IOSSafariOptions(
|
||||
|
@ -1,6 +1,7 @@
|
||||
import 'dart:ui';
|
||||
|
||||
import '../../util.dart';
|
||||
import '../../types.dart';
|
||||
|
||||
import '../chrome_safari_browser_options.dart';
|
||||
import '../chrome_safari_browser.dart';
|
||||
@ -11,7 +12,11 @@ import '../../in_app_webview/android/in_app_webview_options.dart';
|
||||
class AndroidChromeCustomTabsOptions
|
||||
implements ChromeSafariBrowserOptions, AndroidOptions {
|
||||
///Set to `false` if you don't want the default share item to the menu. The default value is `true`.
|
||||
bool addDefaultShareMenuItem;
|
||||
@Deprecated('Use `shareState` instead')
|
||||
bool? addDefaultShareMenuItem;
|
||||
|
||||
///The share state that should be applied to the custom tab. The default value is [CustomTabsShareState.SHARE_STATE_DEFAULT].
|
||||
CustomTabsShareState shareState;
|
||||
|
||||
///Set to `false` if the title shouldn't be shown in the custom tab. The default value is `true`.
|
||||
bool showTitle;
|
||||
@ -42,7 +47,8 @@ class AndroidChromeCustomTabsOptions
|
||||
bool noHistory;
|
||||
|
||||
AndroidChromeCustomTabsOptions(
|
||||
{this.addDefaultShareMenuItem = true,
|
||||
{@Deprecated('Use `shareState` instead') this.addDefaultShareMenuItem,
|
||||
this.shareState = CustomTabsShareState.SHARE_STATE_DEFAULT,
|
||||
this.showTitle = true,
|
||||
this.toolbarBackgroundColor,
|
||||
this.enableUrlBarHiding = false,
|
||||
@ -55,7 +61,9 @@ class AndroidChromeCustomTabsOptions
|
||||
@override
|
||||
Map<String, dynamic> toMap() {
|
||||
return {
|
||||
// ignore: deprecated_member_use_from_same_package
|
||||
"addDefaultShareMenuItem": addDefaultShareMenuItem,
|
||||
"shareState": shareState.toValue(),
|
||||
"showTitle": showTitle,
|
||||
"toolbarBackgroundColor": toolbarBackgroundColor?.toHex(),
|
||||
"enableUrlBarHiding": enableUrlBarHiding,
|
||||
@ -70,7 +78,9 @@ class AndroidChromeCustomTabsOptions
|
||||
static AndroidChromeCustomTabsOptions fromMap(Map<String, dynamic> map) {
|
||||
AndroidChromeCustomTabsOptions options =
|
||||
new AndroidChromeCustomTabsOptions();
|
||||
// ignore: deprecated_member_use_from_same_package
|
||||
options.addDefaultShareMenuItem = map["addDefaultShareMenuItem"];
|
||||
options.shareState = map["shareState"];
|
||||
options.showTitle = map["showTitle"];
|
||||
options.toolbarBackgroundColor =
|
||||
UtilColor.fromHex(map["toolbarBackgroundColor"]);
|
||||
|
@ -6960,4 +6960,58 @@ class DownloadStartRequest {
|
||||
String toString() {
|
||||
return toMap().toString();
|
||||
}
|
||||
}
|
||||
|
||||
///Android-specific class representing the share state that should be applied to the custom tab.
|
||||
class CustomTabsShareState {
|
||||
final int _value;
|
||||
|
||||
const CustomTabsShareState._internal(this._value);
|
||||
|
||||
static final Set<CustomTabsShareState> values = [
|
||||
CustomTabsShareState.SHARE_STATE_DEFAULT,
|
||||
CustomTabsShareState.SHARE_STATE_ON,
|
||||
CustomTabsShareState.SHARE_STATE_OFF,
|
||||
].toSet();
|
||||
|
||||
static CustomTabsShareState? fromValue(int? value) {
|
||||
if (value != null) {
|
||||
try {
|
||||
return CustomTabsShareState.values
|
||||
.firstWhere((element) => element.toValue() == value);
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
int toValue() => _value;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
switch (_value) {
|
||||
case 1:
|
||||
return "SHARE_STATE_ON";
|
||||
case 2:
|
||||
return "SHARE_STATE_OFF";
|
||||
case 0:
|
||||
default:
|
||||
return "SHARE_STATE_DEFAULT";
|
||||
}
|
||||
}
|
||||
|
||||
///Applies the default share settings depending on the browser.
|
||||
static const SHARE_STATE_DEFAULT = const CustomTabsShareState._internal(0);
|
||||
|
||||
///Shows a share option in the tab.
|
||||
static const SHARE_STATE_ON = const CustomTabsShareState._internal(1);
|
||||
|
||||
///Explicitly does not show a share option in the tab.
|
||||
static const SHARE_STATE_OFF = const CustomTabsShareState._internal(2);
|
||||
|
||||
bool operator ==(value) => value == _value;
|
||||
|
||||
@override
|
||||
int get hashCode => _value.hashCode;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user