Skip to content

Commit

Permalink
[MBL-17170][Parent] Updated WebView dependency (#2243)
Browse files Browse the repository at this point in the history
refs: MBL-17170
affects: Parent
release note: Fixed a crash on web content screens on Android 10.

* Updated webview_flutter to 3.0.4

* Fixed dark mode.

* Tests.

* Cleanup.
  • Loading branch information
tamaskozmer authored Nov 9, 2023
1 parent 3dd6c9d commit df03276
Show file tree
Hide file tree
Showing 32 changed files with 450 additions and 3,549 deletions.
7 changes: 7 additions & 0 deletions apps/flutter_parent/assets/html/html_wrapper.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
height: auto;
margin: 0;
padding: 0;
background-color: {BACKGROUND};
color: {COLOR};
}

img {
Expand Down Expand Up @@ -65,6 +67,7 @@

a {
word-wrap: break-word;
color: {LINK_COLOR}
}

.lti_button {
Expand All @@ -81,6 +84,10 @@
font-size: 13px;
margin: auto;
}

a:visited {
color: {VISITED_LINK_COLOR}
}
</style>
<body>
<div id="content">
Expand Down
1 change: 0 additions & 1 deletion apps/flutter_parent/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import 'package:flutter_parent/utils/notification_util.dart';
import 'package:flutter_parent/utils/old_app_migration.dart';
import 'package:flutter_parent/utils/remote_config_utils.dart';
import 'package:flutter_parent/utils/service_locator.dart';
import 'package:webview_flutter/webview_flutter.dart';
import 'package:flutter_downloader/flutter_downloader.dart';

void main() async {
Expand Down
8 changes: 5 additions & 3 deletions apps/flutter_parent/lib/screens/help/terms_of_use_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,12 @@ class _TermsOfUseScreenState extends State<TermsOfUseScreen> {

// Content
return WebView(
darkMode: ParentTheme.of(context)?.isWebViewDarkMode,
onWebViewCreated: (controller) {
controller.loadHtml(snapshot.data!.content!, horizontalPadding: 16);
},
controller.loadHtml(snapshot.data!.content!,
horizontalPadding: 16,
darkMode:
ParentTheme.of(context)?.isWebViewDarkMode ?? false);
},
navigationDelegate: _handleNavigation
);
},
Expand Down
12 changes: 5 additions & 7 deletions apps/flutter_parent/lib/screens/web_login/web_login_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ class _WebLoginScreenState extends State<WebLoginScreen> {
navigationDelegate: (request) =>
_navigate(context, request, verifyResult),
javascriptMode: JavascriptMode.unrestricted,
darkMode: ParentTheme.of(context)?.isWebViewDarkMode,
userAgent: ApiPrefs.getUserAgent(),
onPageFinished: (url) => _pageFinished(url, verifyResult),
onPageStarted: (url) => _pageStarted(url),
Expand Down Expand Up @@ -243,16 +242,15 @@ class _WebLoginScreenState extends State<WebLoginScreen> {
/// Load the authenticated url with any necessary cookies
void _loadAuthUrl() async {
_showLoadingState();
CookieManager().clearCookies();
final cookieManager = CookieManager();
cookieManager.clearCookies();

if (widget.loginFlow == LoginFlow.siteAdmin) {
await _controller?.setAcceptThirdPartyCookies(true);
if (_domain.contains('.instructure.com')) {
String cookie = 'canvas_sa_delegated=1;domain=.instructure.com;path=/;';
await _controller?.setCookie(_domain, cookie);
await _controller?.setCookie('.instructure.com', cookie);
cookieManager.setCookie(WebViewCookie(name: 'canvas_sa_delegated', value: '1', domain: _domain));
cookieManager.setCookie(WebViewCookie(name: 'canvas_sa_delegated', value: '1', domain: '.instructure.com'));
} else {
await _controller?.setCookie(_domain, 'canvas_sa_delegated=1');
cookieManager.setCookie(WebViewCookie(name: 'canvas_sa_delegated', value: '1', domain: _domain));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,14 +230,15 @@ class _ResizingWebViewState extends State<_ResizingWebView> with WidgetsBindingO
if (_content != widgetContent) {
_height = widget.initialHeight;
_content = widgetContent!;
_controller?.loadHtml(_content, horizontalPadding: widget.horizontalPadding);
_controller?.loadHtml(_content,
horizontalPadding: widget.horizontalPadding,
darkMode: ParentTheme.of(context)?.isWebViewDarkMode ?? false);
}

Widget child = WebView(
javascriptMode: JavascriptMode.unrestricted,
onPageFinished: _handlePageLoaded,
onWebViewCreated: _handleWebViewCreated,
darkMode: ParentTheme.of(context)?.isWebViewDarkMode == true,
navigationDelegate: _handleNavigation,
gestureRecognizers: _webViewGestures(),
javascriptChannels: _webViewChannels(),
Expand All @@ -260,7 +261,10 @@ class _ResizingWebViewState extends State<_ResizingWebView> with WidgetsBindingO
}

void _handleWebViewCreated(WebViewController webViewController) async {
webViewController.loadHtml(_content, baseUrl: ApiPrefs.getDomain(), horizontalPadding: widget.horizontalPadding);
webViewController.loadHtml(_content,
baseUrl: ApiPrefs.getDomain(),
horizontalPadding: widget.horizontalPadding,
darkMode: ParentTheme.of(context)?.isWebViewDarkMode ?? false);
_controller = webViewController;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ class _SimpleWebViewScreenState extends State<SimpleWebViewScreen> {
body: WebView(
javascriptMode: JavascriptMode.unrestricted,
userAgent: ApiPrefs.getUserAgent(),
darkMode: ParentTheme.of(context)?.isWebViewDarkMode,
gestureRecognizers: Set()..add(Factory<WebViewGestureRecognizer>(() => WebViewGestureRecognizer())),
navigationDelegate: _handleNavigation,
onWebViewCreated: (controller) {
Expand Down
9 changes: 7 additions & 2 deletions apps/flutter_parent/lib/utils/web_view_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,20 @@ extension WebViewUtils on WebViewController {
String? html, {
String? baseUrl,
Map<String, String>? headers,
double horizontalPadding = 0})
double horizontalPadding = 0,
bool darkMode = false})
async {
String fileText = await rootBundle.loadString('assets/html/html_wrapper.html');
html = _applyWorkAroundForDoubleSlashesAsUrlSource(html);
html = _addProtocolToLinks(html);
html = _checkForMathTags(html);
html = fileText.replaceAll('{CANVAS_CONTENT}', html);
html = html.replaceAll('{BACKGROUND}', darkMode ? '#000000' : '#ffffff');
html = html.replaceAll('{COLOR}', darkMode ? '#ffffff' : '#000000');
html = html.replaceAll('{LINK_COLOR}', darkMode ? '#1283C4' : '#0374B5');
html = html.replaceAll('{VISITED_LINK_COLOR}', darkMode ? '#C74BAF' : '#BF32A4');
html = html.replaceAll('{PADDING}', horizontalPadding.toString());
this.loadData(baseUrl, html, 'text/html', 'utf-8');
this.loadHtmlString(html, baseUrl: baseUrl);
}

/**
Expand Down
25 changes: 0 additions & 25 deletions apps/flutter_parent/plugins/webview_flutter/LICENSE

This file was deleted.

41 changes: 0 additions & 41 deletions apps/flutter_parent/plugins/webview_flutter/android/build.gradle

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit df03276

Please sign in to comment.