Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix/ios keyboard appearance #1756

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions ios/Classes/InAppWebView/FlutterWebViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class FlutterWebViewController: NSObject, FlutterPlatformView, Disposable
let windowId = params["windowId"] as? Int64
let initialUserScripts = params["initialUserScripts"] as? [[String: Any]]
let pullToRefreshInitialSettings = params["pullToRefreshSettings"] as! [String: Any?]
let keyboardAppearanceDark = params["keyboardAppearanceDark"] as! Bool

var userScripts: [UserScript] = []
if let initialUserScripts = initialUserScripts {
Expand Down Expand Up @@ -55,6 +56,10 @@ public class FlutterWebViewController: NSObject, FlutterPlatformView, Disposable
userScripts: userScripts)
}

if (keyboardAppearanceDark) {
setKeyboardAppearanceDark()
}

let pullToRefreshSettings = PullToRefreshSettings()
let _ = pullToRefreshSettings.parse(settings: pullToRefreshInitialSettings)
let pullToRefreshControl = PullToRefreshControl(registrar: registrar, id: viewId, settings: pullToRefreshSettings)
Expand Down Expand Up @@ -190,4 +195,20 @@ public class FlutterWebViewController: NSObject, FlutterPlatformView, Disposable
debugPrint("FlutterWebViewController - dealloc")
dispose()
}

private func setKeyboardAppearanceDark() {
let handler: @convention(block) (AnyObject) -> UIKeyboardAppearance = { (s:AnyObject) in
return UIKeyboardAppearance.dark
}
let darkImp:IMP = imp_implementationWithBlock(handler)
for classString:String? in ["WKContentView", "UITextInputTraits"] {
let cls:AnyClass? = NSClassFromString(classString!)
let method:Method? = class_getInstanceMethod(cls, Selector(("keyboardAppearance")))
if method != nil {
method_setImplementation(method!, darkImp)
} else {
class_addMethod(cls, Selector(("keyboardAppearance")), darkImp, "l@:")
}
}
}
}
1 change: 1 addition & 0 deletions lib/src/in_app_webview/in_app_webview.dart
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,7 @@ class _InAppWebViewState extends State<InAppWebView> {
'initialSettings': settingsMap,
'contextMenu': widget.contextMenu?.toMap() ?? {},
'windowId': widget.windowId,
'keyboardAppearanceDark': Theme.of(context).brightness == Brightness.dark,
'headlessWebViewId': widget.headlessWebView?.isRunning() ?? false
? widget.headlessWebView?.id
: null,
Expand Down