Skip to content

Commit

Permalink
Merge pull request adrianflutur#34 from adrianflutur/dev
Browse files Browse the repository at this point in the history
Version 0.2.1, see changelog.md for changes
  • Loading branch information
adrianflutur authored Sep 11, 2021
2 parents 2f6fa64 + a7d78f4 commit e10be27
Show file tree
Hide file tree
Showing 17 changed files with 143 additions and 106 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
## 0.2.1

- Breaking change

- WebViewX width and height are now required (due to the fact that the web version always needs a width and a height)

- Added the option to use hybrid composition for Android WebViews in `MobileSpecificParams`
- Added a new public default CORS proxy service for Web
- Update dependencies

## 0.2.0

- Deprecated pedantic. Adopted lint instead.
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ Note: For more detailed information about things such as `EmbeddedJsContent`, pl
| `String` initialContent | Initial webview content |
| `SourceType` initialSourceType | Initial webview content type (`url, urlBypass or html`) |
| `String?` userAgent | User agent |
| `double?` width | Widget's width (if null, it takes all available space) |
| `double?` height | Widget's height (if null, it takes all available space) |
| `double` width | Widget's width |
| `double` height | Widget's height |
| `Function(WebViewXController controller)?` onWebViewCreated | Callback that gets executed when the webview has initialized |
| `Set<EmbeddedJsContent>` jsContent | A set of EmbeddedJsContent, which is an object that defines some javascript which will be embedded in the page, once loaded (check the example app) |
| `Set<DartCallback>` dartCallBacks | A set of DartCallback, which is an object that defines a dart callback function, which will be called from javascript (check the example app) |
Expand Down
5 changes: 5 additions & 0 deletions example/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
include: package:lint/analysis_options_package.yaml
linter:
rules:
# Disable
use_build_context_synchronously: false
7 changes: 5 additions & 2 deletions example/lib/webview_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ class _WebViewXPageState extends State<WebViewXPage> {
key: const ValueKey('webviewx'),
initialContent: initialContent,
initialSourceType: SourceType.html,
height: screenSize.height / 2,
width: min(screenSize.width * 0.8, 1024),
onWebViewCreated: (controller) => webviewController = controller,
onPageStarted: (src) =>
debugPrint('A new page has started loading: $src\n'),
Expand All @@ -105,12 +107,13 @@ class _WebViewXPageState extends State<WebViewXPage> {
webSpecificParams: const WebSpecificParams(
printDebugInfo: true,
),
mobileSpecificParams: const MobileSpecificParams(
androidEnableHybridComposition: true,
),
navigationDelegate: (navigation) {
debugPrint(navigation.content.sourceType.toString());
return NavigationDecision.navigate;
},
height: screenSize.height / 2,
width: min(screenSize.width * 0.8, 1024),
);
}

Expand Down
16 changes: 8 additions & 8 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ packages:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.5.0"
version: "2.6.1"
boolean_selector:
dependency: transitive
description:
Expand Down Expand Up @@ -89,12 +89,12 @@ packages:
source: hosted
version: "4.0.0"
lint:
dependency: transitive
dependency: "direct dev"
description:
name: lint
url: "https://pub.dartlang.org"
source: hosted
version: "1.5.3"
version: "1.6.0"
matcher:
dependency: transitive
description:
Expand Down Expand Up @@ -141,7 +141,7 @@ packages:
name: source_span
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0"
version: "1.8.1"
stack_trace:
dependency: transitive
description:
Expand Down Expand Up @@ -176,7 +176,7 @@ packages:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.19"
version: "0.3.0"
typed_data:
dependency: transitive
description:
Expand Down Expand Up @@ -204,14 +204,14 @@ packages:
name: webview_flutter
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.12"
version: "2.0.13"
webviewx:
dependency: "direct main"
description:
path: ".."
relative: true
source: path
version: "0.2.0"
version: "0.2.1"
sdks:
dart: ">=2.12.0 <3.0.0"
dart: ">=2.13.0 <3.0.0"
flutter: ">=2.0.0"
1 change: 1 addition & 0 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ dependencies:
dev_dependencies:
flutter_test:
sdk: flutter
lint: ^1.5.3

