Commit a5a784dd authored by pichillilorenzo's avatar pichillilorenzo

init iOS inline webview implementation

parent f02791f4
This diff is collapsed.
This diff is collapsed.
......@@ -20,7 +20,6 @@
<excludeFolder url="file://$MODULE_DIR$/example/ios/.symlinks/plugins/flutter_inappbrowser/example/.dart_tool" />
<excludeFolder url="file://$MODULE_DIR$/example/ios/.symlinks/plugins/flutter_inappbrowser/example/.pub" />
<excludeFolder url="file://$MODULE_DIR$/example/ios/.symlinks/plugins/flutter_inappbrowser/example/build" />
<excludeFolder url="file://$MODULE_DIR$/example/ios/.symlinks/plugins/flutter_inappbrowser/example/ios/Flutter/flutter_assets/packages" />
<excludeFolder url="file://$MODULE_DIR$/example/ios/Flutter/flutter_assets/packages" />
</content>
<orderEntry type="sourceFolder" forTests="false" />
......
//
// FlutterWebViewController.swift
// flutter_inappbrowser
//
// Created by Lorenzo on 13/11/18.
//
import Foundation
public class FlutterWebViewController: NSObject, FlutterPlatformView {
private weak var registrar: FlutterPluginRegistrar?
private var webView: InAppWebView?
private var viewId: Int64 = 0
private var channel: FlutterMethodChannel?
init(registrar: FlutterPluginRegistrar, withFrame frame: CGRect, viewIdentifier viewId: Int64, arguments args: NSDictionary) {
super.init()
self.registrar = registrar
self.viewId = viewId
webView = InAppWebView(frame: frame)
let channelName = String(format: "com.pichillilorenzo/flutter_inappwebview_%lld", viewId)
self.channel = FlutterMethodChannel(name: channelName, binaryMessenger: registrar.messenger())
self.channel?.setMethodCallHandler(self.handle)
var initialUrl = (args["initialUrl"] as? String)!
let initialFile = args["initialFile"] as? String
let initialData = args["initialData"] as? [String: String]
let initialHeaders = (args["initialHeaders"] as? [String: String])!
let initialOptions = (args["initialOptions"] as? [String: Any])!
webView!.load(URLRequest(url: URL(string: initialUrl)!))
}
public func view() -> UIView {
return webView!
}
public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
let arguments = call.arguments as? NSDictionary
switch call.method {
//case "open":
//self.open(uuid: uuid, arguments: arguments!, result: result)
//break
default:
result(FlutterMethodNotImplemented)
break
}
}
}
//
// FlutterWebViewFactory.swift
// flutter_inappbrowser
//
// Created by Lorenzo on 13/11/18.
//
import Flutter
import Foundation
public class FlutterWebViewFactory: NSObject, FlutterPlatformViewFactory {
private weak var registrar: FlutterPluginRegistrar?
init(registrar: FlutterPluginRegistrar?) {
super.init()
self.registrar = registrar
}
public func createArgsCodec() -> FlutterMessageCodec & NSObjectProtocol {
return FlutterStandardMessageCodec.sharedInstance()
}
public func create(withFrame frame: CGRect, viewIdentifier viewId: Int64, arguments args: Any?) -> FlutterPlatformView {
let arguments = args as? NSDictionary
let webviewController = FlutterWebViewController(registrar: registrar!, withFrame: frame, viewIdentifier: viewId, arguments: arguments!)
return webviewController
}
}
......@@ -36,12 +36,12 @@ extension Dictionary where Key: ExpressibleByStringLiteral {
public class SwiftFlutterPlugin: NSObject, FlutterPlugin {
static var registrar: FlutterPluginRegistrar?
var channel: FlutterMethodChannel
var webViewControllers: [String: InAppBrowserWebViewController?] = [:]
var safariViewControllers: [String: Any?] = [:]
var tmpWindow: UIWindow?
var channel: FlutterMethodChannel
private var previousStatusBarStyle = -1
public init(with registrar: FlutterPluginRegistrar) {
......@@ -56,6 +56,8 @@ public class SwiftFlutterPlugin: NSObject, FlutterPlugin {
let instance = SwiftFlutterPlugin(with: registrar)
registrar.addMethodCallDelegate(instance, channel: channel)
registrar.register(FlutterWebViewFactory(registrar: registrar) as FlutterPlatformViewFactory, withId: "com.pichillilorenzo/flutter_inappwebview")
if #available(iOS 11.0, *) {
MyCookieManager(registrar: registrar)
} else {
......
......@@ -694,6 +694,20 @@ class _InAppWebViewState extends State<InAppWebView> {
creationParamsCodec: const StandardMessageCodec(),
),
);
} else if (defaultTargetPlatform == TargetPlatform.iOS) {
return UiKitView(
viewType: 'com.pichillilorenzo/flutter_inappwebview',
onPlatformViewCreated: _onPlatformViewCreated,
gestureRecognizers: widget.gestureRecognizers,
creationParams: <String, dynamic>{
'initialUrl': widget.initialUrl,
'initialFile': widget.initialFile,
'initialData': widget.initialData?.toMap(),
'initialHeaders': widget.initialHeaders,
'initialOptions': widget.initialOptions
},
creationParamsCodec: const StandardMessageCodec(),
);
}
return Text(
'$defaultTargetPlatform is not yet supported by the flutter_inappbrowser plugin');
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment