概述

#

FlutterViewController 属性 splashScreenView 已从 非空 更改为 可空

splashScreenView 的旧声明

objc
@property(strong, nonatomic) UIView* splashScreenView;

splashScreenView 的新声明

objc
@property(strong, nonatomic, nullable) UIView* splashScreenView;

背景

#

在此更改之前,在 iOS 上,当未设置启动屏幕视图时,splashScreenView 属性会返回 nil,并且将该属性设置为 nil 会移除启动屏幕视图。但是,splashScreenView API 被错误地标记为 非空。此属性在 iOS add-to-app 场景中过渡到 Flutter 视图时最为常用。

变更说明

#

虽然在 Objective-C 中可以通过将 splashScreenView 设置为 nil UIView 来规避不正确的 非空 注释,但在 Swift 中这会导致编译错误。

error build: Value of optional type 'UIView?' must be unwrapped to a value of type 'UIView'

PR #34743 将属性属性更新为 可空。它现在可以在 Objective-C 和 Swift 中返回 nil,并且可以设置为 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