iOS FlutterViewController 的 splashScreenView 属性现已可为空
概述
#FlutterViewController
的 splashScreenView
属性已从 nonnull
更改为 nullable
。
splashScreenView
的旧声明
objc
@property(strong, nonatomic) UIView* splashScreenView;
splashScreenView
的新声明
objc
@property(strong, nonatomic, nullable) UIView* splashScreenView;
背景
#在此更改之前,在 iOS 上,当未设置启动屏幕视图时,splashScreenView
属性返回 nil
,将该属性设置为 nil
则会移除启动屏幕视图。然而,splashScreenView
API 被错误地标记为 nonnull
。该属性最常用于 iOS 添加到应用场景中过渡到 Flutter 视图时。
变更说明
#虽然在 Objective-C 中可以通过将 splashScreenView
设置为 nil
的 UIView
来绕过错误的 nonnull
注解,但在 Swift 中这会导致编译错误。
error build: Value of optional type 'UIView?' must be unwrapped to a value of type 'UIView'
PR #34743 将属性更改为 nullable
。它现在可以返回 nil
,并且在 Objective-C 和 Swift 中都可以设置为 nil
以移除视图。
迁移指南
#如果 splashScreenView
在 Swift 中存储在 UIView
变量中,请更新为可选类型 UIView?
。
迁移前的代码
swift
var splashScreenView = UIView()
var flutterEngine = FlutterEngine(name: "my flutter engine")
let flutterViewController = FlutterViewController(engine: flutterEngine, nibName: nil, bundle: nil)
splashScreenView = flutterViewController.splashScreenView // compilation error: Value of optional type 'UIView?' must be unwrapped to a value of type 'UIView'
迁移后的代码
swift
var splashScreenView : UIView? = UIView()
var flutterEngine = FlutterEngine(name: "my flutter engine")
let flutterViewController = FlutterViewController(engine: flutterEngine, nibName: nil, bundle: nil)
let splashScreenView = flutterViewController.splashScreenView // compiles successfully
if let splashScreenView = splashScreenView {
}
时间线
#稳定版发布于: 3.7
参考资料
#相关 PR