Skip to content

Commit

Permalink
Added InAppWebView widget MacOS support
Browse files Browse the repository at this point in the history
  • Loading branch information
pichillilorenzo committed Sep 22, 2024
1 parent ca417f8 commit 2ff7e88
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 44 deletions.
6 changes: 6 additions & 0 deletions flutter_inappwebview/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
## 6.1.0

- Added initial Windows support
- Added `InAppWebView` MacOS support
- Updates minimum supported SDK version to Flutter 3.24/Dart 3.5.
- Updated androidx.webkit:webkit:1.8.0 to androidx.webkit:webkit:1.12.0
- Updated androidx.browser:browser:1.6.0 to androidx.browser:browser:1.8.0
- Fixed "[MACOS] launching InAppBrowser with 'hidden: true' calls onExit immediately" [#1939](https://github.com/pichillilorenzo/flutter_inappwebview/issues/1939)
- Fixed XCode 16 build
- Removed unsupported WebViewFeature.SUPPRESS_ERROR_PAGE

## 6.0.0

Expand Down
25 changes: 9 additions & 16 deletions flutter_inappwebview/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -84,24 +84,18 @@ PointerInterceptor myDrawer({required BuildContext context}) {
];
} else if (defaultTargetPlatform == TargetPlatform.macOS) {
children = [
// ListTile(
// title: Text('InAppWebView'),
// onTap: () {
// Navigator.pushReplacementNamed(context, '/');
// },
// ),
// ListTile(
// title: Text('InAppBrowser'),
// onTap: () {
// Navigator.pushReplacementNamed(context, '/InAppBrowser');
// },
// ),
ListTile(
title: Text('InAppBrowser'),
title: Text('InAppWebView'),
onTap: () {
Navigator.pushReplacementNamed(context, '/');
},
),
ListTile(
title: Text('InAppBrowser'),
onTap: () {
Navigator.pushReplacementNamed(context, '/InAppBrowser');
},
),
ListTile(
title: Text('WebAuthenticationSession'),
onTap: () {
Expand Down Expand Up @@ -181,9 +175,8 @@ class _MyAppState extends State<MyApp> {
}
if (defaultTargetPlatform == TargetPlatform.macOS) {
return MaterialApp(initialRoute: '/', routes: {
// '/': (context) => InAppWebViewExampleScreen(),
// '/InAppBrowser': (context) => InAppBrowserExampleScreen(),
'/': (context) => InAppBrowserExampleScreen(),
'/': (context) => InAppWebViewExampleScreen(),
'/InAppBrowser': (context) => InAppBrowserExampleScreen(),
'/HeadlessInAppWebView': (context) =>
HeadlessInAppWebViewExampleScreen(),
'/WebAuthenticationSession': (context) =>
Expand Down
3 changes: 2 additions & 1 deletion flutter_inappwebview_macos/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
## 1.1.0

- Added `InAppWebView` support
- Updates minimum supported SDK version to Flutter 3.24/Dart 3.5.
- Fixed "[MACOS] launching InAppBrowser with 'hidden: true' calls onExit immediately" [#1939](https://github.com/pichillilorenzo/flutter_inappwebview/issues/1939)
- Fixed XCode 16 build
- Updates minimum supported SDK version to Flutter 3.24/Dart 3.5.

## 1.0.11

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ class MacOSInAppWebViewWidget extends PlatformInAppWebViewWidget {
}
}

return UiKitView(
return AppKitView(
viewType: 'com.pichillilorenzo/flutter_inappwebview',
onPlatformViewCreated: _onPlatformViewCreated,
gestureRecognizers: params.gestureRecognizers,
Expand Down
21 changes: 10 additions & 11 deletions flutter_inappwebview_macos/lib/src/inappwebview_platform.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,16 @@ class MacOSInAppWebViewPlatform extends InAppWebViewPlatform {
return MacOSInAppWebViewController.static();
}

// TODO: unhide when Flutter official PlatformView for macOS is available
// /// Creates a new [MacOSInAppWebViewWidget].
// ///
// /// This function should only be called by the app-facing package.
// /// Look at using [InAppWebView] in `flutter_inappwebview` instead.
// @override
// MacOSInAppWebViewWidget createPlatformInAppWebViewWidget(
// PlatformInAppWebViewWidgetCreationParams params,
// ) {
// return MacOSInAppWebViewWidget(params);
// }
/// Creates a new [MacOSInAppWebViewWidget].
///
/// This function should only be called by the app-facing package.
/// Look at using [InAppWebView] in `flutter_inappwebview` instead.
@override
MacOSInAppWebViewWidget createPlatformInAppWebViewWidget(
PlatformInAppWebViewWidgetCreationParams params,
) {
return MacOSInAppWebViewWidget(params);
}

/// Creates a new [MacOSFindInteractionController].
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,12 @@ import Foundation
import WebKit
import FlutterMacOS

public class FlutterWebViewController: NSObject, /*FlutterPlatformView,*/ Disposable {
public class FlutterWebViewController: NSView, Disposable {

var myView: NSView?
var keepAliveId: String?

init(plugin: InAppWebViewFlutterPlugin, withFrame frame: CGRect, viewIdentifier viewId: Any, params: NSDictionary) {
super.init()

myView = NSView(frame: frame)
super.init(frame: frame)

keepAliveId = params["keepAliveId"] as? String

Expand Down Expand Up @@ -47,12 +44,12 @@ public class FlutterWebViewController: NSObject, /*FlutterPlatformView,*/ Dispos
binaryMessenger: registrar.messenger)
webView!.channelDelegate = WebViewChannelDelegate(webView: webView!, channel: channel)
}
webView!.frame = myView!.bounds
webView!.frame = self.bounds
webView!.initialUserScripts = userScripts
} else {
webView = InAppWebView(id: viewId,
plugin: plugin,
frame: myView!.bounds,
frame: self.bounds,
configuration: preWebviewConfiguration,
userScripts: userScripts)
}
Expand All @@ -64,17 +61,21 @@ public class FlutterWebViewController: NSObject, /*FlutterPlatformView,*/ Dispos
findInteractionController.prepare()

webView!.autoresizingMask = [.width, .height]
myView!.autoresizesSubviews = true
myView!.autoresizingMask = [.width, .height]
myView!.addSubview(webView!)
self.autoresizesSubviews = true
self.autoresizingMask = [.width, .height]
self.addSubview(webView!)

webView!.settings = settings
webView!.prepare()
webView!.windowCreated = true
}

required init?(coder nsCoder: NSCoder) {
super.init(coder: nsCoder)
}

public func webView() -> InAppWebView? {
for subview in myView?.subviews ?? []
for subview in self.subviews
{
if let item = subview as? InAppWebView
{
Expand All @@ -85,7 +86,7 @@ public class FlutterWebViewController: NSObject, /*FlutterPlatformView,*/ Dispos
}

public func view() -> NSView {
return myView!
return self
}

public func makeInitialLoad(params: NSDictionary) {
Expand Down Expand Up @@ -185,9 +186,8 @@ public class FlutterWebViewController: NSObject, /*FlutterPlatformView,*/ Dispos
}
}
if removeFromSuperview {
myView?.removeFromSuperview()
self.removeFromSuperview()
}
myView = nil
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,6 @@ public class FlutterWebViewFactory: NSObject, FlutterPlatformViewFactory {
flutterWebView?.makeInitialLoad(params: arguments!)
}

return flutterWebView!.view()
return flutterWebView!
}
}

0 comments on commit 2ff7e88

Please sign in to comment.