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