flutter:
uses-material-design: true
Expand Down
2 changes: 1 addition & 1 deletion lib/src/controller/impl/mobile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class WebViewXController extends ChangeNotifier
required String initialContent,
required SourceType initialSourceType,
required bool ignoreAllGestures,
}) : _ignoreAllGesturesNotifier = ValueNotifier(ignoreAllGestures),
}) : _ignoreAllGesturesNotifier = ValueNotifier(ignoreAllGestures),
value = WebViewContent(
source: initialContent,
sourceType: initialSourceType,
Expand Down
2 changes: 1 addition & 1 deletion lib/src/controller/impl/web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class WebViewXController extends ChangeNotifier
required String initialContent,
required SourceType initialSourceType,
required bool ignoreAllGestures,
}) : _ignoreAllGesturesNotifier = ValueNotifier(ignoreAllGestures),
}) : _ignoreAllGesturesNotifier = ValueNotifier(ignoreAllGestures),
_history = HistoryStack<WebViewContent>(
initialEntry: WebViewContent(
source: initialContent,
Expand Down
4 changes: 4 additions & 0 deletions lib/src/utils/mobile_specific_params.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,14 @@ class MobileSpecificParams {
/// Same as the original one from webview_flutter.
final bool gestureNavigationEnabled;

/// Enable WebView hybrid composition
final bool androidEnableHybridComposition;

/// Constructor
const MobileSpecificParams({
this.mobileGestureRecognizers,
this.gestureNavigationEnabled = false,
this.debuggingEnabled = false,
this.androidEnableHybridComposition = false,
});
}
16 changes: 16 additions & 0 deletions lib/src/utils/web_url_bypass_proxy.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ abstract class BypassProxy {
static const publicProxies = <BypassProxy>[
BridgedBypassProxy(),
CodeTabsBypassProxy(),
WeCorsAnyWhereProxy(),
];
}

Expand Down Expand Up @@ -43,6 +44,21 @@ class CodeTabsBypassProxy implements BypassProxy {
}
}

/// we-cors-anywhere.herokuapp.com proxy
class WeCorsAnyWhereProxy implements BypassProxy {
const WeCorsAnyWhereProxy();

@override
String buildProxyUrl(String pageUrl) {
return 'https://we-cors-anywhere.herokuapp.com/$pageUrl';
}

@override
String extractPageSource(String responseBody) {
return responseBody;
}
}

/*
Example for when the proxy's response is not the page source directly,
but instead it's a JSON object.
Expand Down
8 changes: 4 additions & 4 deletions lib/src/view/impl/facade.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ class WebViewX extends StatelessWidget implements view_interface.WebViewX {

/// Widget width
@override
final double? width;
final double width;

/// Widget height
@override
final double? height;
final double height;

/// Callback which returns a referrence to the [WebViewXController]
/// being created.
Expand Down Expand Up @@ -103,8 +103,8 @@ class WebViewX extends StatelessWidget implements view_interface.WebViewX {
this.initialContent = 'about:blank',
this.initialSourceType = SourceType.url,
this.userAgent,
this.width,
this.height,
required this.width,
required this.height,
this.onWebViewCreated,
this.jsContent = const {},
this.dartCallBacks = const {},
Expand Down
50 changes: 24 additions & 26 deletions lib/src/view/impl/io.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ class WebViewX extends StatelessWidget implements view_interface.WebViewX {

/// Widget width
@override
final double? width;
final double width;

/// Widget height
@override
final double? height;
final double height;

/// Callback which returns a referrence to the [WebViewXController]
/// being created.
Expand Down Expand Up @@ -109,8 +109,8 @@ class WebViewX extends StatelessWidget implements view_interface.WebViewX {
this.initialContent = 'about:blank',
this.initialSourceType = SourceType.url,
this.userAgent,
this.width,
this.height,
required this.width,
required this.height,
this.onWebViewCreated,
this.jsContent = const {},
this.dartCallBacks = const {},
Expand All @@ -128,27 +128,25 @@ class WebViewX extends StatelessWidget implements view_interface.WebViewX {

@override
Widget build(BuildContext context) {
return LayoutBuilder(builder: (context, constraints) {
return mobile.WebViewX(
key: key,
initialContent: initialContent,
initialSourceType: initialSourceType,
userAgent: userAgent,
width: width ?? constraints.maxWidth,
height: height ?? constraints.maxHeight,
dartCallBacks: dartCallBacks,
jsContent: jsContent,
onWebViewCreated: onWebViewCreated,
ignoreAllGestures: ignoreAllGestures,
javascriptMode: javascriptMode,
initialMediaPlaybackPolicy: initialMediaPlaybackPolicy,
onPageStarted: onPageStarted,
onPageFinished: onPageFinished,
navigationDelegate: navigationDelegate,
onWebResourceError: onWebResourceError,
webSpecificParams: webSpecificParams,
mobileSpecificParams: mobileSpecificParams,
);
});
return mobile.WebViewX(
key: key,
initialContent: initialContent,
initialSourceType: initialSourceType,
userAgent: userAgent,
width: width,
height: height,
dartCallBacks: dartCallBacks,
jsContent: jsContent,
onWebViewCreated: onWebViewCreated,
ignoreAllGestures: ignoreAllGestures,
javascriptMode: javascriptMode,
initialMediaPlaybackPolicy: initialMediaPlaybackPolicy,
onPageStarted: onPageStarted,
onPageFinished: onPageFinished,
navigationDelegate: navigationDelegate,
onWebResourceError: onWebResourceError,
webSpecificParams: webSpecificParams,
mobileSpecificParams: mobileSpecificParams,
);
}
}
58 changes: 31 additions & 27 deletions lib/src/view/impl/mobile.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'dart:async';
import 'dart:io';

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
Expand Down Expand Up @@ -32,11 +33,11 @@ class WebViewX extends StatefulWidget implements view_interface.WebViewX {

/// Widget width
@override
final double? width;
final double width;

/// Widget height
@override
final double? height;
final double height;

/// Callback which returns a referrence to the [WebViewXController]
/// being created.
Expand Down Expand Up @@ -111,8 +112,8 @@ class WebViewX extends StatefulWidget implements view_interface.WebViewX {
this.initialContent = 'about:blank',
this.initialSourceType = SourceType.url,
this.userAgent,
this.width,
this.height,
required this.width,
required this.height,
this.onWebViewCreated,
this.jsContent = const {},
this.dartCallBacks = const {},
Expand Down Expand Up @@ -142,6 +143,11 @@ class _WebViewXState extends State<WebViewX> {
void initState() {
super.initState();

if (Platform.isAndroid &&
widget.mobileSpecificParams.androidEnableHybridComposition) {
wf.WebView.platform = wf.SurfaceAndroidWebView();
}

_ignoreAllGestures = widget.ignoreAllGestures;
webViewXController = _createWebViewXController();
}
Expand Down Expand Up @@ -220,33 +226,31 @@ class _WebViewXState extends State<WebViewX> {
)
.toSet();

final webview = SizedBox(
return SizedBox(
width: widget.width,
height: widget.height,
child: wf.WebView(
key: widget.key,
initialUrl: _initialContent(),
javascriptMode: javascriptMode,
onWebViewCreated: onWebViewCreated,
javascriptChannels: javascriptChannels,
gestureRecognizers:
widget.mobileSpecificParams.mobileGestureRecognizers,
onPageStarted: widget.onPageStarted,
onPageFinished: widget.onPageFinished,
initialMediaPlaybackPolicy: initialMediaPlaybackPolicy,
onWebResourceError: onWebResourceError,
gestureNavigationEnabled:
widget.mobileSpecificParams.gestureNavigationEnabled,
debuggingEnabled: widget.mobileSpecificParams.debuggingEnabled,
navigationDelegate: navigationDelegate,
userAgent: widget.userAgent,
child: IgnorePointer(
ignoring: _ignoreAllGestures,
child: wf.WebView(
key: widget.key,
initialUrl: _initialContent(),
javascriptMode: javascriptMode,
onWebViewCreated: onWebViewCreated,
javascriptChannels: javascriptChannels,
gestureRecognizers:
widget.mobileSpecificParams.mobileGestureRecognizers,
onPageStarted: widget.onPageStarted,
onPageFinished: widget.onPageFinished,
initialMediaPlaybackPolicy: initialMediaPlaybackPolicy,
onWebResourceError: onWebResourceError,
gestureNavigationEnabled:
widget.mobileSpecificParams.gestureNavigationEnabled,
debuggingEnabled: widget.mobileSpecificParams.debuggingEnabled,
navigationDelegate: navigationDelegate,
userAgent: widget.userAgent,
),
),
);

return IgnorePointer(
ignoring: _ignoreAllGestures,
child: webview,
);
}

// Returns initial data
Expand Down
Loading

0 comments on commit e10be27

Please sign in to comment.