UIKitView在打开相机后冻结问题临时处理方案
- flutter 1.20.2 版本iOS WKWebView 和 UIImagePickerController 冲突临时解决方案,目前最新的版本1.22.2已经修复了,项目改动小的可以直接升级
- github issue地址: https://github.com/flutter/flutter/issues/65361
frozen image
- 异常情况的视图层级,对比发现开启相机后,再进入UIKitView页面会新增
FlutterClippingMaskView
,遮罩层 - 正常情况的视图层级
Related views
- FlutterTouchInterceptingView
// A UIView that is used as the parent for embedded UIViews.
//
// This view has 2 roles:
// 1. Delay or prevent touch events from arriving the embedded view.
// 2. Dispatching all events that are hittested to the embedded view to FlutterView
- bind engine delegate and create surface
ChildClippingView
- filter touch events
FlutterClippingMaskView
- chip the bottom views, (bloc the platform view touch events)
Temp solution
- 如果时再UIKitView所在的页面则不会出现这个问题,临时解决方案
- remove
FlutterClippingMaskView
on webview loaded
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
let lastView = webView.superview?.superview?.subviews.last
if lastView?.description.contains("FlutterClippingMaskView") ?? false {
lastView?.isUserInteractionEnabled = true;
lastView?.removeFromSuperview();
}
print(#function,#line)
}
- disable the edge gestures for navigation
body: WillPopScope(child: UiKitView(
viewType: VIEW_TYPE,
hitTestBehavior: PlatformViewHitTestBehavior.opaque,
creationParams: {'url': 'https://www.baidu.com'},
onPlatformViewCreated: (viewId) {
channel = MethodChannel('${VIEW_TYPE}_$viewId');
},
creationParamsCodec: StandardMessageCodec(),
), onWillPop: () async {
if (Navigator.of(context).userGestureInProgress) {
return false;
} else {
return true;
}
},
),